Some adjustments for better cmserver compatibility
This commit is contained in:
@@ -42,12 +42,15 @@ struct HouseRebuilt {
|
||||
struct HouseBuilt {
|
||||
Town *town;
|
||||
TileIndex tile;
|
||||
HouseID house_id;
|
||||
const HouseSpec *house_spec;
|
||||
bool is_rebuilding;
|
||||
};
|
||||
|
||||
struct HouseCleared {
|
||||
Town *town;
|
||||
TileIndex tile;
|
||||
HouseID house_id;
|
||||
const HouseSpec *house_spec;
|
||||
bool was_completed; ///< whether house was completed before destruction
|
||||
};
|
||||
@@ -55,6 +58,7 @@ struct HouseCleared {
|
||||
struct HouseCompleted {
|
||||
Town *town;
|
||||
TileIndex tile;
|
||||
HouseID house_id;
|
||||
const HouseSpec *house_spec;
|
||||
};
|
||||
|
||||
|
||||
@@ -31,29 +31,29 @@ Game::Game() {
|
||||
this->events.listen<event::TownGrowthSucceeded>([this] (const event::TownGrowthSucceeded &event) {
|
||||
if (event.town->cache.num_houses <= event.prev_houses) {
|
||||
event.town->cm.hs_total++;
|
||||
this->towns_growth_tiles[event.tile] = TownGrowthTileState::HS;
|
||||
this->set_town_growth_tile(event.tile, TownGrowthTileState::HS);
|
||||
}
|
||||
});
|
||||
|
||||
this->events.listen<event::TownGrowthFailed>([this] (const event::TownGrowthFailed &event) {
|
||||
event.town->cm.cs_total++;
|
||||
this->towns_growth_tiles[event.tile] = TownGrowthTileState::CS;
|
||||
this->set_town_growth_tile(event.tile, TownGrowthTileState::CS);
|
||||
});
|
||||
|
||||
this->events.listen<event::HouseRebuilt>([this] (const event::HouseRebuilt &event) {
|
||||
if (event.was_successful) {
|
||||
event.town->cm.houses_reconstructed_this_month++;
|
||||
this->towns_growth_tiles[event.tile] = TownGrowthTileState::RH_REBUILT;
|
||||
this->set_town_growth_tile(event.tile, TownGrowthTileState::RH_REBUILT);
|
||||
} else {
|
||||
event.town->cm.houses_demolished_this_month++;
|
||||
this->towns_growth_tiles[event.tile] = TownGrowthTileState::RH_REMOVED;
|
||||
this->set_town_growth_tile(event.tile, TownGrowthTileState::RH_REMOVED);
|
||||
}
|
||||
});
|
||||
|
||||
this->events.listen<event::HouseBuilt>([this] (const event::HouseBuilt &event) {
|
||||
event.town->cm.houses_constructing++;
|
||||
event.town->cm.real_population += event.house_spec->population;
|
||||
this->towns_growth_tiles[event.tile] = TownGrowthTileState::NEW_HOUSE;
|
||||
this->set_town_growth_tile(event.tile, TownGrowthTileState::NEW_HOUSE);
|
||||
});
|
||||
|
||||
this->events.listen<event::HouseCleared>([this] (const event::HouseCleared &event) {
|
||||
@@ -86,4 +86,8 @@ Game::Game() {
|
||||
});
|
||||
}
|
||||
|
||||
void Game::set_town_growth_tile(TileIndex tile, TownGrowthTileState state) {
|
||||
if (this->towns_growth_tiles[tile] < state) this->towns_growth_tiles[tile] = state;
|
||||
}
|
||||
|
||||
} // namespace citymania
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef CMEXT_GAME_HPP
|
||||
#define CMEXT_GAME_HPP
|
||||
#ifndef CM_GAME_HPP
|
||||
#define CM_GAME_HPP
|
||||
|
||||
#include "../town.h"
|
||||
|
||||
@@ -27,6 +27,7 @@ public:
|
||||
event::Dispatcher events;
|
||||
|
||||
Game();
|
||||
void set_town_growth_tile(TileIndex tile, TownGrowthTileState state);
|
||||
};
|
||||
|
||||
} // namespace citymania
|
||||
|
||||
@@ -13,7 +13,7 @@ void ResetGame() {
|
||||
}
|
||||
|
||||
void SwitchToMode(SwitchMode new_mode) {
|
||||
ResetGame();
|
||||
if (new_mode != SM_SAVE_GAME) ResetGame();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -263,30 +263,30 @@ static u8vector EncodeData() {
|
||||
bs.Reserve(1000);
|
||||
bs.WriteBytes(SAVEGAME_DATA_FORMAT_VERSION, 2);
|
||||
bs.WriteBytes(_last_client_version, 2);
|
||||
bs.WriteBytes(_settings_game.cm.controller_type, 1);
|
||||
bs.WriteBytes(_settings_game.citymania.controller_type, 1);
|
||||
bs.WriteBytes(_date, 4); // Just in case we'll need to detect that game
|
||||
bs.WriteBytes(_date_fract, 1); // was saved by unmodified client
|
||||
bs.WriteBytes(_settings_game.cm.game_type, 1);
|
||||
bs.WriteBytes(_settings_game.citymania.game_type, 1);
|
||||
bs.WriteBytes(0, 3); // Reserved
|
||||
bs.WriteBytes(0, 4); // Reserved
|
||||
EncodeSettings(bs, _settings_game.cm);
|
||||
EncodeSettings(bs, _settings_game.citymania);
|
||||
EncodeCompanies(bs);
|
||||
EncodeTowns(bs);
|
||||
EncodeTownsGrowthTiles(bs, _game->towns_growth_tiles);
|
||||
EncodeTownsGrowthTiles(bs, _game->towns_growth_tiles_last_month);
|
||||
if (_settings_game.cm.controller_type == 4)
|
||||
if (_settings_game.citymania.controller_type == 4)
|
||||
CBController_saveload_encode(bs);
|
||||
|
||||
return bs.GetVector();
|
||||
}
|
||||
|
||||
static void DecodeDataV2(BitIStream &bs) {
|
||||
DecodeSettings(bs, _settings_game.cm);
|
||||
DecodeSettings(bs, _settings_game.citymania);
|
||||
DecodeCompanies(bs);
|
||||
DecodeTowns(bs);
|
||||
DecodeTownsGrowthTiles(bs, _game->towns_growth_tiles);
|
||||
DecodeTownsGrowthTiles(bs, _game->towns_growth_tiles_last_month);
|
||||
if (_settings_game.cm.controller_type == 4) CBController_saveload_decode(bs);
|
||||
if (_settings_game.citymania.controller_type == 4) CBController_saveload_decode(bs);
|
||||
}
|
||||
|
||||
static void DecodeTownsCargoV1(BitIStream &bs)
|
||||
@@ -332,7 +332,7 @@ static void DecodeTownsCargoV1(BitIStream &bs)
|
||||
}
|
||||
|
||||
static void DecodeDataV1(BitIStream &bs) {
|
||||
if (_settings_game.cm.controller_type != 0) DecodeTownsCargoV1(bs);
|
||||
if (_settings_game.citymania.controller_type != 0) DecodeTownsCargoV1(bs);
|
||||
for (Town *t : Town::Iterate()) {
|
||||
t->cm.growing_by_chance = bs.ReadBytes(1);
|
||||
t->cm.houses_reconstructed_this_month = bs.ReadBytes(2);
|
||||
@@ -379,15 +379,15 @@ static void DecodeData(u8vector &data) {
|
||||
}
|
||||
DEBUG(sl, 2, "CityMania savegame data version %u", version);
|
||||
_last_client_version = bs.ReadBytes(2);
|
||||
_settings_game.cm.controller_type = bs.ReadBytes(1);
|
||||
if (version <= 1) _settings_game.cm.controller_type = (_settings_game.cm.controller_type ? 4 : 0);
|
||||
_settings_game.citymania.controller_type = bs.ReadBytes(1);
|
||||
if (version <= 1) _settings_game.citymania.controller_type = (_settings_game.citymania.controller_type ? 4 : 0);
|
||||
int32 date = bs.ReadBytes(4);
|
||||
uint32 date_fract = bs.ReadBytes(1);
|
||||
if (date != _date || date_fract != _date_fract) {
|
||||
DEBUG(sl, 0, "Savegame was run in unmodified client, extra save data "
|
||||
"preserved, but may not be accurate");
|
||||
}
|
||||
_settings_game.cm.game_type = bs.ReadBytes(1);
|
||||
_settings_game.citymania.game_type = bs.ReadBytes(1);
|
||||
bs.ReadBytes(3); // reserved
|
||||
bs.ReadBytes(4); // reserved
|
||||
if (version == 1) DecodeDataV1(bs);
|
||||
|
||||
@@ -561,7 +561,7 @@ struct GameSettings {
|
||||
StationSettings station; ///< settings related to station management
|
||||
LocaleSettings locale; ///< settings related to used currency/unit system in the current game
|
||||
|
||||
citymania::Settings cm;
|
||||
citymania::Settings citymania;
|
||||
};
|
||||
|
||||
/** All settings that are only important for the local client. */
|
||||
|
||||
@@ -227,7 +227,7 @@ enum TownGrowthResult {
|
||||
// GROWTH_SEARCH_RUNNING >= 1
|
||||
};
|
||||
|
||||
static bool BuildTownHouse(Town *t, TileIndex tile);
|
||||
static bool BuildTownHouse(Town *t, TileIndex tile, bool is_rebuilding = false);
|
||||
static Town *CreateRandomTown(uint attempts, uint32 townnameparts, TownSize size, bool city, TownLayout layout);
|
||||
|
||||
static void TownDrawHouseLift(const TileInfo *ti)
|
||||
@@ -503,7 +503,7 @@ static void MakeSingleHouseBigger(TileIndex tile)
|
||||
ResetHouseAge(tile);
|
||||
|
||||
if (hs->building_flags & BUILDING_HAS_1_TILE)
|
||||
citymania::Emit(citymania::event::HouseCompleted{town, tile, hs});
|
||||
citymania::Emit(citymania::event::HouseCompleted{town, tile, house_id, hs});
|
||||
}
|
||||
MarkTileDirtyByTile(tile);
|
||||
}
|
||||
@@ -639,7 +639,7 @@ static void TileLoop_Town(TileIndex tile)
|
||||
|
||||
/* Rebuild with another house? */
|
||||
bool rebuild_res = false;
|
||||
if (GB(r, 24, 8) >= 12) rebuild_res = BuildTownHouse(t, tile);
|
||||
if (GB(r, 24, 8) >= 12) rebuild_res = BuildTownHouse(t, tile, true);
|
||||
citymania::Emit(citymania::event::HouseRebuilt{t, tile, rebuild_res});
|
||||
}
|
||||
|
||||
@@ -2474,7 +2474,7 @@ static bool CheckTownBuild2x2House(TileIndex *tile, Town *t, int maxz, bool nosl
|
||||
* @param tile where the house will be built
|
||||
* @return false iff no house can be built at this tile
|
||||
*/
|
||||
static bool BuildTownHouse(Town *t, TileIndex tile)
|
||||
static bool BuildTownHouse(Town *t, TileIndex tile, bool is_rebuilding)
|
||||
{
|
||||
/* forbidden building here by town layout */
|
||||
if (!TownLayoutAllowsHouseHere(t, tile)) return false;
|
||||
@@ -2621,8 +2621,10 @@ static bool BuildTownHouse(Town *t, TileIndex tile)
|
||||
UpdateTownGrowthRate(t);
|
||||
UpdateTownCargoes(t, tile);
|
||||
|
||||
citymania::Emit(citymania::event::HouseBuilt{t, tile, hs});
|
||||
if (completed) citymania::Emit(citymania::event::HouseCompleted{t, tile, hs});
|
||||
if (!_generating_world) {
|
||||
citymania::Emit(citymania::event::HouseBuilt{t, tile, house, hs, is_rebuilding});
|
||||
if (completed) citymania::Emit(citymania::event::HouseCompleted{t, tile, house, hs});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -2712,7 +2714,7 @@ void ClearTownHouse(Town *t, TileIndex tile)
|
||||
/* Update cargo acceptance. */
|
||||
UpdateTownCargoes(t, tile);
|
||||
|
||||
citymania::Emit(citymania::event::HouseCleared{t, tile, hs, is_completed});
|
||||
citymania::Emit(citymania::event::HouseCleared{t, tile, house, hs, is_completed});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user