Files
@ r28025:9116d6e411b0
Branch filter:
Location: cpp/openttd-patchpack/source/src/script/api/script_marine.cpp - annotation
r28025:9116d6e411b0
5.9 KiB
text/x-c
Codechange: replace x.size() == 0 with x.empty()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r26105:23588534dec9 r26105:23588534dec9 r26105:23588534dec9 r18500:14a481bc4437 r26105:23588534dec9 r26105:23588534dec9 r18500:14a481bc4437 r21383:942c32fb8b0e r21383:942c32fb8b0e r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r24158:d64bbd0cb864 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r24158:d64bbd0cb864 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r26996:7064173a70ca r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r26112:8e77e1979a31 r18500:14a481bc4437 r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r26996:7064173a70ca r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r26112:8e77e1979a31 r18500:14a481bc4437 r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r26996:7064173a70ca r18500:14a481bc4437 r18500:14a481bc4437 r26112:8e77e1979a31 r18500:14a481bc4437 r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r26996:7064173a70ca r18500:14a481bc4437 r18500:14a481bc4437 r26114:91e053fa2e46 r18500:14a481bc4437 r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r26996:7064173a70ca r18500:14a481bc4437 r18500:14a481bc4437 r26114:91e053fa2e46 r18500:14a481bc4437 r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r26996:7064173a70ca r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r26118:2b515956558b r18500:14a481bc4437 r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r26996:7064173a70ca r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r26118:2b515956558b r18500:14a481bc4437 r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r26996:7064173a70ca r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r26118:2b515956558b r18500:14a481bc4437 r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r26996:7064173a70ca r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r26118:2b515956558b r18500:14a481bc4437 r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r26996:7064173a70ca r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 r26118:2b515956558b r18500:14a481bc4437 r18500:14a481bc4437 r18501:8e3d905ea4bc r18500:14a481bc4437 r18500:14a481bc4437 r23607:36c15679007d r23607:36c15679007d r23607:36c15679007d r25961:cdb060badef0 r25961:cdb060badef0 r18500:14a481bc4437 r18500:14a481bc4437 r18500:14a481bc4437 | /*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file script_marine.cpp Implementation of ScriptMarine. */
#include "../../stdafx.h"
#include "script_marine.hpp"
#include "script_station.hpp"
#include "../../station_base.h"
#include "../../dock_cmd.h"
#include "../../landscape_cmd.h"
#include "../../station_cmd.h"
#include "../../tile_cmd.h"
#include "../../water_cmd.h"
#include "../../waypoint_cmd.h"
#include "../../safeguards.h"
/* static */ bool ScriptMarine::IsWaterDepotTile(TileIndex tile)
{
if (!::IsValidTile(tile)) return false;
return ::IsTileType(tile, MP_WATER) && ::GetWaterTileType(tile) == WATER_TILE_DEPOT;
}
/* static */ bool ScriptMarine::IsDockTile(TileIndex tile)
{
if (!::IsValidTile(tile)) return false;
return ::IsTileType(tile, MP_STATION) && ::IsDock(tile);
}
/* static */ bool ScriptMarine::IsBuoyTile(TileIndex tile)
{
if (!::IsValidTile(tile)) return false;
return ::IsTileType(tile, MP_STATION) && ::IsBuoy(tile);
}
/* static */ bool ScriptMarine::IsLockTile(TileIndex tile)
{
if (!::IsValidTile(tile)) return false;
return ::IsTileType(tile, MP_WATER) && ::GetWaterTileType(tile) == WATER_TILE_LOCK;
}
/* static */ bool ScriptMarine::IsCanalTile(TileIndex tile)
{
if (!::IsValidTile(tile)) return false;
return ::IsTileType(tile, MP_WATER) && ::IsCanal(tile);
}
/* static */ bool ScriptMarine::AreWaterTilesConnected(TileIndex t1, TileIndex t2)
{
if (!::IsValidTile(t1)) return false;
if (!::IsValidTile(t2)) return false;
/* Tiles not neighbouring */
if (::DistanceManhattan(t1, t2) != 1) return false;
DiagDirection to_other_tile = ::DiagdirBetweenTiles(t2, t1);
/* Determine the reachable tracks from the shared edge */
TrackBits gtts1 = ::TrackStatusToTrackBits(::GetTileTrackStatus(t1, TRANSPORT_WATER, 0, ReverseDiagDir(to_other_tile))) & ::DiagdirReachesTracks(to_other_tile);
if (gtts1 == TRACK_BIT_NONE) return false;
to_other_tile = ReverseDiagDir(to_other_tile);
TrackBits gtts2 = ::TrackStatusToTrackBits(::GetTileTrackStatus(t2, TRANSPORT_WATER, 0, ReverseDiagDir(to_other_tile))) & ::DiagdirReachesTracks(to_other_tile);
return gtts2 != TRACK_BIT_NONE;
}
/* static */ bool ScriptMarine::BuildWaterDepot(TileIndex tile, TileIndex front)
{
EnforceCompanyModeValid(false);
EnforcePrecondition(false, ::IsValidTile(tile));
EnforcePrecondition(false, ::IsValidTile(front));
EnforcePrecondition(false, (::TileX(front) == ::TileX(tile)) != (::TileY(front) == ::TileY(tile)));
return ScriptObject::Command<CMD_BUILD_SHIP_DEPOT>::Do(tile, ::TileX(front) == ::TileX(tile) ? AXIS_Y : AXIS_X);
}
/* static */ bool ScriptMarine::BuildDock(TileIndex tile, StationID station_id)
{
EnforceCompanyModeValid(false);
EnforcePrecondition(false, ::IsValidTile(tile));
EnforcePrecondition(false, station_id == ScriptStation::STATION_NEW || station_id == ScriptStation::STATION_JOIN_ADJACENT || ScriptStation::IsValidStation(station_id));
return ScriptObject::Command<CMD_BUILD_DOCK>::Do(tile, ScriptStation::IsValidStation(station_id) ? station_id : INVALID_STATION, station_id != ScriptStation::STATION_JOIN_ADJACENT);
}
/* static */ bool ScriptMarine::BuildBuoy(TileIndex tile)
{
EnforceCompanyModeValid(false);
EnforcePrecondition(false, ::IsValidTile(tile));
return ScriptObject::Command<CMD_BUILD_BUOY>::Do(tile);
}
/* static */ bool ScriptMarine::BuildLock(TileIndex tile)
{
EnforceCompanyModeValid(false);
EnforcePrecondition(false, ::IsValidTile(tile));
return ScriptObject::Command<CMD_BUILD_LOCK>::Do(tile);
}
/* static */ bool ScriptMarine::BuildCanal(TileIndex tile)
{
EnforceCompanyModeValid(false);
EnforcePrecondition(false, ::IsValidTile(tile));
return ScriptObject::Command<CMD_BUILD_CANAL>::Do(tile, tile, WATER_CLASS_CANAL, false);
}
/* static */ bool ScriptMarine::RemoveWaterDepot(TileIndex tile)
{
EnforceCompanyModeValid(false);
EnforcePrecondition(false, ::IsValidTile(tile));
EnforcePrecondition(false, IsWaterDepotTile(tile));
return ScriptObject::Command<CMD_LANDSCAPE_CLEAR>::Do(tile);
}
/* static */ bool ScriptMarine::RemoveDock(TileIndex tile)
{
EnforceCompanyModeValid(false);
EnforcePrecondition(false, ::IsValidTile(tile));
EnforcePrecondition(false, IsDockTile(tile));
return ScriptObject::Command<CMD_LANDSCAPE_CLEAR>::Do(tile);
}
/* static */ bool ScriptMarine::RemoveBuoy(TileIndex tile)
{
EnforceCompanyModeValid(false);
EnforcePrecondition(false, ::IsValidTile(tile));
EnforcePrecondition(false, IsBuoyTile(tile));
return ScriptObject::Command<CMD_LANDSCAPE_CLEAR>::Do(tile);
}
/* static */ bool ScriptMarine::RemoveLock(TileIndex tile)
{
EnforceCompanyModeValid(false);
EnforcePrecondition(false, ::IsValidTile(tile));
EnforcePrecondition(false, IsLockTile(tile));
return ScriptObject::Command<CMD_LANDSCAPE_CLEAR>::Do(tile);
}
/* static */ bool ScriptMarine::RemoveCanal(TileIndex tile)
{
EnforceCompanyModeValid(false);
EnforcePrecondition(false, ::IsValidTile(tile));
EnforcePrecondition(false, IsCanalTile(tile));
return ScriptObject::Command<CMD_LANDSCAPE_CLEAR>::Do(tile);
}
/* static */ Money ScriptMarine::GetBuildCost(BuildType build_type)
{
switch (build_type) {
case BT_DOCK: return ::GetPrice(PR_BUILD_STATION_DOCK, 1, nullptr);
case BT_DEPOT: return ::GetPrice(PR_BUILD_DEPOT_SHIP, 1, nullptr);
case BT_BUOY: return ::GetPrice(PR_BUILD_WAYPOINT_BUOY, 1, nullptr);
case BT_LOCK: return ::GetPrice(PR_BUILD_LOCK, 1, nullptr);
case BT_CANAL: return ::GetPrice(PR_BUILD_CANAL, 1, nullptr);
default: return -1;
}
}
|