diff options
author | rubidium <rubidium@openttd.org> | 2007-06-21 14:32:27 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-06-21 14:32:27 +0000 |
commit | f806b46cc967202db3d2fbf3384d0f037c13ed8a (patch) | |
tree | 4d9bfa9de886f7ff167c4fa02326f5cd302e8cce /src | |
parent | 06fded123a346d556ceb2f4585429046ddf8f1b9 (diff) | |
download | openttd-f806b46cc967202db3d2fbf3384d0f037c13ed8a.tar.xz |
(svn r10246) -Fix (r10297): some forgotten money conversions and truncation issues. Thanks to benc for providing the patch.
Diffstat (limited to 'src')
-rw-r--r-- | src/ai/default/default.cpp | 22 | ||||
-rw-r--r-- | src/ai/trolly/trolly.cpp | 3 | ||||
-rw-r--r-- | src/aircraft_cmd.cpp | 2 | ||||
-rw-r--r-- | src/autoreplace_cmd.cpp | 2 | ||||
-rw-r--r-- | src/bridge_gui.cpp | 2 | ||||
-rw-r--r-- | src/build_vehicle_gui.cpp | 12 | ||||
-rw-r--r-- | src/command.cpp | 6 | ||||
-rw-r--r-- | src/command.h | 2 | ||||
-rw-r--r-- | src/economy.cpp | 28 | ||||
-rw-r--r-- | src/fileio.cpp | 14 | ||||
-rw-r--r-- | src/functions.h | 4 | ||||
-rw-r--r-- | src/gui.h | 2 | ||||
-rw-r--r-- | src/macros.h | 8 | ||||
-rw-r--r-- | src/main_gui.cpp | 4 | ||||
-rw-r--r-- | src/misc_gui.cpp | 8 | ||||
-rw-r--r-- | src/network/network.h | 6 | ||||
-rw-r--r-- | src/newgrf_engine.cpp | 24 | ||||
-rw-r--r-- | src/player.h | 2 | ||||
-rw-r--r-- | src/player_gui.cpp | 4 | ||||
-rw-r--r-- | src/rail_cmd.cpp | 2 | ||||
-rw-r--r-- | src/station_gui.cpp | 4 | ||||
-rw-r--r-- | src/town_gui.cpp | 2 | ||||
-rw-r--r-- | src/train_cmd.cpp | 2 | ||||
-rw-r--r-- | src/variables.h | 2 | ||||
-rw-r--r-- | src/vehicle_gui.cpp | 9 |
25 files changed, 94 insertions, 82 deletions
diff --git a/src/ai/default/default.cpp b/src/ai/default/default.cpp index a5bc10514..d0b5e7fba 100644 --- a/src/ai/default/default.cpp +++ b/src/ai/default/default.cpp @@ -132,7 +132,7 @@ static void AiStateVehLoop(Player *p) p->ai.state_counter = 0; } -static EngineID AiChooseTrainToBuild(RailType railtype, int32 money, byte flag, TileIndex tile) +static EngineID AiChooseTrainToBuild(RailType railtype, Money money, byte flag, TileIndex tile) { EngineID best_veh_index = INVALID_ENGINE; byte best_veh_score = 0; @@ -161,7 +161,7 @@ static EngineID AiChooseTrainToBuild(RailType railtype, int32 money, byte flag, return best_veh_index; } -static EngineID AiChooseRoadVehToBuild(CargoID cargo, int32 money, TileIndex tile) +static EngineID AiChooseRoadVehToBuild(CargoID cargo, Money money, TileIndex tile) { EngineID best_veh_index = INVALID_ENGINE; int32 best_veh_rating = 0; @@ -199,10 +199,10 @@ static EngineID AiChooseRoadVehToBuild(CargoID cargo, int32 money, TileIndex til return best_veh_index; } -static EngineID AiChooseAircraftToBuild(int32 money, byte flag) +static EngineID AiChooseAircraftToBuild(Money money, byte flag) { EngineID best_veh_index = INVALID_ENGINE; - int32 best_veh_cost = 0; + Money best_veh_cost = 0; EngineID i; for (i = AIRCRAFT_ENGINES_INDEX; i != AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; i++) { @@ -225,9 +225,9 @@ static EngineID AiChooseAircraftToBuild(int32 money, byte flag) return best_veh_index; } -static int32 AiGetBasePrice(const Player* p) +static Money AiGetBasePrice(const Player* p) { - int32 base = _price.station_value; + Money base = _price.station_value; // adjust base price when more expensive vehicles are available switch (p->ai.railtype_to_use) { @@ -242,7 +242,7 @@ static int32 AiGetBasePrice(const Player* p) } #if 0 -static EngineID AiChooseShipToBuild(byte cargo, int32 money) +static EngineID AiChooseShipToBuild(byte cargo, Money money) { // XXX: not done return INVALID_ENGINE; @@ -251,13 +251,13 @@ static EngineID AiChooseShipToBuild(byte cargo, int32 money) static EngineID AiChooseRoadVehToReplaceWith(const Player* p, const Vehicle* v) { - int32 avail_money = p->player_money + v->value; + Money avail_money = p->player_money + v->value; return AiChooseRoadVehToBuild(v->cargo_type, avail_money, v->tile); } static EngineID AiChooseAircraftToReplaceWith(const Player* p, const Vehicle* v) { - int32 avail_money = p->player_money + v->value; + Money avail_money = p->player_money + v->value; return AiChooseAircraftToBuild( avail_money, AircraftVehInfo(v->engine_type)->subtype & AIR_CTOL ); @@ -265,7 +265,7 @@ static EngineID AiChooseAircraftToReplaceWith(const Player* p, const Vehicle* v) static EngineID AiChooseTrainToReplaceWith(const Player* p, const Vehicle* v) { - int32 avail_money = p->player_money + v->value; + Money avail_money = p->player_money + v->value; const Vehicle* u = v; int num = 0; @@ -3901,7 +3901,7 @@ static void AiHandleTakeover(Player *p) static void AiAdjustLoan(const Player* p) { - int32 base = AiGetBasePrice(p); + Money base = AiGetBasePrice(p); if (p->player_money > base * 1400) { // Decrease loan diff --git a/src/ai/trolly/trolly.cpp b/src/ai/trolly/trolly.cpp index fb0263d41..1f540ceed 100644 --- a/src/ai/trolly/trolly.cpp +++ b/src/ai/trolly/trolly.cpp @@ -97,7 +97,6 @@ static void AiNew_State_Nothing(Player *p) // - Build HQ static void AiNew_State_WakeUp(Player *p) { - int32 money; int c; assert(p->ainew.state == AI_STATE_WAKE_UP); // First, check if we have a HQ @@ -111,7 +110,7 @@ static void AiNew_State_WakeUp(Player *p) return; } - money = p->player_money - AI_MINIMUM_MONEY; + Money money = p->player_money - AI_MINIMUM_MONEY; // Let's pick an action! if (p->ainew.action == AI_ACTION_NONE) { diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index b92039ed5..2f4f90daa 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -347,7 +347,7 @@ CommandCost CmdBuildAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) v->subtype = (avi->subtype & AIR_CTOL ? AIR_AIRCRAFT : AIR_HELICOPTER); v->UpdateDeltaXY(INVALID_DIR); - v->value = (uint32)value.GetCost(); + v->value = value.GetCost(); u->subtype = AIR_SHADOW; u->UpdateDeltaXY(INVALID_DIR); diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp index 37e0f79d8..14c5e3310 100644 --- a/src/autoreplace_cmd.cpp +++ b/src/autoreplace_cmd.cpp @@ -124,7 +124,7 @@ static CargoID GetNewCargoTypeForReplace(Vehicle *v, EngineID engine_type) * @param flags is the flags to use when calling DoCommand(). Mainly DC_EXEC counts * @return value is cost of the replacement or CMD_ERROR */ -static CommandCost ReplaceVehicle(Vehicle **w, byte flags, int32 total_cost) +static CommandCost ReplaceVehicle(Vehicle **w, byte flags, Money total_cost) { CommandCost cost; CommandCost sell_value; diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp index da0cd4a88..238ac1698 100644 --- a/src/bridge_gui.cpp +++ b/src/bridge_gui.cpp @@ -22,7 +22,7 @@ static struct BridgeData { TileIndex end_tile; byte type; byte indexes[MAX_BRIDGES]; - int32 costs[MAX_BRIDGES]; + Money costs[MAX_BRIDGES]; } _bridgedata; void CcBuildBridge(bool success, TileIndex tile, uint32 p1, uint32 p2) diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index 517ad7b52..94647881d 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -206,9 +206,9 @@ static int CDECL TrainEngineRunningCostSorter(const void *a, const void *b) const RailVehicleInfo *rvi_a = RailVehInfo(*(const EngineID*)a); const RailVehicleInfo *rvi_b = RailVehInfo(*(const EngineID*)b); - int va = rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class] * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1); - int vb = rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class] * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1); - int r = va - vb; + Money va = rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class] * (rvi_a->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1); + Money vb = rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class] * (rvi_b->railveh_type == RAILVEH_MULTIHEAD ? 2 : 1); + int r = ClampToI32(va - vb); return _internal_sort_order ? -r : r; } @@ -224,9 +224,9 @@ static int CDECL TrainEnginePowerVsRunningCostSorter(const void *a, const void * * Because of this, the return value have to be reversed as well and we return b - a instead of a - b. * Another thing is that both power and running costs should be doubled for multiheaded engines. * Since it would be multipling with 2 in both numerator and denumerator, it will even themselves out and we skip checking for multiheaded. */ - int va = (rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class]) / max((uint16)1, rvi_a->power); - int vb = (rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class]) / max((uint16)1, rvi_b->power); - int r = vb - va; + Money va = (rvi_a->running_cost_base * _price.running_rail[rvi_a->running_cost_class]) / max((uint16)1, rvi_a->power); + Money vb = (rvi_b->running_cost_base * _price.running_rail[rvi_b->running_cost_class]) / max((uint16)1, rvi_b->power); + int r = ClampToI32(vb - va); return _internal_sort_order ? -r : r; } diff --git a/src/command.cpp b/src/command.cpp index a400307dc..3aa93777c 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -418,10 +418,10 @@ error: return res; } -int32 GetAvailableMoneyForCommand() +Money GetAvailableMoneyForCommand() { PlayerID pid = _current_player; - if (!IsValidPlayer(pid)) return 0x7FFFFFFF; // max int + if (!IsValidPlayer(pid)) return INT64_MAX; return GetPlayer(pid)->player_money; } @@ -568,7 +568,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, if (IsLocalPlayer() && _game_mode != GM_EDITOR) { if (res2.GetCost() != 0) ShowCostOrIncomeAnimation(x, y, GetSlopeZ(x, y), res2.GetCost()); - if (_additional_cash_required) { + if (_additional_cash_required != 0) { SetDParam(0, _additional_cash_required); ShowErrorMessage(STR_0003_NOT_ENOUGH_CASH_REQUIRES, error_part1, x, y); if (res2.GetCost() == 0) goto callb_err; diff --git a/src/command.h b/src/command.h index 6f2014765..c19027a31 100644 --- a/src/command.h +++ b/src/command.h @@ -212,6 +212,6 @@ extern const char* _cmd_text; ///< Text, which gets sent with a command bool IsValidCommand(uint cmd); byte GetCommandFlags(uint cmd); -int32 GetAvailableMoneyForCommand(); +Money GetAvailableMoneyForCommand(); #endif /* COMMAND_H */ diff --git a/src/economy.cpp b/src/economy.cpp index fde538feb..b9813a7ea 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -112,7 +112,7 @@ int UpdateCompanyRatingAndValue(Player *p, bool update) /* Count vehicles */ { Vehicle *v; - int32 min_profit = 0; + Money min_profit = 0; bool min_profit_first = true; uint num = 0; @@ -135,7 +135,7 @@ int UpdateCompanyRatingAndValue(Player *p, bool update) _score_part[owner][SCORE_VEHICLES] = num; /* Don't allow negative min_profit to show */ if (min_profit > 0) - _score_part[owner][SCORE_MIN_PROFIT] = min_profit; + _score_part[owner][SCORE_MIN_PROFIT] = ClampToI32(min_profit); } /* Count stations */ @@ -163,9 +163,9 @@ int UpdateCompanyRatingAndValue(Player *p, bool update) } while (++pee,--numec); if (min_income > 0) - _score_part[owner][SCORE_MIN_INCOME] = min_income; + _score_part[owner][SCORE_MIN_INCOME] = ClampToI32(min_income); - _score_part[owner][SCORE_MAX_INCOME] = max_income; + _score_part[owner][SCORE_MAX_INCOME] = ClampToI32(max_income); } } @@ -196,15 +196,14 @@ int UpdateCompanyRatingAndValue(Player *p, bool update) /* Generate score for player money */ { - int32 money = p->player_money; - if (money > 0) { - _score_part[owner][SCORE_MONEY] = money; + if (p->player_money > 0) { + _score_part[owner][SCORE_MONEY] = ClampToI32(p->player_money); } } /* Generate score for loan */ { - _score_part[owner][SCORE_LOAN] = _score_info[SCORE_LOAN].needed - p->current_loan; + _score_part[owner][SCORE_LOAN] = ClampToI32(_score_info[SCORE_LOAN].needed - p->current_loan); } /* Now we calculate the score for each item.. */ @@ -438,7 +437,6 @@ static void ChangeNetworkOwner(PlayerID current_player, PlayerID new_player) static void PlayersCheckBankrupt(Player *p) { PlayerID owner; - int64 val; /* If the player has money again, it does not go bankrupt */ if (p->player_money >= 0) { @@ -466,7 +464,7 @@ static void PlayersCheckBankrupt(Player *p) /* Check if the company has any value.. if not, declare it bankrupt * right now */ - val = CalculateCompanyValue(p); + Money val = CalculateCompanyValue(p); if (val > 0) { p->bankrupt_value = val; p->bankrupt_asked = 1 << owner; // Don't ask the owner @@ -1319,11 +1317,11 @@ static bool CheckSubsidised(Station *from, Station *to, CargoID cargo_type) return false; } -static int32 DeliverGoods(int num_pieces, CargoID cargo_type, StationID source, StationID dest, TileIndex source_tile, byte days_in_transit) +static Money DeliverGoods(int num_pieces, CargoID cargo_type, StationID source, StationID dest, TileIndex source_tile, byte days_in_transit) { bool subsidised; Station *s_from, *s_to; - int32 profit; + Money profit; assert(num_pieces > 0); @@ -1511,7 +1509,7 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left) bool anything_loaded = false; uint32 cargo_not_full = 0; uint32 cargo_full = 0; - int total_cargo_feeder_share = 0; // the feeder cash amount for the goods being loaded/unloaded in this load step + Money total_cargo_feeder_share = 0; // the feeder cash amount for the goods being loaded/unloaded in this load step v->cur_speed = 0; @@ -1603,7 +1601,7 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left) /* if last speed is 0, we treat that as if no vehicle has ever visited the station. */ ge->days_since_pickup = 0; ge->last_speed = min(t, 255); - ge->last_age = _cur_year - v->build_year; + ge->last_age = _cur_year - u->build_year; /* If there's goods waiting at the station, and the vehicle * has capacity for it, load it on the vehicle. */ @@ -1643,7 +1641,7 @@ static void LoadUnloadVehicle(Vehicle *v, int *cargo_left) * ge->unload_pending holds the amount that has been credited, but has not yet been unloaded. */ int cargoshare = cap * 10000 / (ge->waiting_acceptance + ge->unload_pending); - int feeder_profit_share = ge->feeder_profit * cargoshare / 10000; + Money feeder_profit_share = ge->feeder_profit * cargoshare / 10000; v->cargo_count += cap; ge->waiting_acceptance -= cap; diff --git a/src/fileio.cpp b/src/fileio.cpp index b7c060fed..2b37dabf2 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -410,7 +410,9 @@ void ChangeWorkingDirectory(const char *exe) void DetermineBasePaths(const char *exe) { char tmp[MAX_PATH]; -#ifdef WITH_PERSONAL_DIR +#if defined(__MORPHOS__) || defined(__AMIGA__) || !defined(WITH_PERSONAL_DIR) + _searchpaths[SP_PERSONAL_DIR] = NULL; +#else const char *homedir = getenv("HOME"); if (homedir == NULL) { @@ -422,14 +424,16 @@ void DetermineBasePaths(const char *exe) AppendPathSeparator(tmp, MAX_PATH); _searchpaths[SP_PERSONAL_DIR] = strdup(tmp); -#else - _searchpaths[SP_PERSONAL_DIR] = NULL; #endif _searchpaths[SP_SHARED_DIR] = NULL; +#if defined(__MORPHOS__) || defined(__AMIGA__) + _searchpaths[SP_WORKING_DIR] = NULL; +#else getcwd(tmp, MAX_PATH); AppendPathSeparator(tmp, MAX_PATH); _searchpaths[SP_WORKING_DIR] = strdup(tmp); +#endif /* Change the working directory to that one of the executable */ ChangeWorkingDirectory((char*)exe); @@ -437,9 +441,13 @@ void DetermineBasePaths(const char *exe) AppendPathSeparator(tmp, MAX_PATH); _searchpaths[SP_BINARY_DIR] = strdup(tmp); +#if defined(__MORPHOS__) || defined(__AMIGA__) + _searchpaths[SP_INSTALLATION_DIR] = NULL; +#else snprintf(tmp, MAX_PATH, "%s", GLOBAL_DATA_DIR); AppendPathSeparator(tmp, MAX_PATH); _searchpaths[SP_INSTALLATION_DIR] = strdup(tmp); +#endif #ifdef WITH_COCOA extern void cocoaSetApplicationBundleDir(); cocoaSetApplicationBundleDir(); diff --git a/src/functions.h b/src/functions.h index 9edddce4b..ba6d737e3 100644 --- a/src/functions.h +++ b/src/functions.h @@ -139,8 +139,8 @@ void DrawSprite(SpriteID img, SpriteID pal, int x, int y); bool EnsureNoVehicle(TileIndex tile); bool EnsureNoVehicleOnGround(TileIndex tile); void MarkAllViewportsDirty(int left, int top, int right, int bottom); -void ShowCostOrIncomeAnimation(int x, int y, int z, int32 cost); -void ShowFeederIncomeAnimation(int x, int y, int z, int32 cost); +void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost); +void ShowFeederIncomeAnimation(int x, int y, int z, Money cost); bool CheckIfAuthorityAllows(TileIndex tile); Town *ClosestTownFromTile(TileIndex tile, uint threshold); @@ -105,7 +105,7 @@ void ShowPlayerStations(PlayerID player); void ShowPlayerFinances(PlayerID player); void ShowPlayerCompany(PlayerID player); -void ShowEstimatedCostOrIncome(int32 cost, int x, int y); +void ShowEstimatedCostOrIncome(Money cost, int x, int y); void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y); void DrawStationCoverageAreaText(int sx, int sy, uint mask,int rad); diff --git a/src/macros.h b/src/macros.h index c10ef4d49..406ae83da 100644 --- a/src/macros.h +++ b/src/macros.h @@ -51,6 +51,14 @@ static inline uint clampu(uint a, uint min, uint max) return a; } +/* Gracefully reduce a signed 64-bit int to signed 32-bit -- no bogusly truncating the sign bit */ +static inline int32 ClampToI32(int64 a) +{ + if (a <= (int32)0x80000000) return 0x80000000; + if (a >= (int32)0x7FFFFFFF) return 0x7FFFFFFF; + return (int32)a; +} + static inline int32 BIGMULSS(int32 a, int32 b, int shift) { return (int32)((int64)a * (int64)b >> shift); diff --git a/src/main_gui.cpp b/src/main_gui.cpp index 430d9948f..a7896b62d 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -94,10 +94,10 @@ void HandleOnEditText(const char *str) const Player *p = GetPlayer(_current_player); Money money = min(p->player_money - p->current_loan, atoi(str) / _currency->rate); - money = clamp(money, 0, 20000000); // Clamp between 20 million and 0 + uint32 money_c = clamp(ClampToI32(money), 0, 20000000); // Clamp between 20 million and 0 /* Give 'id' the money, and substract it from ourself */ - DoCommandP(0, money, id, CcGiveMoney, CMD_GIVE_MONEY | CMD_MSG(STR_INSUFFICIENT_FUNDS)); + DoCommandP(0, money_c, id, CcGiveMoney, CMD_GIVE_MONEY | CMD_MSG(STR_INSUFFICIENT_FUNDS)); } break; #endif /* ENABLE_NETWORK */ default: NOT_REACHED(); diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 5ab378297..64fba654c 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -104,7 +104,7 @@ static void Place_LandInfo(TileIndex tile) t = ClosestTownFromTile(tile, _patches.dist_local_authority); old_money = p->player_money; - p->player_money = 0x7fffffff; + p->player_money = INT64_MAX; costclear = DoCommand(tile, 0, 0, 0, CMD_LANDSCAPE_CLEAR); p->player_money = old_money; @@ -610,7 +610,7 @@ void ShowErrorMessage(StringID msg_1, StringID msg_2, int x, int y) } -void ShowEstimatedCostOrIncome(int32 cost, int x, int y) +void ShowEstimatedCostOrIncome(Money cost, int x, int y) { StringID msg = STR_0805_ESTIMATED_COST; @@ -622,7 +622,7 @@ void ShowEstimatedCostOrIncome(int32 cost, int x, int y) ShowErrorMessage(INVALID_STRING_ID, msg, x, y); } -void ShowCostOrIncomeAnimation(int x, int y, int z, int32 cost) +void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost) { StringID msg; Point pt = RemapCoords(x,y,z); @@ -636,7 +636,7 @@ void ShowCostOrIncomeAnimation(int x, int y, int z, int32 cost) AddTextEffect(msg, pt.x, pt.y, 0x250); } -void ShowFeederIncomeAnimation(int x, int y, int z, int32 cost) +void ShowFeederIncomeAnimation(int x, int y, int z, Money cost) { Point pt = RemapCoords(x,y,z); diff --git a/src/network/network.h b/src/network/network.h index 6cd534ec9..c20e9b3f8 100644 --- a/src/network/network.h +++ b/src/network/network.h @@ -44,9 +44,9 @@ struct NetworkPlayerInfo { char company_name[NETWORK_NAME_LENGTH]; // Company name char password[NETWORK_PASSWORD_LENGTH]; // The password for the player Year inaugurated_year; // What year the company started in - int64 company_value; // The company value - int64 money; // The amount of money the company has - int64 income; // How much did the company earned last year + Money company_value; // The company value + Money money; // The amount of money the company has + Money income; // How much did the company earned last year uint16 performance; // What was his performance last month? bool use_password; // Is there a password uint16 num_vehicle[NETWORK_VEHICLE_TYPES]; // How many vehicles are there of this type? diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index 7a3e980eb..fc2dacdcf 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -727,19 +727,19 @@ static uint32 VehicleGetVariable(const ResolverObject *object, byte variable, by case 0x4F: return GB(v->reliability, 8, 8); case 0x50: return v->reliability_spd_dec; case 0x51: return GB(v->reliability_spd_dec, 8, 8); - case 0x52: return v->profit_this_year; - case 0x53: return GB(v->profit_this_year, 8, 24); - case 0x54: return GB(v->profit_this_year, 16, 16); - case 0x55: return GB(v->profit_this_year, 24, 8); - case 0x56: return v->profit_last_year; - case 0x57: return GB(v->profit_last_year, 8, 24); - case 0x58: return GB(v->profit_last_year, 16, 16); - case 0x59: return GB(v->profit_last_year, 24, 8); + case 0x52: return ClampToI32(v->profit_this_year); + case 0x53: return GB(ClampToI32(v->profit_this_year), 8, 24); + case 0x54: return GB(ClampToI32(v->profit_this_year), 16, 16); + case 0x55: return GB(ClampToI32(v->profit_this_year), 24, 8); + case 0x56: return ClampToI32(v->profit_last_year); + case 0x57: return GB(ClampToI32(v->profit_last_year), 8, 24); + case 0x58: return GB(ClampToI32(v->profit_last_year), 16, 16); + case 0x59: return GB(ClampToI32(v->profit_last_year), 24, 8); case 0x5A: return v->next == NULL ? INVALID_VEHICLE : v->next->index; - case 0x5C: return v->value; - case 0x5D: return GB(v->value, 8, 24); - case 0x5E: return GB(v->value, 16, 16); - case 0x5F: return GB(v->value, 24, 8); + case 0x5C: return ClampToI32(v->value); + case 0x5D: return GB(ClampToI32(v->value), 8, 24); + case 0x5E: return GB(ClampToI32(v->value), 16, 16); + case 0x5F: return GB(ClampToI32(v->value), 24, 8); case 0x60: return v->string_id; case 0x61: return GB(v->string_id, 8, 8); case 0x72: return v->cargo_subtype; diff --git a/src/player.h b/src/player.h index 5c0825662..45a7a4518 100644 --- a/src/player.h +++ b/src/player.h @@ -116,7 +116,7 @@ struct PlayerAiNew { CargoID cargo; byte tbt; ///< train/bus/truck 0/1/2 AI_TRAIN/AI_BUS/AI_TRUCK - int new_cost; + Money new_cost; byte action; diff --git a/src/player_gui.cpp b/src/player_gui.cpp index 2f307570d..a56d05c78 100644 --- a/src/player_gui.cpp +++ b/src/player_gui.cpp @@ -31,8 +31,8 @@ static void DoShowPlayerFinances(PlayerID player, bool show_small, bool show_sti static void DrawPlayerEconomyStats(const Player *p, byte mode) { int x, y, i, j, year; - const int64 (*tbl)[13]; - int64 sum, cost; + const Money (*tbl)[13]; + Money sum, cost; StringID str; if (!(mode & 1)) { // normal sized economics window (mode&1) is minimized status diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 9c9dc791a..6dc6d36a6 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -974,7 +974,7 @@ extern CommandCost DoConvertTunnelBridgeRail(TileIndex tile, RailType totype, bo CommandCost CmdConvertRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) { CommandCost ret, cost; - int32 money; + Money money; int ex; int ey; int sx, sy, x, y; diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 045f927b9..dd8e8a99c 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -131,14 +131,14 @@ static int CDECL StationWaitingSorter(const void *a, const void *b) { const Station* st1 = *(const Station**)a; const Station* st2 = *(const Station**)b; - int sum1 = 0, sum2 = 0; + Money sum1 = 0, sum2 = 0; for (CargoID j = 0; j < NUM_CARGO; j++) { if (st1->goods[j].waiting_acceptance & 0xfff) sum1 += GetTransportedGoodsIncome(st1->goods[j].waiting_acceptance & 0xfff, 20, 50, j); if (st2->goods[j].waiting_acceptance & 0xfff) sum2 += GetTransportedGoodsIncome(st2->goods[j].waiting_acceptance & 0xfff, 20, 50, j); } - return (_internal_sort_order & 1) ? sum2 - sum1 : sum1 - sum2; + return (_internal_sort_order & 1) ? ClampToI32(sum2 - sum1) : ClampToI32(sum1 - sum2); } /** diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 565a7ecec..bb46c0c17 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -41,7 +41,7 @@ extern const byte _town_action_costs[8]; */ uint GetMaskOfTownActions(int *nump, PlayerID pid, const Town *t) { - int32 avail, ref; + Money avail, ref; int num = 0; uint avail_buttons = 0x7F; // by default all buttons except bribe are enabled. uint buttons = 0; diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 065e6db02..1d5a88877 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -1248,7 +1248,7 @@ CommandCost CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) IsTrainEngine(v)) ? v->u.rail.other_multiheaded_part : NULL; if (rear != NULL) { - cost.AddCost(-(int64)rear->value); + cost.AddCost(-rear->value); if (flags & DC_EXEC) { UnlinkWagon(rear, first); DeleteDepotHighlightOfVehicle(rear); diff --git a/src/variables.h b/src/variables.h index a45ef3e6e..d62c6f250 100644 --- a/src/variables.h +++ b/src/variables.h @@ -286,7 +286,7 @@ VARDEF uint32 _news_display_opt; VARDEF bool _news_ticker_sound; VARDEF StringID _error_message; -VARDEF int32 _additional_cash_required; +VARDEF Money _additional_cash_required; VARDEF uint32 _decode_parameters[20]; diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index fca73e38b..b9bd7bb31 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -589,7 +589,7 @@ static int CDECL VehicleProfitThisYearSorter(const void *a, const void *b) { const Vehicle* va = *(const Vehicle**)a; const Vehicle* vb = *(const Vehicle**)b; - int r = va->profit_this_year - vb->profit_this_year; + int r = ClampToI32(va->profit_this_year - vb->profit_this_year); VEHICLEUNITNUMBERSORTER(r, va, vb); @@ -600,7 +600,7 @@ static int CDECL VehicleProfitLastYearSorter(const void *a, const void *b) { const Vehicle* va = *(const Vehicle**)a; const Vehicle* vb = *(const Vehicle**)b; - int r = va->profit_last_year - vb->profit_last_year; + int r = ClampToI32(va->profit_last_year - vb->profit_last_year); VEHICLEUNITNUMBERSORTER(r, va, vb); @@ -687,13 +687,12 @@ static int CDECL VehicleValueSorter(const void *a, const void *b) const Vehicle* va = *(const Vehicle**)a; const Vehicle* vb = *(const Vehicle**)b; const Vehicle *u; - int valuea = 0, valueb = 0; - int r; + Money valuea = 0, valueb = 0; for (u = va; u != NULL; u = u->next) valuea += u->value; for (u = vb; u != NULL; u = u->next) valueb += u->value; - r = valuea - valueb; + int r = ClampToI32(valuea - valueb); VEHICLEUNITNUMBERSORTER(r, va, vb); |