widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #03361
[Merge] lp:~widelands-dev/widelands/clang-for-ai-files into lp:widelands
TiborB has proposed merging lp:~widelands-dev/widelands/clang-for-ai-files into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/clang-for-ai-files/+merge/244508
This is simple reformatting with clang-format on three files as requested by SirVer here: https://code.launchpad.net/~widelands-dev/widelands/seafaring-ai/+merge/242271/comments/601220
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/clang-for-ai-files into lp:widelands.
=== modified file 'src/economy/portdock.cc'
--- src/economy/portdock.cc 2014-11-28 16:40:55 +0000
+++ src/economy/portdock.cc 2014-12-11 21:38:11 +0000
@@ -46,20 +46,16 @@
return g_portdock_descr;
}
-
PortdockDescr::PortdockDescr(char const* const _name, char const* const _descname)
- :
- MapObjectDescr(MapObjectType::PORTDOCK, _name, _descname)
-{
+ : MapObjectDescr(MapObjectType::PORTDOCK, _name, _descname) {
}
-PortDock::PortDock(Warehouse* wh) :
- PlayerImmovable(g_portdock_descr),
- m_fleet(nullptr),
- m_warehouse(wh),
- m_need_ship(false),
- m_expedition_ready(false)
-{
+PortDock::PortDock(Warehouse* wh)
+ : PlayerImmovable(g_portdock_descr),
+ m_fleet(nullptr),
+ m_warehouse(wh),
+ m_need_ship(false),
+ m_expedition_ready(false) {
}
PortDock::~PortDock() {
@@ -76,8 +72,7 @@
*
* @note This only works properly when called before @ref init
*/
-void PortDock::add_position(Coords where)
-{
+void PortDock::add_position(Coords where) {
m_dockpoints.push_back(where);
}
@@ -90,29 +85,23 @@
*
* @warning This should only be called via @ref Fleet itself.
*/
-void PortDock::set_fleet(Fleet * fleet)
-{
+void PortDock::set_fleet(Fleet* fleet) {
m_fleet = fleet;
}
-int32_t PortDock::get_size() const
-{
+int32_t PortDock::get_size() const {
return SMALL;
}
-bool PortDock::get_passable() const
-{
+bool PortDock::get_passable() const {
return true;
}
-PortDock::PositionList PortDock::get_positions
- (const EditorGameBase &) const
-{
+PortDock::PositionList PortDock::get_positions(const EditorGameBase&) const {
return m_dockpoints;
}
-Flag & PortDock::base_flag()
-{
+Flag& PortDock::base_flag() {
return m_warehouse->base_flag();
}
@@ -120,8 +109,7 @@
* Return the dock that has the given flag as its base, or 0 if no dock of our fleet
* has the given flag.
*/
-PortDock * PortDock::get_dock(Flag & flag) const
-{
+PortDock* PortDock::get_dock(Flag& flag) const {
if (m_fleet)
return m_fleet->get_dock(flag);
return nullptr;
@@ -133,8 +121,7 @@
* Called by @ref Warehouse::set_economy, and responsible for forwarding the
* change to @ref Fleet.
*/
-void PortDock::set_economy(Economy * e)
-{
+void PortDock::set_economy(Economy* e) {
if (e == get_economy())
return;
@@ -152,18 +139,14 @@
m_expedition_bootstrap->set_economy(e);
}
-
-void PortDock::draw
- (const EditorGameBase &, RenderTarget &, const FCoords&, const Point&)
-{
+void PortDock::draw(const EditorGameBase&, RenderTarget&, const FCoords&, const Point&) {
// do nothing
}
-void PortDock::init(EditorGameBase & egbase)
-{
+void PortDock::init(EditorGameBase& egbase) {
PlayerImmovable::init(egbase);
- for (const Coords& coords: m_dockpoints) {
+ for (const Coords& coords : m_dockpoints) {
set_position(egbase, coords);
}
@@ -174,16 +157,14 @@
* Create our initial singleton @ref Fleet. The fleet code ensures
* that we merge with a larger fleet when possible.
*/
-void PortDock::init_fleet(EditorGameBase & egbase)
-{
- Fleet * fleet = new Fleet(owner());
+void PortDock::init_fleet(EditorGameBase& egbase) {
+ Fleet* fleet = new Fleet(owner());
fleet->add_port(egbase, this);
fleet->init(egbase);
// Note: the Fleet calls our set_fleet automatically
}
-void PortDock::cleanup(EditorGameBase & egbase)
-{
+void PortDock::cleanup(EditorGameBase& egbase) {
if (egbase.objects().object_still_available(m_warehouse)) {
// Transfer all our wares into the warehouse.
if (upcast(Game, game, &egbase)) {
@@ -212,7 +193,7 @@
if (m_fleet)
m_fleet->remove_port(egbase, this);
- for (const Coords& coords: m_dockpoints) {
+ for (const Coords& coords : m_dockpoints) {
unset_position(egbase, coords);
}
@@ -227,8 +208,7 @@
/**
* Add the flags of all ports that can be reached via this dock.
*/
-void PortDock::add_neighbours(std::vector<RoutingNodeNeighbour> & neighbours)
-{
+void PortDock::add_neighbours(std::vector<RoutingNodeNeighbour>& neighbours) {
if (m_fleet && m_fleet->active())
m_fleet->add_neighbours(*this, neighbours);
}
@@ -236,8 +216,7 @@
/**
* The given @p ware enters the dock, waiting to be transported away.
*/
-void PortDock::add_shippingitem(Game & game, WareInstance & ware)
-{
+void PortDock::add_shippingitem(Game& game, WareInstance& ware) {
m_waiting.push_back(ShippingItem(ware));
ware.set_location(game, this);
ware.update(game);
@@ -247,15 +226,14 @@
* The given @p ware, which is assumed to be inside the dock, has updated
* its route.
*/
-void PortDock::update_shippingitem(Game & game, WareInstance & ware)
-{
+void PortDock::update_shippingitem(Game& game, WareInstance& ware) {
for (std::vector<ShippingItem>::iterator item_iter = m_waiting.begin();
- item_iter != m_waiting.end();
- ++item_iter) {
+ item_iter != m_waiting.end();
+ ++item_iter) {
if (item_iter->m_object.serial() == ware.serial()) {
_update_shippingitem(game, item_iter);
- return;
+ return;
}
}
}
@@ -263,8 +241,7 @@
/**
* The given @p worker enters the dock, waiting to be transported away.
*/
-void PortDock::add_shippingitem(Game & game, Worker & worker)
-{
+void PortDock::add_shippingitem(Game& game, Worker& worker) {
m_waiting.push_back(ShippingItem(worker));
worker.set_location(this);
update_shippingitem(game, worker);
@@ -274,24 +251,22 @@
* The given @p worker, which is assumed to be inside the dock, has
* updated its route.
*/
-void PortDock::update_shippingitem(Game & game, Worker & worker)
-{
+void PortDock::update_shippingitem(Game& game, Worker& worker) {
for (std::vector<ShippingItem>::iterator item_iter = m_waiting.begin();
- item_iter != m_waiting.end();
- ++item_iter) {
+ item_iter != m_waiting.end();
+ ++item_iter) {
if (item_iter->m_object.serial() == worker.serial()) {
_update_shippingitem(game, item_iter);
- return;
+ return;
}
}
}
-void PortDock::_update_shippingitem(Game & game, std::vector<ShippingItem>::iterator it)
-{
+void PortDock::_update_shippingitem(Game& game, std::vector<ShippingItem>::iterator it) {
it->update_destination(game, *this);
- PortDock * dst = it->get_destination(game);
+ PortDock* dst = it->get_destination(game);
assert(dst != this);
// Destination might have vanished or be in another economy altogether.
@@ -312,8 +287,7 @@
* A ship has arrived at the dock. Clear all items designated for this dock,
* and load the ship.
*/
-void PortDock::ship_arrived(Game & game, Ship & ship)
-{
+void PortDock::ship_arrived(Game& game, Ship& ship) {
std::vector<ShippingItem> items_brought_by_ship;
ship.withdraw_items(game, *this, items_brought_by_ship);
@@ -330,7 +304,8 @@
// Load the ship
std::vector<Worker*> workers;
std::vector<WareInstance*> wares;
- m_expedition_bootstrap->get_waiting_workers_and_wares(game, owner().tribe(), &workers, &wares);
+ m_expedition_bootstrap->get_waiting_workers_and_wares(
+ game, owner().tribe(), &workers, &wares);
for (Worker* worker : workers) {
ship.add_item(game, ShippingItem(*worker));
@@ -375,8 +350,7 @@
m_fleet->update(game);
}
-void PortDock::set_need_ship(Game & game, bool need)
-{
+void PortDock::set_need_ship(Game& game, bool need) {
molog("set_need_ship(%s)\n", need ? "true" : "false");
if (need == m_need_ship)
@@ -393,13 +367,12 @@
/**
* Return the number of wares or workers of the given type that are waiting at the dock.
*/
-uint32_t PortDock::count_waiting(WareWorker waretype, WareIndex wareindex)
-{
+uint32_t PortDock::count_waiting(WareWorker waretype, WareIndex wareindex) {
uint32_t count = 0;
for (ShippingItem& shipping_item : m_waiting) {
- WareInstance * ware;
- Worker * worker;
+ WareInstance* ware;
+ Worker* worker;
shipping_item.get(owner().egbase(), &ware, &worker);
if (waretype == wwWORKER) {
@@ -414,7 +387,6 @@
return count;
}
-
/// \returns whether an expedition was started or is even ready
bool PortDock::expedition_started() {
return (m_expedition_bootstrap.get() != nullptr) || m_expedition_ready;
@@ -425,19 +397,18 @@
assert(!m_expedition_bootstrap);
m_expedition_bootstrap.reset(new ExpeditionBootstrap(this));
m_expedition_bootstrap->start();
-
}
ExpeditionBootstrap* PortDock::expedition_bootstrap() {
return m_expedition_bootstrap.get();
}
-void PortDock::expedition_bootstrap_complete(Game & game) {
+void PortDock::expedition_bootstrap_complete(Game& game) {
m_expedition_ready = true;
get_fleet()->update(game);
}
-void PortDock::cancel_expedition(Game & game) {
+void PortDock::cancel_expedition(Game& game) {
// Reset
m_expedition_ready = false;
@@ -445,38 +416,34 @@
m_expedition_bootstrap.reset(nullptr);
}
-
-void PortDock::log_general_info(const EditorGameBase & egbase)
-{
+void PortDock::log_general_info(const EditorGameBase& egbase) {
PlayerImmovable::log_general_info(egbase);
Coords pos(m_warehouse->get_position());
- molog
- ("PortDock for warehouse %u (at %i,%i) in fleet %u, need_ship: %s, waiting: %" PRIuS "\n",
- m_warehouse ? m_warehouse->serial() : 0, pos.x, pos.y,
- m_fleet ? m_fleet->serial() : 0,
- m_need_ship ? "true" : "false",
- m_waiting.size());
+ molog("PortDock for warehouse %u (at %i,%i) in fleet %u, need_ship: %s, waiting: %" PRIuS "\n",
+ m_warehouse ? m_warehouse->serial() : 0,
+ pos.x,
+ pos.y,
+ m_fleet ? m_fleet->serial() : 0,
+ m_need_ship ? "true" : "false",
+ m_waiting.size());
for (ShippingItem& shipping_item : m_waiting) {
- molog
- (" IT %u, destination %u\n",
- shipping_item.m_object.serial(),
- shipping_item.m_destination_dock.serial());
+ molog(" IT %u, destination %u\n",
+ shipping_item.m_object.serial(),
+ shipping_item.m_destination_dock.serial());
}
}
#define PORTDOCK_SAVEGAME_VERSION 3
-PortDock::Loader::Loader() : m_warehouse(0)
-{
+PortDock::Loader::Loader() : m_warehouse(0) {
}
-void PortDock::Loader::load(FileRead & fr, uint8_t version)
-{
+void PortDock::Loader::load(FileRead& fr, uint8_t version) {
PlayerImmovable::Loader::load(fr);
- PortDock & pd = get<PortDock>();
+ PortDock& pd = get<PortDock>();
m_warehouse = fr.unsigned_32();
uint16_t nrdockpoints = fr.unsigned_16();
@@ -507,11 +474,10 @@
}
}
-void PortDock::Loader::load_pointers()
-{
+void PortDock::Loader::load_pointers() {
PlayerImmovable::Loader::load_pointers();
- PortDock & pd = get<PortDock>();
+ PortDock& pd = get<PortDock>();
pd.m_warehouse = &mol().get<Warehouse>(m_warehouse);
pd.m_waiting.resize(m_waiting.size());
@@ -520,11 +486,10 @@
}
}
-void PortDock::Loader::load_finish()
-{
+void PortDock::Loader::load_finish() {
PlayerImmovable::Loader::load_finish();
- PortDock & pd = get<PortDock>();
+ PortDock& pd = get<PortDock>();
if (pd.m_warehouse->get_portdock() != &pd) {
log("Inconsistent PortDock <> Warehouse link\n");
@@ -537,9 +502,7 @@
pd.init_fleet(egbase());
}
-MapObject::Loader * PortDock::load
- (EditorGameBase & egbase, MapObjectLoader & mol, FileRead & fr)
-{
+MapObject::Loader* PortDock::load(EditorGameBase& egbase, MapObjectLoader& mol, FileRead& fr) {
std::unique_ptr<Loader> loader(new Loader);
try {
@@ -551,15 +514,14 @@
loader->load(fr, version);
} else
throw GameDataError("unknown/unhandled version %u", version);
- } catch (const std::exception & e) {
+ } catch (const std::exception& e) {
throw wexception("loading portdock: %s", e.what());
}
return loader.release();
}
-void PortDock::save(EditorGameBase & egbase, MapObjectSaver & mos, FileWrite & fw)
-{
+void PortDock::save(EditorGameBase& egbase, MapObjectSaver& mos, FileWrite& fw) {
fw.unsigned_8(HeaderPortDock);
fw.unsigned_8(PORTDOCK_SAVEGAME_VERSION);
@@ -567,7 +529,7 @@
fw.unsigned_32(mos.get_object_file_index(*m_warehouse));
fw.unsigned_16(m_dockpoints.size());
- for (const Coords& coords: m_dockpoints) {
+ for (const Coords& coords : m_dockpoints) {
write_coords_32(&fw, coords);
}
@@ -583,4 +545,4 @@
fw.unsigned_8(m_expedition_ready ? 1 : 0);
}
-} // namespace Widelands
+} // namespace Widelands
=== modified file 'src/logic/ship.cc'
--- src/logic/ship.cc 2014-11-30 18:49:38 +0000
+++ src/logic/ship.cc 2014-12-11 21:38:11 +0000
@@ -49,24 +49,24 @@
namespace Widelands {
-ShipDescr::ShipDescr
- (const char * given_name, const char * gdescname,
- const std::string & directory, Profile & prof, Section & global_s,
- const TribeDescr & gtribe)
- :
- BobDescr(MapObjectType::SHIP, given_name, gdescname, >ribe)
-{
- { // global options
- Section & idle_s = prof.get_safe_section("idle");
+ShipDescr::ShipDescr(const char* given_name,
+ const char* gdescname,
+ const std::string& directory,
+ Profile& prof,
+ Section& global_s,
+ const TribeDescr& gtribe)
+ : BobDescr(MapObjectType::SHIP, given_name, gdescname, >ribe) {
+ { // global options
+ Section& idle_s = prof.get_safe_section("idle");
add_animation("idle", g_gr->animations().load(directory, idle_s));
}
m_sail_anims.parse(*this, directory, prof, "sail");
- Section * sinking_s = prof.get_section("sinking");
+ Section* sinking_s = prof.get_section("sinking");
if (sinking_s)
add_animation("sinking", g_gr->animations().load(directory, *sinking_s));
- m_capacity = global_s.get_natural("capacity", 20);
+ m_capacity = global_s.get_natural("capacity", 20);
m_vision_range = global_s.get_natural("vision_range", 7);
}
@@ -74,18 +74,12 @@
return MOVECAPS_SWIM;
}
-Bob & ShipDescr::create_object() const {
+Bob& ShipDescr::create_object() const {
return *new Ship(*this);
}
-
-Ship::Ship(const ShipDescr & gdescr) :
- Bob(gdescr),
- m_window(nullptr),
- m_fleet(nullptr),
- m_economy(nullptr),
- m_ship_state(TRANSPORT)
-{
+Ship::Ship(const ShipDescr& gdescr)
+ : Bob(gdescr), m_window(nullptr), m_fleet(nullptr), m_economy(nullptr), m_ship_state(TRANSPORT) {
}
Ship::~Ship() {
@@ -104,11 +98,11 @@
return m_fleet;
}
-void Ship::init_auto_task(Game & game) {
+void Ship::init_auto_task(Game& game) {
start_task_ship(game);
}
-void Ship::init(EditorGameBase & egbase) {
+void Ship::init(EditorGameBase& egbase) {
Bob::init(egbase);
init_fleet(egbase);
}
@@ -118,15 +112,15 @@
* The fleet code will automatically merge us into a larger
* fleet, if one is reachable.
*/
-void Ship::init_fleet(EditorGameBase & egbase) {
+void Ship::init_fleet(EditorGameBase& egbase) {
assert(get_owner() != nullptr);
- Fleet * fleet = new Fleet(*get_owner());
+ Fleet* fleet = new Fleet(*get_owner());
fleet->add_ship(this);
fleet->init(egbase);
// fleet calls the set_fleet function appropriately
}
-void Ship::cleanup(EditorGameBase & egbase) {
+void Ship::cleanup(EditorGameBase& egbase) {
if (m_fleet) {
m_fleet->remove_ship(egbase, this);
}
@@ -142,52 +136,48 @@
/**
* This function is to be called only by @ref Fleet.
*/
-void Ship::set_fleet(Fleet * fleet) {
+void Ship::set_fleet(Fleet* fleet) {
m_fleet = fleet;
}
-void Ship::wakeup_neighbours(Game & game) {
+void Ship::wakeup_neighbours(Game& game) {
FCoords position = get_position();
Area<FCoords> area(position, 1);
- std::vector<Bob *> ships;
+ std::vector<Bob*> ships;
game.map().find_bobs(area, &ships, FindBobShip());
- for
- (std::vector<Bob *>::const_iterator it = ships.begin();
- it != ships.end(); ++it)
- {
+ for (std::vector<Bob*>::const_iterator it = ships.begin(); it != ships.end(); ++it) {
if (*it == this)
continue;
- static_cast<Ship *>(*it)->ship_wakeup(game);
+ static_cast<Ship*>(*it)->ship_wakeup(game);
}
}
-
/**
* Standard behaviour of ships.
*
* ivar1 = helper flag for coordination of mutual evasion of ships
*/
const Bob::Task Ship::taskShip = {
- "ship",
- static_cast<Bob::Ptr>(&Ship::ship_update),
- nullptr,
- nullptr,
- true // unique task
+ "ship",
+ static_cast<Bob::Ptr>(&Ship::ship_update),
+ nullptr,
+ nullptr,
+ true // unique task
};
-void Ship::start_task_ship(Game & game) {
+void Ship::start_task_ship(Game& game) {
push_task(game, taskShip);
top_state().ivar1 = 0;
}
-void Ship::ship_wakeup(Game & game) {
+void Ship::ship_wakeup(Game& game) {
if (get_state(taskShip))
send_signal(game, "wakeup");
}
-void Ship::ship_update(Game & game, Bob::State & state) {
+void Ship::ship_update(Game& game, Bob::State& state) {
// Handle signals
std::string signal = get_signal();
if (!signal.empty()) {
@@ -211,44 +201,43 @@
}
switch (m_ship_state) {
- case TRANSPORT:
- if (ship_update_transport(game, state))
- return;
- break;
- case EXP_FOUNDPORTSPACE:
- case EXP_SCOUTING:
- case EXP_WAITING:
- ship_update_expedition(game, state);
- break;
- case EXP_COLONIZING:
- break;
- case SINK_REQUEST:
- if (descr().is_animation_known("sinking")) {
- m_ship_state = SINK_ANIMATION;
- start_task_idle(game, descr().get_animation("sinking"), 3000);
- return;
- }
- log("Oh no... this ship has no sinking animation :(!\n");
- // fall trough
- case SINK_ANIMATION:
- // The sink animation has been played, so finally remove the ship from the map
- pop_task(game);
- remove(game);
- return;
- default:
- assert(false); // never here
+ case TRANSPORT:
+ if (ship_update_transport(game, state))
+ return;
+ break;
+ case EXP_FOUNDPORTSPACE:
+ case EXP_SCOUTING:
+ case EXP_WAITING:
+ ship_update_expedition(game, state);
+ break;
+ case EXP_COLONIZING:
+ break;
+ case SINK_REQUEST:
+ if (descr().is_animation_known("sinking")) {
+ m_ship_state = SINK_ANIMATION;
+ start_task_idle(game, descr().get_animation("sinking"), 3000);
+ return;
+ }
+ log("Oh no... this ship has no sinking animation :(!\n");
+ // fall trough
+ case SINK_ANIMATION:
+ // The sink animation has been played, so finally remove the ship from the map
+ pop_task(game);
+ remove(game);
+ return;
+ default:
+ assert(false); // never here
}
// if the real update function failed (e.g. nothing to transport), the ship goes idle
ship_update_idle(game, state);
}
-
/// updates a ships tasks in transport mode \returns false if failed to update tasks
-bool Ship::ship_update_transport(Game & game, Bob::State &) {
- Map & map = game.map();
+bool Ship::ship_update_transport(Game& game, Bob::State&) {
+ Map& map = game.map();
- PortDock * dst = get_destination(game);
+ PortDock* dst = get_destination(game);
if (!dst) {
molog("ship_update: No destination anymore.\n");
if (m_items.empty())
@@ -277,7 +266,7 @@
molog("ship_update: Go to dock %u\n", dst->serial());
- PortDock * lastdock = m_lastdock.get(game);
+ PortDock* lastdock = m_lastdock.get(game);
if (lastdock && lastdock != dst) {
molog("ship_update: Have lastdock %u\n", lastdock->serial());
@@ -332,10 +321,9 @@
return true;
}
-
/// updates a ships tasks in expedition mode
-void Ship::ship_update_expedition(Game & game, Bob::State &) {
- Map & map = game.map();
+void Ship::ship_update_expedition(Game& game, Bob::State&) {
+ Map& map = game.map();
assert(m_expedition);
@@ -343,30 +331,30 @@
FCoords position = get_position();
for (Direction dir = FIRST_DIRECTION; dir <= LAST_DIRECTION; ++dir) {
m_expedition->swimable[dir - 1] =
- map.get_neighbour(position, dir).field->nodecaps() & MOVECAPS_SWIM;
+ map.get_neighbour(position, dir).field->nodecaps() & MOVECAPS_SWIM;
}
if (m_ship_state == EXP_SCOUTING) {
// Check surrounding fields for port buildspaces
- std::unique_ptr<std::list<Coords> > temp_port_buildspaces(new std::list<Coords>());
- MapRegion<Area<Coords> > mr(map, Area<Coords>(position, descr().vision_range()));
+ std::unique_ptr<std::list<Coords>> temp_port_buildspaces(new std::list<Coords>());
+ MapRegion<Area<Coords>> mr(map, Area<Coords>(position, descr().vision_range()));
bool new_port_space = false;
do {
if (map.is_port_space(mr.location())) {
FCoords fc = map.get_fcoords(mr.location());
- // Check whether the maximum theoretical possible NodeCap of the field is of the size big
+ // Check whether the maximum theoretical possible NodeCap of the field is of the size
+ // big
// and whether it can theoretically be a port space
- if
- ((map.get_max_nodecaps(game.world(), fc) & BUILDCAPS_SIZEMASK) != BUILDCAPS_BIG
- ||
- map.find_portdock(fc).empty())
- {
+ if ((map.get_max_nodecaps(game.world(), fc) & BUILDCAPS_SIZEMASK) != BUILDCAPS_BIG ||
+ map.find_portdock(fc).empty()) {
continue;
}
- // NOTE This is the place to handle enemy territory and "clearing a port space from the enemy".
- // NOTE There is a simple check for the current land owner to avoid placement of ports into enemy
+ // NOTE This is the place to handle enemy territory and "clearing a port space from the
+ // enemy".
+ // NOTE There is a simple check for the current land owner to avoid placement of ports
+ // into enemy
// NOTE territory, as "clearing" is not yet implemented.
// NOTE further it checks, whether there is a Player_immovable on one of the fields.
// TODO(unknown): handle this more gracefully concering opposing players
@@ -378,7 +366,7 @@
invalid = true;
continue;
}
- BaseImmovable * baim = coord.field->get_immovable();
+ BaseImmovable* baim = coord.field->get_immovable();
if (baim)
if (is_a(PlayerImmovable, baim)) {
invalid = true;
@@ -387,60 +375,60 @@
// Check all neighboured fields that will be used by the port
switch (step) {
- case 0:
- map.get_ln(fc, &coord);
- break;
- case 1:
- map.get_tln(fc, &coord);
- break;
- case 2:
- map.get_trn(fc, &coord);
- break;
- case 3:
- // Flag coordinate
- map.get_brn(fc, &coord);
- break;
- default:
- break;
+ case 0:
+ map.get_ln(fc, &coord);
+ break;
+ case 1:
+ map.get_tln(fc, &coord);
+ break;
+ case 2:
+ map.get_trn(fc, &coord);
+ break;
+ case 3:
+ // Flag coordinate
+ map.get_brn(fc, &coord);
+ break;
+ default:
+ break;
}
}
// Now check whether there is a flag in the surroundings of the flag position
FCoords neighb;
map.get_ln(coord, &neighb);
for (uint8_t step = 0; !invalid && step < 5; ++step) {
- BaseImmovable * baim = neighb.field->get_immovable();
+ BaseImmovable* baim = neighb.field->get_immovable();
if (baim)
if (is_a(Flag, baim)) {
invalid = true;
continue;
}
- // Check all neighboured fields but not the one already checked for a PlayerImmovable.
+ // Check all neighboured fields but not the one already checked for a
+ // PlayerImmovable.
switch (step) {
- case 0:
- map.get_bln(coord, &neighb);
- break;
- case 1:
- map.get_brn(coord, &neighb);
- break;
- case 2:
- map.get_rn(coord, &neighb);
- break;
- case 3:
- map.get_trn(coord, &neighb);
- break;
- default:
- break;
+ case 0:
+ map.get_bln(coord, &neighb);
+ break;
+ case 1:
+ map.get_brn(coord, &neighb);
+ break;
+ case 2:
+ map.get_rn(coord, &neighb);
+ break;
+ case 3:
+ map.get_trn(coord, &neighb);
+ break;
+ default:
+ break;
}
}
if (invalid)
continue;
bool pbs_saved = false;
- for
- (std::list<Coords>::const_iterator it = m_expedition->seen_port_buildspaces->begin();
- it != m_expedition->seen_port_buildspaces->end() && !pbs_saved;
- ++it)
- {
+ for (std::list<Coords>::const_iterator it =
+ m_expedition->seen_port_buildspaces->begin();
+ it != m_expedition->seen_port_buildspaces->end() && !pbs_saved;
+ ++it) {
// Check if the ship knows this port space already from its last check
if (*it == mr.location()) {
temp_port_buildspaces->push_back(mr.location());
@@ -465,7 +453,7 @@
}
}
-void Ship::ship_update_idle(Game & game, Bob::State & state) {
+void Ship::ship_update_idle(Game& game, Bob::State& state) {
if (state.ivar1) {
// We've just completed one step, so give neighbours
// a chance to move away first
@@ -475,214 +463,221 @@
return;
}
- // If we are waiting for the next transport job, check if we should move away from ships and shores
+ // If we are waiting for the next transport job, check if we should move away from ships and
+ // shores
switch (m_ship_state) {
- case TRANSPORT: {
- FCoords position = get_position();
- Map & map = game.map();
- unsigned int dirs[LAST_DIRECTION + 1];
- unsigned int dirmax = 0;
-
+ case TRANSPORT: {
+ FCoords position = get_position();
+ Map& map = game.map();
+ unsigned int dirs[LAST_DIRECTION + 1];
+ unsigned int dirmax = 0;
+
+ for (Direction dir = 0; dir <= LAST_DIRECTION; ++dir) {
+ FCoords node = dir ? map.get_neighbour(position, dir) : position;
+ dirs[dir] = node.field->nodecaps() & MOVECAPS_WALK ? 10 : 0;
+
+ Area<FCoords> area(node, 0);
+ std::vector<Bob*> ships;
+ map.find_bobs(area, &ships, FindBobShip());
+
+ for (std::vector<Bob*>::const_iterator it = ships.begin(); it != ships.end(); ++it) {
+ if (*it == this)
+ continue;
+
+ dirs[dir] += 3;
+ }
+
+ dirmax = std::max(dirmax, dirs[dir]);
+ }
+
+ if (dirmax) {
+ unsigned int prob[LAST_DIRECTION + 1];
+ unsigned int totalprob = 0;
+
+ // The probability for moving into a given direction is also
+ // affected by the "close" directions.
for (Direction dir = 0; dir <= LAST_DIRECTION; ++dir) {
- FCoords node = dir ? map.get_neighbour(position, dir) : position;
- dirs[dir] = node.field->nodecaps() & MOVECAPS_WALK ? 10 : 0;
-
- Area<FCoords> area(node, 0);
- std::vector<Bob *> ships;
- map.find_bobs(area, &ships, FindBobShip());
-
- for (std::vector<Bob *>::const_iterator it = ships.begin(); it != ships.end(); ++it) {
- if (*it == this)
- continue;
-
- dirs[dir] += 3;
- }
-
- dirmax = std::max(dirmax, dirs[dir]);
- }
-
- if (dirmax) {
- unsigned int prob[LAST_DIRECTION + 1];
- unsigned int totalprob = 0;
-
- // The probability for moving into a given direction is also
- // affected by the "close" directions.
- for (Direction dir = 0; dir <= LAST_DIRECTION; ++dir) {
- prob[dir] = 10 * dirmax - 10 * dirs[dir];
-
- if (dir > 0) {
- unsigned int delta = std::min(prob[dir], dirs[(dir % 6) + 1] + dirs[1 + ((dir - 1) % 6)]);
- prob[dir] -= delta;
- }
-
- totalprob += prob[dir];
- }
-
- if (totalprob == 0) {
- start_task_idle(game, descr().main_animation(), 1500);
- return;
- }
-
- unsigned int rnd = game.logic_rand() % totalprob;
- Direction dir = 0;
- while (rnd >= prob[dir]) {
- rnd -= prob[dir];
- ++dir;
- }
-
- if (dir == 0 || dir > LAST_DIRECTION) {
- start_task_idle(game, descr().main_animation(), 1500);
- return;
- }
-
- FCoords neighbour = map.get_neighbour(position, dir);
- if (!(neighbour.field->nodecaps() & MOVECAPS_SWIM)) {
- start_task_idle(game, descr().main_animation(), 1500);
- return;
- }
-
- state.ivar1 = 1;
- start_task_move(game, dir, descr().get_sail_anims(), false);
- return;
- }
- // No desire to move around, so sleep
- start_task_idle(game, descr().main_animation(), -1);
+ prob[dir] = 10 * dirmax - 10 * dirs[dir];
+
+ if (dir > 0) {
+ unsigned int delta =
+ std::min(prob[dir], dirs[(dir % 6) + 1] + dirs[1 + ((dir - 1) % 6)]);
+ prob[dir] -= delta;
+ }
+
+ totalprob += prob[dir];
+ }
+
+ if (totalprob == 0) {
+ start_task_idle(game, descr().main_animation(), 1500);
+ return;
+ }
+
+ unsigned int rnd = game.logic_rand() % totalprob;
+ Direction dir = 0;
+ while (rnd >= prob[dir]) {
+ rnd -= prob[dir];
+ ++dir;
+ }
+
+ if (dir == 0 || dir > LAST_DIRECTION) {
+ start_task_idle(game, descr().main_animation(), 1500);
+ return;
+ }
+
+ FCoords neighbour = map.get_neighbour(position, dir);
+ if (!(neighbour.field->nodecaps() & MOVECAPS_SWIM)) {
+ start_task_idle(game, descr().main_animation(), 1500);
+ return;
+ }
+
+ state.ivar1 = 1;
+ start_task_move(game, dir, descr().get_sail_anims(), false);
return;
}
- case EXP_SCOUTING: {
- if (m_expedition->island_exploration) { // Exploration of the island
- if (exp_close_to_coast()) {
- if (m_expedition->direction == 0) {
- // Make sure we know the location of the coast and use it as initial direction we come from
- m_expedition->direction = WALK_SE;
- for (uint8_t secure = 0; exp_dir_swimable(m_expedition->direction); ++secure) {
- assert(secure < 6);
- m_expedition->direction = get_cw_neighbour(m_expedition->direction);
- }
- m_expedition->direction = get_backward_dir(m_expedition->direction);
- // Save the position - this is where we start
- m_expedition->exploration_start = get_position();
- } else {
- // Check whether the island was completely surrounded
- if (get_position() == m_expedition->exploration_start) {
- std::string msg_head = _("Island Circumnavigated");
- std::string msg_body = _("An expedition ship sailed around its"
- " island without any events.");
- send_message(game, "exp_island", msg_head, msg_body,
- "ship_explore_island_cw.png");
- m_ship_state = EXP_WAITING;
- return start_task_idle(game, descr().main_animation(), 1500);
- }
+ // No desire to move around, so sleep
+ start_task_idle(game, descr().main_animation(), -1);
+ return;
+ }
+ case EXP_SCOUTING: {
+ if (m_expedition->island_exploration) { // Exploration of the island
+ if (exp_close_to_coast()) {
+ if (m_expedition->direction == 0) {
+ // Make sure we know the location of the coast and use it as initial direction we
+ // come from
+ m_expedition->direction = WALK_SE;
+ for (uint8_t secure = 0; exp_dir_swimable(m_expedition->direction); ++secure) {
+ assert(secure < 6);
+ m_expedition->direction = get_cw_neighbour(m_expedition->direction);
}
- // The ship is supposed to follow the coast as close as possible, therefore the check for
- // a swimable field begins at the neighbour field of the direction we came from.
m_expedition->direction = get_backward_dir(m_expedition->direction);
- if (m_expedition->clockwise) {
- do {
- m_expedition->direction = get_ccw_neighbour(m_expedition->direction);
- } while (!exp_dir_swimable(m_expedition->direction));
- } else {
- do {
- m_expedition->direction = get_cw_neighbour(m_expedition->direction);
- } while (!exp_dir_swimable(m_expedition->direction));
- }
- state.ivar1 = 1;
- return start_task_move(game, m_expedition->direction, descr().get_sail_anims(), false);
- } else {
- // The ship got the command to scout around an island, but is not close to any island
- // Most likely the command was send as the ship was on an exploration and just leaving
- // the island - therefore we try to find the island again.
- FCoords position = get_position();
- Map & map = game.map();
- for (uint8_t dir = FIRST_DIRECTION; dir <= LAST_DIRECTION; ++dir) {
- FCoords neighbour = map.get_neighbour(position, dir);
- for (uint8_t sur = FIRST_DIRECTION; sur <= LAST_DIRECTION; ++sur)
- if (!(map.get_neighbour(neighbour, sur).field->nodecaps() & MOVECAPS_SWIM)) {
- // Okay we found the next coast, so now the ship should go there.
- // However, we do neither save the position as starting position, nor do we save
- // the direction we currently go. So the ship can start exploring normally
- state.ivar1 = 1;
- return start_task_move(game, dir, descr().get_sail_anims(), false);
- }
- }
- // if we are here, it seems something really strange happend.
- log("WARNING: ship was not able to start exploration. Entering WAIT mode.");
- m_ship_state = EXP_WAITING;
- return start_task_idle(game, descr().main_animation(), 1500);
- }
- } else { // scouting towards a specific direction
- if (exp_dir_swimable(m_expedition->direction)) {
- // the scouting direction is still free to move
- state.ivar1 = 1;
- start_task_move(game, m_expedition->direction, descr().get_sail_anims(), false);
- return;
- }
- // coast reached
+ // Save the position - this is where we start
+ m_expedition->exploration_start = get_position();
+ } else {
+ // Check whether the island was completely surrounded
+ if (get_position() == m_expedition->exploration_start) {
+ std::string msg_head = _("Island Circumnavigated");
+ std::string msg_body = _("An expedition ship sailed around its"
+ " island without any events.");
+ send_message(
+ game, "exp_island", msg_head, msg_body, "ship_explore_island_cw.png");
+ m_ship_state = EXP_WAITING;
+ return start_task_idle(game, descr().main_animation(), 1500);
+ }
+ }
+ // The ship is supposed to follow the coast as close as possible, therefore the check
+ // for
+ // a swimable field begins at the neighbour field of the direction we came from.
+ m_expedition->direction = get_backward_dir(m_expedition->direction);
+ if (m_expedition->clockwise) {
+ do {
+ m_expedition->direction = get_ccw_neighbour(m_expedition->direction);
+ } while (!exp_dir_swimable(m_expedition->direction));
+ } else {
+ do {
+ m_expedition->direction = get_cw_neighbour(m_expedition->direction);
+ } while (!exp_dir_swimable(m_expedition->direction));
+ }
+ state.ivar1 = 1;
+ return start_task_move(game, m_expedition->direction, descr().get_sail_anims(), false);
+ } else {
+ // The ship got the command to scout around an island, but is not close to any island
+ // Most likely the command was send as the ship was on an exploration and just leaving
+ // the island - therefore we try to find the island again.
+ FCoords position = get_position();
+ Map& map = game.map();
+ for (uint8_t dir = FIRST_DIRECTION; dir <= LAST_DIRECTION; ++dir) {
+ FCoords neighbour = map.get_neighbour(position, dir);
+ for (uint8_t sur = FIRST_DIRECTION; sur <= LAST_DIRECTION; ++sur)
+ if (!(map.get_neighbour(neighbour, sur).field->nodecaps() & MOVECAPS_SWIM)) {
+ // Okay we found the next coast, so now the ship should go there.
+ // However, we do neither save the position as starting position, nor do we
+ // save
+ // the direction we currently go. So the ship can start exploring normally
+ state.ivar1 = 1;
+ return start_task_move(game, dir, descr().get_sail_anims(), false);
+ }
+ }
+ // if we are here, it seems something really strange happend.
+ log("WARNING: ship was not able to start exploration. Entering WAIT mode.");
m_ship_state = EXP_WAITING;
- start_task_idle(game, descr().main_animation(), 1500);
- // Send a message to the player, that a new coast was reached
- std::string msg_head = _("Coast Reached");
- std::string msg_body =
- _("An expedition ship reached a coast and is waiting for further commands.");
- send_message(game, "exp_coast", msg_head, msg_body, "ship_explore_island_cw.png");
+ return start_task_idle(game, descr().main_animation(), 1500);
+ }
+ } else { // scouting towards a specific direction
+ if (exp_dir_swimable(m_expedition->direction)) {
+ // the scouting direction is still free to move
+ state.ivar1 = 1;
+ start_task_move(game, m_expedition->direction, descr().get_sail_anims(), false);
return;
}
- }
- case EXP_COLONIZING: {
- assert(m_expedition->seen_port_buildspaces && !m_expedition->seen_port_buildspaces->empty());
- BaseImmovable * baim = game.map()[m_expedition->seen_port_buildspaces->front()].get_immovable();
- assert(baim);
- upcast(ConstructionSite, cs, baim);
-
- for (int i = m_items.size() - 1; i >= 0; --i) {
- WareInstance * ware;
- Worker * worker;
- m_items.at(i).get(game, &ware, &worker);
- if (ware) {
- // no, we don't transfer the wares, we create new ones out of air and remove the old ones ;)
- WaresQueue & wq = cs->waresqueue(ware->descr_index());
- const uint32_t max = wq.get_max_fill();
- const uint32_t cur = wq.get_filled();
- assert(max > cur);
- wq.set_filled(cur + 1);
- m_items.at(i).remove(game);
- m_items.resize(i);
- break;
- } else {
- assert(worker);
- worker->set_economy(nullptr);
- worker->set_location(cs);
- worker->set_position(game, cs->get_position());
- worker->reset_tasks(game);
- PartiallyFinishedBuilding::request_builder_callback
- (game, *cs->get_builder_request(), worker->descr().worker_index(), worker, *cs);
- m_items.resize(i);
- }
- }
- if (m_items.empty()) {
- m_ship_state = TRANSPORT; // That's it, expedition finished
-
- init_fleet(game);
- m_expedition.reset(nullptr);
-
- if (upcast(InteractiveGameBase, igb, game.get_ibase()))
- refresh_window(*igb);
- }
- return start_task_idle(game, descr().main_animation(), 1500); // unload the next item
- }
-
- default: {
- // wait for input
+ // coast reached
+ m_ship_state = EXP_WAITING;
start_task_idle(game, descr().main_animation(), 1500);
+ // Send a message to the player, that a new coast was reached
+ std::string msg_head = _("Coast Reached");
+ std::string msg_body =
+ _("An expedition ship reached a coast and is waiting for further commands.");
+ send_message(game, "exp_coast", msg_head, msg_body, "ship_explore_island_cw.png");
return;
}
}
+ case EXP_COLONIZING: {
+ assert(m_expedition->seen_port_buildspaces && !m_expedition->seen_port_buildspaces->empty());
+ BaseImmovable* baim =
+ game.map()[m_expedition->seen_port_buildspaces->front()].get_immovable();
+ assert(baim);
+ upcast(ConstructionSite, cs, baim);
+
+ for (int i = m_items.size() - 1; i >= 0; --i) {
+ WareInstance* ware;
+ Worker* worker;
+ m_items.at(i).get(game, &ware, &worker);
+ if (ware) {
+ // no, we don't transfer the wares, we create new ones out of air and remove the old
+ // ones ;)
+ WaresQueue& wq = cs->waresqueue(ware->descr_index());
+ const uint32_t max = wq.get_max_fill();
+ const uint32_t cur = wq.get_filled();
+ assert(max > cur);
+ wq.set_filled(cur + 1);
+ m_items.at(i).remove(game);
+ m_items.resize(i);
+ break;
+ } else {
+ assert(worker);
+ worker->set_economy(nullptr);
+ worker->set_location(cs);
+ worker->set_position(game, cs->get_position());
+ worker->reset_tasks(game);
+ PartiallyFinishedBuilding::request_builder_callback(
+ game, *cs->get_builder_request(), worker->descr().worker_index(), worker, *cs);
+ m_items.resize(i);
+ }
+ }
+ if (m_items.empty()) {
+ m_ship_state = TRANSPORT; // That's it, expedition finished
+
+ init_fleet(game);
+ m_expedition.reset(nullptr);
+
+ if (upcast(InteractiveGameBase, igb, game.get_ibase()))
+ refresh_window(*igb);
+ }
+ return start_task_idle(game, descr().main_animation(), 1500); // unload the next item
+ }
+
+ default: {
+ // wait for input
+ start_task_idle(game, descr().main_animation(), 1500);
+ return;
+ }
+ }
// never here
- assert (false);
+ assert(false);
}
-void Ship::set_economy(Game & game, Economy * e) {
+void Ship::set_economy(Game& game, Economy* e) {
// Do not check here that the economy actually changed, because on loading
// we rely that wares really get reassigned our economy.
@@ -697,23 +692,23 @@
*
* @note This is supposed to be called only from the scheduling code of @ref Fleet.
*/
-void Ship::set_destination(Game & game, PortDock & pd) {
+void Ship::set_destination(Game& game, PortDock& pd) {
molog("set_destination to %u (currently %" PRIuS " items)\n", pd.serial(), m_items.size());
m_destination = &pd;
send_signal(game, "wakeup");
}
-void Ship::add_item(Game & game, const ShippingItem & item) {
+void Ship::add_item(Game& game, const ShippingItem& item) {
assert(m_items.size() < descr().get_capacity());
m_items.push_back(item);
m_items.back().set_location(game, this);
}
-void Ship::withdraw_items(Game & game, PortDock & pd, std::vector<ShippingItem> & items) {
+void Ship::withdraw_items(Game& game, PortDock& pd, std::vector<ShippingItem>& items) {
uint32_t dst = 0;
for (uint32_t src = 0; src < m_items.size(); ++src) {
- PortDock * destination = m_items[src].get_destination(game);
+ PortDock* destination = m_items[src].get_destination(game);
if (!destination || destination == &pd) {
items.push_back(m_items[src]);
} else {
@@ -726,8 +721,8 @@
/**
* Find a path to the dock @p pd and follow it without using precomputed paths.
*/
-void Ship::start_task_movetodock(Game & game, PortDock & pd) {
- Map & map = game.map();
+void Ship::start_task_movetodock(Game& game, PortDock& pd) {
+ Map& map = game.map();
StepEvalAStar se(pd.get_warehouse()->get_position());
se.m_swim = true;
se.m_conservative = false;
@@ -753,7 +748,7 @@
}
/// Prepare everything for the coming exploration
-void Ship::start_task_expedition(Game & game) {
+void Ship::start_task_expedition(Game& game) {
// Now we are waiting
m_ship_state = EXP_WAITING;
// Initialize a new, yet empty expedition
@@ -773,8 +768,8 @@
set_economy(game, m_expedition->economy.get());
for (int i = m_items.size() - 1; i >= 0; --i) {
- WareInstance * ware;
- Worker * worker;
+ WareInstance* ware;
+ Worker* worker;
m_items.at(i).get(game, &ware, &worker);
if (worker) {
worker->reset_tasks(game);
@@ -792,7 +787,7 @@
/// Initializes / changes the direction of scouting to @arg direction
/// @note only called via player command
-void Ship::exp_scout_direction(Game &, uint8_t direction) {
+void Ship::exp_scout_direction(Game&, uint8_t direction) {
assert(m_expedition);
m_ship_state = EXP_SCOUTING;
m_expedition->direction = direction;
@@ -801,7 +796,7 @@
/// Initializes the construction of a port at @arg c
/// @note only called via player command
-void Ship::exp_construct_port (Game &, const Coords& c) {
+void Ship::exp_construct_port(Game&, const Coords& c) {
assert(m_expedition);
BuildingIndex port_idx = get_owner()->tribe().safe_building_index("port");
get_owner()->force_csite(c, port_idx);
@@ -810,7 +805,7 @@
/// Initializes / changes the direction the island exploration in @arg clockwise direction
/// @note only called via player command
-void Ship::exp_explore_island (Game &, bool clockwise) {
+void Ship::exp_explore_island(Game&, bool clockwise) {
assert(m_expedition);
m_ship_state = EXP_SCOUTING;
m_expedition->clockwise = clockwise;
@@ -820,7 +815,7 @@
/// Cancels a currently running expedition
/// @note only called via player command
-void Ship::exp_cancel (Game & game) {
+void Ship::exp_cancel(Game& game) {
// Running colonization has the highest priority before cancelation
// + cancelation only works if an expedition is actually running
if ((m_ship_state == EXP_COLONIZING) || !state_is_expedition())
@@ -834,7 +829,7 @@
// Theres nothing to be done for wares - they already changed
// economy with us and the warehouse will make sure that they are
// getting used.
- Worker * worker;
+ Worker* worker;
for (ShippingItem& item : m_items) {
item.get(game, nullptr, &worker);
if (worker) {
@@ -859,7 +854,7 @@
/// Sinks the ship
/// @note only called via player command
-void Ship::sink_ship (Game & game) {
+void Ship::sink_ship(Game& game) {
// Running colonization has the highest priority + a sink request is only valid once
if (!state_is_sinkable())
return;
@@ -869,25 +864,22 @@
close_window();
}
-void Ship::log_general_info(const EditorGameBase & egbase)
-{
+void Ship::log_general_info(const EditorGameBase& egbase) {
Bob::log_general_info(egbase);
- molog
- ("Fleet: %u, destination: %u, lastdock: %u, carrying: %" PRIuS "\n",
- m_fleet? m_fleet->serial() : 0,
- m_destination.serial(), m_lastdock.serial(),
- m_items.size());
+ molog("Fleet: %u, destination: %u, lastdock: %u, carrying: %" PRIuS "\n",
+ m_fleet ? m_fleet->serial() : 0,
+ m_destination.serial(),
+ m_lastdock.serial(),
+ m_items.size());
for (const ShippingItem& shipping_item : m_items) {
- molog
- (" IT %u, destination %u\n",
- shipping_item.m_object.serial(),
- shipping_item.m_destination_dock.serial());
+ molog(" IT %u, destination %u\n",
+ shipping_item.m_object.serial(),
+ shipping_item.m_destination_dock.serial());
}
}
-
/**
* Send a message to the owning player.
*
@@ -895,31 +887,31 @@
*
* \param msgsender a computer-readable description of why the message was sent
* \param title user-visible title of the message
- * \param description user-visible message body, will be placed in an appropriate rich-text paragraph
+ * \param description user-visible message body, will be placed in an appropriate rich-text
+ *paragraph
* \param picture picture name relative to the pics directory
*/
-void Ship::send_message
- (Game & game, const std::string & msgsender,
- const std::string & title, const std::string & description,
- const std::string & picture)
-{
+void Ship::send_message(Game& game,
+ const std::string& msgsender,
+ const std::string& title,
+ const std::string& description,
+ const std::string& picture) {
std::string rt_description;
if (picture.size() > 3) {
- rt_description = "<rt image=pics/";
+ rt_description = "<rt image=pics/";
rt_description += picture;
rt_description += "><p font-size=14 font-face=DejaVuSerif>";
} else
- rt_description = "<rt><p font-size=14 font-face=DejaVuSerif>";
+ rt_description = "<rt><p font-size=14 font-face=DejaVuSerif>";
rt_description += description;
rt_description += "</p></rt>";
- Message * msg = new Message
- (msgsender, game.get_gametime(), title, rt_description, get_position(), m_serial);
+ Message* msg =
+ new Message(msgsender, game.get_gametime(), title, rt_description, get_position(), m_serial);
get_owner()->add_message(game, *msg);
}
-
/*
==============================
@@ -930,20 +922,16 @@
#define SHIP_SAVEGAME_VERSION 4
-Ship::Loader::Loader() :
- m_lastdock(0),
- m_destination(0)
-{
+Ship::Loader::Loader() : m_lastdock(0), m_destination(0) {
}
-const Bob::Task * Ship::Loader::get_task(const std::string & name)
-{
- if (name == "shipidle" || name == "ship") return &taskShip;
+const Bob::Task* Ship::Loader::get_task(const std::string& name) {
+ if (name == "shipidle" || name == "ship")
+ return &taskShip;
return Bob::Loader::get_task(name);
}
-void Ship::Loader::load(FileRead & fr, uint8_t version)
-{
+void Ship::Loader::load(FileRead& fr, uint8_t version) {
Bob::Loader::load(fr);
if (version >= 2) {
@@ -952,15 +940,8 @@
m_ship_state = fr.unsigned_8();
// Expedition specific data
- if
- (m_ship_state == EXP_SCOUTING
- ||
- m_ship_state == EXP_WAITING
- ||
- m_ship_state == EXP_FOUNDPORTSPACE
- ||
- m_ship_state == EXP_COLONIZING)
- {
+ if (m_ship_state == EXP_SCOUTING || m_ship_state == EXP_WAITING ||
+ m_ship_state == EXP_FOUNDPORTSPACE || m_ship_state == EXP_COLONIZING) {
m_expedition.reset(new Expedition());
// Currently seen port build spaces
m_expedition->seen_port_buildspaces.reset(new std::list<Coords>());
@@ -992,11 +973,10 @@
}
}
-void Ship::Loader::load_pointers()
-{
+void Ship::Loader::load_pointers() {
Bob::Loader::load_pointers();
- Ship & ship = get<Ship>();
+ Ship& ship = get<Ship>();
if (m_lastdock)
ship.m_lastdock = &mol().get<PortDock>(m_lastdock);
@@ -1009,11 +989,10 @@
}
}
-void Ship::Loader::load_finish()
-{
+void Ship::Loader::load_finish() {
Bob::Loader::load_finish();
- Ship & ship = get<Ship>();
+ Ship& ship = get<Ship>();
// restore the state the ship is in
ship.m_ship_state = m_ship_state;
@@ -1023,7 +1002,8 @@
ship.m_expedition.swap(m_expedition);
ship.m_expedition->economy.reset(new Economy(*ship.get_owner()));
ship.m_economy = ship.m_expedition->economy.get();
- } else assert(m_ship_state == TRANSPORT);
+ } else
+ assert(m_ship_state == TRANSPORT);
// Workers load code set their economy to the economy of their location
// (which is a PlayerImmovable), that means that workers on ships do not get
@@ -1034,10 +1014,7 @@
ship.set_economy(dynamic_cast<Game&>(egbase()), ship.m_economy);
}
-
-MapObject::Loader * Ship::load
- (EditorGameBase & egbase, MapObjectLoader & mol, FileRead & fr)
-{
+MapObject::Loader* Ship::load(EditorGameBase& egbase, MapObjectLoader& mol, FileRead& fr) {
std::unique_ptr<Loader> loader(new Loader);
try {
@@ -1047,32 +1024,28 @@
if (1 <= version && version <= SHIP_SAVEGAME_VERSION) {
std::string owner = fr.c_string();
std::string name = fr.c_string();
- const ShipDescr * descr = nullptr;
+ const ShipDescr* descr = nullptr;
egbase.manually_load_tribe(owner);
- if (const TribeDescr * tribe = egbase.get_tribe(owner))
- descr = dynamic_cast<const ShipDescr *>
- (tribe->get_bob_descr(name));
+ if (const TribeDescr* tribe = egbase.get_tribe(owner))
+ descr = dynamic_cast<const ShipDescr*>(tribe->get_bob_descr(name));
if (!descr)
- throw GameDataError
- ("undefined ship %s/%s", owner.c_str(), name.c_str());
+ throw GameDataError("undefined ship %s/%s", owner.c_str(), name.c_str());
loader->init(egbase, mol, descr->create_object());
loader->load(fr, version);
} else
throw GameDataError("unknown/unhandled version %u", version);
- } catch (const std::exception & e) {
+ } catch (const std::exception& e) {
throw wexception("loading ship: %s", e.what());
}
return loader.release();
}
-void Ship::save
- (EditorGameBase & egbase, MapObjectSaver & mos, FileWrite & fw)
-{
+void Ship::save(EditorGameBase& egbase, MapObjectSaver& mos, FileWrite& fw) {
fw.unsigned_8(HeaderShip);
fw.unsigned_8(SHIP_SAVEGAME_VERSION);
@@ -1089,11 +1062,9 @@
// currently seen port buildspaces
assert(m_expedition->seen_port_buildspaces);
fw.unsigned_8(m_expedition->seen_port_buildspaces->size());
- for
- (std::list<Coords>::const_iterator it = m_expedition->seen_port_buildspaces->begin();
- it != m_expedition->seen_port_buildspaces->end();
- ++it)
- {
+ for (std::list<Coords>::const_iterator it = m_expedition->seen_port_buildspaces->begin();
+ it != m_expedition->seen_port_buildspaces->end();
+ ++it) {
write_coords_32(&fw, *it);
}
// swimability of the directions
@@ -1118,4 +1089,4 @@
}
}
-} // namespace Widelands
+} // namespace Widelands
=== modified file 'src/logic/warehouse.cc'
--- src/logic/warehouse.cc 2014-12-04 09:18:03 +0000
+++ src/logic/warehouse.cc 2014-12-11 21:38:11 +0000
@@ -50,7 +50,7 @@
namespace Widelands {
-namespace {
+namespace {
static const uint32_t WORKER_WITHOUT_COST_SPAWN_INTERVAL = 2500;
@@ -68,19 +68,17 @@
} // namespace
-WarehouseSupply::~WarehouseSupply()
-{
+WarehouseSupply::~WarehouseSupply() {
if (m_economy) {
- log
- ("WarehouseSupply::~WarehouseSupply: Warehouse %u still belongs to "
- "an economy",
- m_warehouse->serial());
+ log("WarehouseSupply::~WarehouseSupply: Warehouse %u still belongs to "
+ "an economy",
+ m_warehouse->serial());
set_economy(nullptr);
}
// We're removed from the Economy. Therefore, the wares can simply
// be cleared out. The global inventory will be okay.
- m_wares .clear();
+ m_wares.clear();
m_workers.clear();
}
@@ -96,10 +94,8 @@
m_workers.set_nrwares(i);
}
-
/// Add and remove our wares and the Supply to the economies as necessary.
-void WarehouseSupply::set_economy(Economy * const e)
-{
+void WarehouseSupply::set_economy(Economy* const e) {
if (e == m_economy)
return;
@@ -126,87 +122,74 @@
}
}
-
/// Add wares and update the economy.
-void WarehouseSupply::add_wares(WareIndex const id, uint32_t const count)
-{
+void WarehouseSupply::add_wares(WareIndex const id, uint32_t const count) {
if (!count)
return;
- if (m_economy) // No economies in the editor
+ if (m_economy) // No economies in the editor
m_economy->add_wares(id, count);
m_wares.add(id, count);
}
-
/// Remove wares and update the economy.
-void WarehouseSupply::remove_wares(WareIndex const id, uint32_t const count)
-{
+void WarehouseSupply::remove_wares(WareIndex const id, uint32_t const count) {
if (!count)
return;
m_wares.remove(id, count);
- if (m_economy) // No economies in the editor
+ if (m_economy) // No economies in the editor
m_economy->remove_wares(id, count);
}
-
/// Add workers and update the economy.
-void WarehouseSupply::add_workers(WareIndex const id, uint32_t const count)
-{
+void WarehouseSupply::add_workers(WareIndex const id, uint32_t const count) {
if (!count)
return;
- if (m_economy) // No economies in the editor
+ if (m_economy) // No economies in the editor
m_economy->add_workers(id, count);
m_workers.add(id, count);
}
-
/**
* Remove workers and update the economy.
* Comments see add_workers
*/
-void WarehouseSupply::remove_workers(WareIndex const id, uint32_t const count)
-{
+void WarehouseSupply::remove_workers(WareIndex const id, uint32_t const count) {
if (!count)
return;
m_workers.remove(id, count);
- if (m_economy) // No economies in the editor
+ if (m_economy) // No economies in the editor
m_economy->remove_workers(id, count);
}
/// Return the position of the Supply, i.e. the owning Warehouse.
-PlayerImmovable * WarehouseSupply::get_position(Game &) {return m_warehouse;}
-
+PlayerImmovable* WarehouseSupply::get_position(Game&) {
+ return m_warehouse;
+}
/// Warehouse supplies are never active.
-bool WarehouseSupply::is_active() const {return false;}
+bool WarehouseSupply::is_active() const {
+ return false;
+}
-bool WarehouseSupply::has_storage() const
-{
+bool WarehouseSupply::has_storage() const {
return true;
}
-void WarehouseSupply::get_ware_type(WareWorker & /* type */, WareIndex & /* ware */) const
-{
- throw wexception
- ("WarehouseSupply::get_ware_type: calling this is nonsensical");
+void WarehouseSupply::get_ware_type(WareWorker& /* type */, WareIndex& /* ware */) const {
+ throw wexception("WarehouseSupply::get_ware_type: calling this is nonsensical");
}
-void WarehouseSupply::send_to_storage(Game &, Warehouse * /* wh */)
-{
+void WarehouseSupply::send_to_storage(Game&, Warehouse* /* wh */) {
throw wexception("WarehouseSupply::send_to_storage: should never be called");
}
-uint32_t WarehouseSupply::nr_supplies
- (const Game & game, const Request & req) const
-{
+uint32_t WarehouseSupply::nr_supplies(const Game& game, const Request& req) const {
if (req.get_type() == wwWORKER)
- return
- m_warehouse->count_workers
- (game, req.get_index(), req.get_requirements());
+ return m_warehouse->count_workers(game, req.get_index(), req.get_requirements());
// Calculate how many wares can be sent out - it might be that we need them
// ourselves. E.g. for hiring new soldiers.
@@ -216,18 +199,16 @@
// of *this* warehouse + 1 (+1 is important, as else the ware would directly
// be taken back to the warehouse as the request of the warehouse would be
// highered and would have the same value as the original request)
- int32_t const y =
- x + (req.get_priority(0) / 100)
- - (m_warehouse->get_priority(wwWARE, req.get_index()) / 100) - 1;
+ int32_t const y = x + (req.get_priority(0) / 100) -
+ (m_warehouse->get_priority(wwWARE, req.get_index()) / 100) - 1;
// But the number should never be higher than the number of wares available
if (y > x)
return x;
return (x > 0) ? x : 0;
}
-
/// Launch a ware.
-WareInstance & WarehouseSupply::launch_ware(Game & game, const Request & req) {
+WareInstance& WarehouseSupply::launch_ware(Game& game, const Request& req) {
if (req.get_type() != wwWARE)
throw wexception("WarehouseSupply::launch_ware: called for non-ware request");
if (!m_wares.stock(req.get_index()))
@@ -237,29 +218,26 @@
}
/// Launch a ware as worker.
-Worker & WarehouseSupply::launch_worker(Game & game, const Request & req)
-{
- return
- m_warehouse->launch_worker
- (game, req.get_index(), req.get_requirements());
+Worker& WarehouseSupply::launch_worker(Game& game, const Request& req) {
+ return m_warehouse->launch_worker(game, req.get_index(), req.get_requirements());
}
-
/*
==============================
Warehouse Building
==============================
*/
-
/// Warehouse Descr
-WarehouseDescr::WarehouseDescr
- (char const* const _name, char const* const _descname,
- const std::string& directory, Profile& prof, Section& global_s, const TribeDescr& _tribe)
- : BuildingDescr(MapObjectType::WAREHOUSE, _name, _descname, directory, prof, global_s, _tribe),
- m_conquers (0),
- m_heal_per_second (0)
-{
+WarehouseDescr::WarehouseDescr(char const* const _name,
+ char const* const _descname,
+ const std::string& directory,
+ Profile& prof,
+ Section& global_s,
+ const TribeDescr& _tribe)
+ : BuildingDescr(MapObjectType::WAREHOUSE, _name, _descname, directory, prof, global_s, _tribe),
+ m_conquers(0),
+ m_heal_per_second(0) {
m_heal_per_second = global_s.get_safe_int("heal_per_second");
if ((m_conquers = prof.get_safe_section("global").get_positive("conquers", 0)))
m_workarea_info[m_conquers].insert(descname() + " conquer");
@@ -271,25 +249,21 @@
==============================
*/
-Warehouse::Warehouse(const WarehouseDescr & warehouse_descr) :
- Building(warehouse_descr),
- m_supply(new WarehouseSupply(this)),
- m_next_military_act(0),
- m_portdock(nullptr)
-{
+Warehouse::Warehouse(const WarehouseDescr& warehouse_descr)
+ : Building(warehouse_descr),
+ m_supply(new WarehouseSupply(this)),
+ m_next_military_act(0),
+ m_portdock(nullptr) {
uint8_t nr_worker_types_without_cost =
- warehouse_descr.tribe().worker_types_without_cost().size();
- m_next_worker_without_cost_spawn =
- new uint32_t[nr_worker_types_without_cost];
+ warehouse_descr.tribe().worker_types_without_cost().size();
+ m_next_worker_without_cost_spawn = new uint32_t[nr_worker_types_without_cost];
for (int i = 0; i < nr_worker_types_without_cost; ++i) {
m_next_worker_without_cost_spawn[i] = never();
}
m_next_stock_remove_act = 0;
}
-
-Warehouse::~Warehouse()
-{
+Warehouse::~Warehouse() {
delete m_supply;
delete[] m_next_worker_without_cost_spawn;
}
@@ -298,22 +272,19 @@
* Try to bring the given \ref PlannedWorkers up to date with our game data.
* Return \c false if \p pw cannot be salvaged.
*/
-bool Warehouse::_load_finish_planned_worker(PlannedWorkers & pw)
-{
+bool Warehouse::_load_finish_planned_worker(PlannedWorkers& pw) {
if (pw.index == INVALID_INDEX || !(pw.index < m_supply->get_workers().get_nrwareids()))
return false;
- const WorkerDescr * w_desc = descr().tribe().get_worker_descr(pw.index);
+ const WorkerDescr* w_desc = descr().tribe().get_worker_descr(pw.index);
if (!w_desc || !w_desc->is_buildable())
return false;
- const WorkerDescr::Buildcost & cost = w_desc->buildcost();
+ const WorkerDescr::Buildcost& cost = w_desc->buildcost();
uint32_t idx = 0;
- for
- (WorkerDescr::Buildcost::const_iterator cost_it = cost.begin();
- cost_it != cost.end(); ++cost_it, ++idx)
- {
+ for (WorkerDescr::Buildcost::const_iterator cost_it = cost.begin(); cost_it != cost.end();
+ ++cost_it, ++idx) {
WareWorker type;
WareIndex ware;
ware = descr().tribe().ware_index(cost_it->first);
@@ -325,13 +296,10 @@
return false;
if (idx < pw.requests.size()) {
- if
- (pw.requests[idx]->get_type() == type &&
- pw.requests[idx]->get_index() == ware)
+ if (pw.requests[idx]->get_type() == type && pw.requests[idx]->get_index() == ware)
continue;
- std::vector<Request *>::iterator req_it =
- pw.requests.begin() + idx + 1;
+ std::vector<Request*>::iterator req_it = pw.requests.begin() + idx + 1;
while (req_it != pw.requests.end()) {
if ((*req_it)->get_type() == type && (*req_it)->get_index() == ware)
break;
@@ -344,19 +312,16 @@
}
}
- log
- ("_load_finish_planned_worker: old savegame: "
- "need to create new request for '%s'\n",
- cost_it->first.c_str());
- pw.requests.insert
- (pw.requests.begin() + idx,
- new Request(*this, ware, &Warehouse::request_cb, type));
+ log("_load_finish_planned_worker: old savegame: "
+ "need to create new request for '%s'\n",
+ cost_it->first.c_str());
+ pw.requests.insert(
+ pw.requests.begin() + idx, new Request(*this, ware, &Warehouse::request_cb, type));
}
while (pw.requests.size() > idx) {
- log
- ("_load_finish_planned_worker: old savegame: "
- "removing outdated request.\n");
+ log("_load_finish_planned_worker: old savegame: "
+ "removing outdated request.\n");
delete pw.requests.back();
pw.requests.pop_back();
}
@@ -364,30 +329,31 @@
return true;
}
-void Warehouse::load_finish(EditorGameBase & egbase) {
+void Warehouse::load_finish(EditorGameBase& egbase) {
Building::load_finish(egbase);
uint32_t next_spawn = never();
- const std::vector<WareIndex> & worker_types_without_cost =
- descr().tribe().worker_types_without_cost();
+ const std::vector<WareIndex>& worker_types_without_cost =
+ descr().tribe().worker_types_without_cost();
for (uint8_t i = worker_types_without_cost.size(); i;) {
WareIndex const worker_index = worker_types_without_cost.at(--i);
- if
- (owner().is_worker_type_allowed(worker_index) &&
- m_next_worker_without_cost_spawn[i] == static_cast<uint32_t>(never()))
- {
+ if (owner().is_worker_type_allowed(worker_index) &&
+ m_next_worker_without_cost_spawn[i] == static_cast<uint32_t>(never())) {
if (next_spawn == static_cast<uint32_t>(never())) {
- next_spawn = schedule_act(dynamic_cast<Game&>(egbase), WORKER_WITHOUT_COST_SPAWN_INTERVAL);
+ next_spawn =
+ schedule_act(dynamic_cast<Game&>(egbase), WORKER_WITHOUT_COST_SPAWN_INTERVAL);
}
m_next_worker_without_cost_spawn[i] = next_spawn;
- log
- ("WARNING: player %u is allowed to create worker type %s but his "
- "%s %u at (%i, %i) does not have a next_spawn time set for that "
- "worker type; setting it to %u\n",
- owner().player_number(),
- descr().tribe().get_worker_descr(worker_index)->descname().c_str(),
- descr().descname().c_str(), serial(), get_position().x, get_position().y,
- next_spawn);
+ log("WARNING: player %u is allowed to create worker type %s but his "
+ "%s %u at (%i, %i) does not have a next_spawn time set for that "
+ "worker type; setting it to %u\n",
+ owner().player_number(),
+ descr().tribe().get_worker_descr(worker_index)->descname().c_str(),
+ descr().descname().c_str(),
+ serial(),
+ get_position().x,
+ get_position().y,
+ next_spawn);
}
}
@@ -405,13 +371,12 @@
}
}
-void Warehouse::init(EditorGameBase & egbase)
-{
+void Warehouse::init(EditorGameBase& egbase) {
Building::init(egbase);
- WareIndex const nr_wares = descr().tribe().get_nrwares ();
+ WareIndex const nr_wares = descr().tribe().get_nrwares();
WareIndex const nr_workers = descr().tribe().get_nrworkers();
- m_supply->set_nrwares (nr_wares);
+ m_supply->set_nrwares(nr_wares);
m_supply->set_nrworkers(nr_workers);
m_ware_policy.resize(nr_wares, SP_Normal);
@@ -420,17 +385,15 @@
// Even though technically, a warehouse might be completely empty,
// we let warehouse see always for simplicity's sake (since there's
// almost always going to be a carrier inside, that shouldn't hurt).
- Player & player = owner();
+ Player& player = owner();
if (upcast(Game, game, &egbase)) {
- player.see_area
- (Area<FCoords>
- (egbase.map().get_fcoords(get_position()), descr().vision_range()));
+ player.see_area(
+ Area<FCoords>(egbase.map().get_fcoords(get_position()), descr().vision_range()));
{
- uint32_t const act_time = schedule_act
- (*game, WORKER_WITHOUT_COST_SPAWN_INTERVAL);
- const std::vector<WareIndex> & worker_types_without_cost =
- descr().tribe().worker_types_without_cost();
+ uint32_t const act_time = schedule_act(*game, WORKER_WITHOUT_COST_SPAWN_INTERVAL);
+ const std::vector<WareIndex>& worker_types_without_cost =
+ descr().tribe().worker_types_without_cost();
for (size_t i = 0; i < worker_types_without_cost.size(); ++i) {
if (owner().is_worker_type_allowed(worker_types_without_cost.at(i))) {
@@ -445,22 +408,21 @@
m_next_stock_remove_act = schedule_act(*game, 4000);
- log("Message: adding (wh) (%s) %i \n", to_string(descr().type()).c_str(), player.player_number());
- send_message
- (*game,
- "warehouse",
- descr().descname(),
- (boost::format(_("A new %s was added to your economy."))
- % descr().descname().c_str()).str(),
- true);
- }
+ log("Message: adding (wh) (%s) %i \n",
+ to_string(descr().type()).c_str(),
+ player.player_number());
+ send_message(*game,
+ "warehouse",
+ descr().descname(),
+ (boost::format(_("A new %s was added to your economy.")) %
+ descr().descname().c_str()).str(),
+ true);
+ }
if (uint32_t const conquer_radius = descr().get_conquers())
- egbase.conquer_area
- (PlayerArea<Area<FCoords> >
- (player.player_number(),
- Area<FCoords>
- (egbase.map().get_fcoords(get_position()), conquer_radius)));
+ egbase.conquer_area(PlayerArea<Area<FCoords>>(
+ player.player_number(),
+ Area<FCoords>(egbase.map().get_fcoords(get_position()), conquer_radius)));
if (descr().get_isport())
init_portdock(egbase);
@@ -470,11 +432,10 @@
* Find a contiguous set of water fields close to the port for docking
* and initialize the @ref PortDock instance.
*/
-void Warehouse::init_portdock(EditorGameBase & egbase)
-{
+void Warehouse::init_portdock(EditorGameBase& egbase) {
molog("Setting up port dock fields\n");
- Map & map = egbase.map();
+ Map& map = egbase.map();
std::vector<Coords> dock = map.find_portdock(get_position());
if (dock.empty()) {
log("Attempting to setup port without neighboring water.\n");
@@ -495,14 +456,12 @@
m_portdock->set_economy(get_economy());
}
-void Warehouse::destroy(EditorGameBase & egbase)
-{
+void Warehouse::destroy(EditorGameBase& egbase) {
Building::destroy(egbase);
}
/// Destroy the warehouse.
-void Warehouse::cleanup(EditorGameBase & egbase)
-{
+void Warehouse::cleanup(EditorGameBase& egbase) {
if (egbase.objects().object_still_available(m_portdock)) {
m_portdock->remove(egbase);
m_portdock = nullptr;
@@ -529,21 +488,18 @@
Map& map = egbase.map();
if (const uint32_t conquer_radius = descr().get_conquers())
- egbase.unconquer_area
- (PlayerArea<Area<FCoords> >
- (owner().player_number(),
- Area<FCoords>(map.get_fcoords(get_position()), conquer_radius)),
- m_defeating_player);
+ egbase.unconquer_area(
+ PlayerArea<Area<FCoords>>(owner().player_number(),
+ Area<FCoords>(map.get_fcoords(get_position()), conquer_radius)),
+ m_defeating_player);
// Unsee the area that we started seeing in init()
- Player & player = owner();
- player.unsee_area
- (Area<FCoords>(map.get_fcoords(get_position()), descr().vision_range()));
+ Player& player = owner();
+ player.unsee_area(Area<FCoords>(map.get_fcoords(get_position()), descr().vision_range()));
Building::cleanup(egbase);
}
-
/// Act regularly to create workers of buildable types without cost. According
/// to intelligence, this is some highly advanced technology. Not only do the
/// settlers have no problems with birth control, they do not even need anybody
@@ -551,12 +507,11 @@
/// what the hell are they doing, killing useless tribesmen! The Borg? Or just
/// like Soylent Green? Or maybe I should just stop writing comments that late
/// at night ;-)
-void Warehouse::act(Game & game, uint32_t const data)
-{
+void Warehouse::act(Game& game, uint32_t const data) {
uint32_t const gametime = game.get_gametime();
{
- const std::vector<WareIndex> & worker_types_without_cost =
- owner().tribe().worker_types_without_cost();
+ const std::vector<WareIndex>& worker_types_without_cost =
+ owner().tribe().worker_types_without_cost();
for (size_t i = worker_types_without_cost.size(); i;)
if (m_next_worker_without_cost_spawn[--i] <= gametime) {
WareIndex const id = worker_types_without_cost.at(i);
@@ -574,8 +529,7 @@
remove_workers(id, 1);
}
- m_next_worker_without_cost_spawn[i] =
- schedule_act(game, tdelta);
+ m_next_worker_without_cost_spawn[i] = schedule_act(game, tdelta);
} else
m_next_worker_without_cost_spawn[i] = never();
}
@@ -586,19 +540,15 @@
WareIndex const ware = descr().tribe().safe_worker_index("soldier");
if (m_incorporated_workers.count(ware)) {
- WorkerList & soldiers = m_incorporated_workers[ware];
+ WorkerList& soldiers = m_incorporated_workers[ware];
uint32_t total_heal = descr().get_heal_per_second();
// Using an explicit iterator, as we plan to erase some
// of those guys
- for
- (WorkerList::iterator it = soldiers.begin();
- it != soldiers.end();
- ++it)
- {
+ for (WorkerList::iterator it = soldiers.begin(); it != soldiers.end(); ++it) {
// This is a safe cast: we know only soldiers can land in this
// slot in the incorporated array
- Soldier * soldier = static_cast<Soldier *>(*it);
+ Soldier* soldier = static_cast<Soldier*>(*it);
// Soldier dead ...
if (!soldier || soldier->get_current_hitpoints() == 0) {
@@ -611,7 +561,6 @@
soldier->heal(total_heal);
continue;
}
-
}
}
m_next_military_act = schedule_act(game, 1000);
@@ -632,11 +581,9 @@
Building::act(game, data);
}
-
/// Transfer our registration to the new economy.
-void Warehouse::set_economy(Economy * const e)
-{
- Economy * const old = get_economy();
+void Warehouse::set_economy(Economy* const e) {
+ Economy* const old = get_economy();
if (old == e)
return;
@@ -650,7 +597,7 @@
Building::set_economy(e);
for (const PlannedWorkers& pw : m_planned_workers) {
- for (Request * req : pw.requests) {
+ for (Request* req : pw.requests) {
req->set_economy(e);
}
}
@@ -662,82 +609,62 @@
e->add_warehouse(*this);
}
-
-const WareList & Warehouse::get_wares() const
-{
+const WareList& Warehouse::get_wares() const {
return m_supply->get_wares();
}
-
-const WareList & Warehouse::get_workers() const
-{
+const WareList& Warehouse::get_workers() const {
return m_supply->get_workers();
}
-PlayerImmovable::Workers Warehouse::get_incorporated_workers()
-{
+PlayerImmovable::Workers Warehouse::get_incorporated_workers() {
PlayerImmovable::Workers all_workers;
for (const std::pair<WareIndex, WorkerList>& worker_pair : m_incorporated_workers) {
- for (Worker * worker : worker_pair.second) {
+ for (Worker* worker : worker_pair.second) {
all_workers.push_back(worker);
}
}
return all_workers;
}
-
/// Magically create wares in this warehouse. Updates the economy accordingly.
-void Warehouse::insert_wares(WareIndex const id, uint32_t const count)
-{
+void Warehouse::insert_wares(WareIndex const id, uint32_t const count) {
m_supply->add_wares(id, count);
}
-
/// Magically destroy wares.
-void Warehouse::remove_wares(WareIndex const id, uint32_t const count)
-{
+void Warehouse::remove_wares(WareIndex const id, uint32_t const count) {
m_supply->remove_wares(id, count);
}
-
/// Magically create workers in this warehouse. Updates the economy accordingly.
-void Warehouse::insert_workers(WareIndex const id, uint32_t const count)
-{
+void Warehouse::insert_workers(WareIndex const id, uint32_t const count) {
m_supply->add_workers(id, count);
}
-
/// Magically destroy workers.
-void Warehouse::remove_workers(WareIndex const id, uint32_t const count)
-{
+void Warehouse::remove_workers(WareIndex const id, uint32_t const count) {
m_supply->remove_workers(id, count);
}
-
-
/// Launch a carrier to fetch an ware from our flag.
-bool Warehouse::fetch_from_flag(Game & game)
-{
+bool Warehouse::fetch_from_flag(Game& game) {
WareIndex const carrierid = descr().tribe().safe_worker_index("carrier");
- if (!m_supply->stock_workers(carrierid)) // XXX yep, let's cheat
+ if (!m_supply->stock_workers(carrierid)) // XXX yep, let's cheat
insert_workers(carrierid, 1);
- launch_worker(game, carrierid, Requirements()).start_task_fetchfromflag
- (game);
+ launch_worker(game, carrierid, Requirements()).start_task_fetchfromflag(game);
return true;
}
-
/**
* \return the number of workers that we can launch satisfying the given
* requirements.
*/
-uint32_t Warehouse::count_workers
- (const Game & /* game */, WareIndex ware, const Requirements & req)
-{
+uint32_t Warehouse::count_workers(const Game& /* game */, WareIndex ware, const Requirements& req) {
uint32_t sum = 0;
do {
@@ -745,7 +672,7 @@
// NOTE: This code lies about the TrainingAttributes of non-instantiated workers.
if (m_incorporated_workers.count(ware)) {
- for (Worker * worker : m_incorporated_workers[ware]) {
+ for (Worker* worker : m_incorporated_workers[ware]) {
if (!req.check(*worker)) {
// This is one of the workers in our sum.
// But he is too stupid for this job
@@ -762,9 +689,7 @@
/// Start a worker of a given type. The worker will
/// be assigned a job by the caller.
-Worker & Warehouse::launch_worker
- (Game & game, WareIndex ware, const Requirements & req)
-{
+Worker& Warehouse::launch_worker(Game& game, WareIndex ware, const Requirements& req) {
do {
if (m_supply->stock_workers(ware)) {
uint32_t unincorporated = m_supply->stock_workers(ware);
@@ -777,15 +702,15 @@
remove_no_longer_existing_workers(game, &m_incorporated_workers[ware]);
WorkerList& incorporated_workers = m_incorporated_workers[ware];
- for (std::vector<Worker *>::iterator worker_iter = incorporated_workers.begin();
- worker_iter != incorporated_workers.end(); ++worker_iter)
- {
+ for (std::vector<Worker*>::iterator worker_iter = incorporated_workers.begin();
+ worker_iter != incorporated_workers.end();
+ ++worker_iter) {
Worker* worker = *worker_iter;
--unincorporated;
if (req.check(*worker)) {
- worker->reset_tasks(game); // forget everything you did
- worker->set_location(this); // back in a economy
+ worker->reset_tasks(game); // forget everything you did
+ worker->set_location(this); // back in a economy
incorporated_workers.erase(worker_iter);
m_supply->remove_workers(ware, 1);
@@ -800,7 +725,7 @@
// Create a new one
// NOTE: This code lies about the TrainingAttributes of the new worker
m_supply->remove_workers(ware, 1);
- const WorkerDescr & workerdescr = *descr().tribe().get_worker_descr(ware);
+ const WorkerDescr& workerdescr = *descr().tribe().get_worker_descr(ware);
return workerdescr.create(game, owner(), this, m_position);
}
}
@@ -813,13 +738,10 @@
}
} while (ware != INVALID_INDEX);
- throw wexception
- ("Warehouse::launch_worker: worker does not actually exist");
+ throw wexception("Warehouse::launch_worker: worker does not actually exist");
}
-
-void Warehouse::incorporate_worker(EditorGameBase & egbase, Worker* w)
-{
+void Warehouse::incorporate_worker(EditorGameBase& egbase, Worker* w) {
assert(w != nullptr);
assert(w->get_owner() == &owner());
@@ -845,10 +767,10 @@
// Incorporate the worker
if (!m_incorporated_workers.count(worker_index))
- m_incorporated_workers[worker_index] = std::vector<Worker *>();
+ m_incorporated_workers[worker_index] = std::vector<Worker*>();
m_incorporated_workers[worker_index].push_back(w);
- w->set_location(nullptr); // no longer in an economy
+ w->set_location(nullptr); // no longer in an economy
if (upcast(Game, game, &egbase)) {
// Bind the worker into this house, hide him on the map.
@@ -859,9 +781,9 @@
/// Create an instance of a ware and make sure it gets
/// carried out of the warehouse.
-WareInstance & Warehouse::launch_ware(Game & game, WareIndex const ware_index) {
+WareInstance& Warehouse::launch_ware(Game& game, WareIndex const ware_index) {
// Create the ware
- WareInstance & ware = *new WareInstance(ware_index, descr().tribe().get_ware_descr(ware_index));
+ WareInstance& ware = *new WareInstance(ware_index, descr().tribe().get_ware_descr(ware_index));
ware.init(game);
do_launch_ware(game, ware);
@@ -870,15 +792,13 @@
return ware;
}
-
/// Get a carrier to actually move this ware out of the warehouse.
-void Warehouse::do_launch_ware(Game & game, WareInstance & ware)
-{
+void Warehouse::do_launch_ware(Game& game, WareInstance& ware) {
// Create a carrier
WareIndex const carrierid = descr().tribe().worker_index("carrier");
- const WorkerDescr & workerdescr = *descr().tribe().get_worker_descr(carrierid);
+ const WorkerDescr& workerdescr = *descr().tribe().get_worker_descr(carrierid);
- Worker & worker = workerdescr.create(game, owner(), this, m_position);
+ Worker& worker = workerdescr.create(game, owner(), this, m_position);
// Yup, this is cheating.
if (m_supply->stock_workers(carrierid))
@@ -888,23 +808,15 @@
worker.start_task_dropoff(game, ware);
}
-
-void Warehouse::incorporate_ware(EditorGameBase & egbase, WareInstance* ware)
-{
+void Warehouse::incorporate_ware(EditorGameBase& egbase, WareInstance* ware) {
m_supply->add_wares(ware->descr_index(), 1);
ware->destroy(egbase);
}
-
/// Called when a transfer for one of the idle Requests completes.
-void Warehouse::request_cb
- (Game & game,
- Request &,
- WareIndex const ware,
- Worker * const w,
- PlayerImmovable & target)
-{
- Warehouse & wh = dynamic_cast<Warehouse&>(target);
+void Warehouse::request_cb(
+ Game& game, Request&, WareIndex const ware, Worker* const w, PlayerImmovable& target) {
+ Warehouse& wh = dynamic_cast<Warehouse&>(target);
if (w) {
w->schedule_incorporate(game);
@@ -921,38 +833,35 @@
/**
* Receive a ware from a transfer that was not associated to a \ref Request.
*/
-void Warehouse::receive_ware(Game & /* game */, WareIndex ware)
-{
+void Warehouse::receive_ware(Game& /* game */, WareIndex ware) {
m_supply->add_wares(ware, 1);
}
/**
* Receive a worker from a transfer that was not associated to a \ref Request.
*/
-void Warehouse::receive_worker(Game & game, Worker & worker)
-{
+void Warehouse::receive_worker(Game& game, Worker& worker) {
worker.schedule_incorporate(game);
}
-Building & WarehouseDescr::create_object() const {
+Building& WarehouseDescr::create_object() const {
return *new Warehouse(*this);
}
-
-bool Warehouse::can_create_worker(Game &, WareIndex const worker) const {
+bool Warehouse::can_create_worker(Game&, WareIndex const worker) const {
if (!(worker < m_supply->get_workers().get_nrwareids()))
- throw wexception
- ("worker type %d does not exists (max is %d)",
- worker, m_supply->get_workers().get_nrwareids());
+ throw wexception("worker type %d does not exists (max is %d)",
+ worker,
+ m_supply->get_workers().get_nrwareids());
- const WorkerDescr & w_desc = *descr().tribe().get_worker_descr(worker);
+ const WorkerDescr& w_desc = *descr().tribe().get_worker_descr(worker);
assert(&w_desc);
if (!w_desc.is_buildable())
return false;
// see if we have the resources
for (const std::pair<std::string, uint8_t>& buildcost : w_desc.buildcost()) {
- const std::string & input_name = buildcost.first;
+ const std::string& input_name = buildcost.first;
WareIndex id_w = descr().tribe().ware_index(input_name);
if (id_w != INVALID_INDEX) {
if (m_supply->stock_wares(id_w) < buildcost.second)
@@ -961,27 +870,26 @@
if (m_supply->stock_workers(id_w) < buildcost.second)
return false;
} else
- throw wexception
- ("worker type %s needs \"%s\" to be built but that is neither "
- "a ware type nor a worker type defined in the tribe %s",
- w_desc.descname().c_str(), input_name.c_str(),
- descr().tribe().name().c_str());
+ throw wexception("worker type %s needs \"%s\" to be built but that is neither "
+ "a ware type nor a worker type defined in the tribe %s",
+ w_desc.descname().c_str(),
+ input_name.c_str(),
+ descr().tribe().name().c_str());
}
return true;
}
-
-void Warehouse::create_worker(Game & game, WareIndex const worker) {
- assert(can_create_worker (game, worker));
-
- const WorkerDescr & w_desc = *descr().tribe().get_worker_descr(worker);
+void Warehouse::create_worker(Game& game, WareIndex const worker) {
+ assert(can_create_worker(game, worker));
+
+ const WorkerDescr& w_desc = *descr().tribe().get_worker_descr(worker);
for (const std::pair<std::string, uint8_t>& buildcost : w_desc.buildcost()) {
- const std::string & input = buildcost.first;
+ const std::string& input = buildcost.first;
WareIndex const id_ware = descr().tribe().ware_index(input);
if (id_ware != INVALID_INDEX) {
- remove_wares (id_ware, buildcost.second);
- //update statistic accordingly
+ remove_wares(id_ware, buildcost.second);
+ // update statistic accordingly
owner().ware_consumed(id_ware, buildcost.second);
} else
remove_workers(descr().tribe().safe_worker_index(input), buildcost.second);
@@ -1003,8 +911,7 @@
* Return the number of workers of the given type that we plan to
* create in this warehouse.
*/
-uint32_t Warehouse::get_planned_workers(Game & /* game */, WareIndex index) const
-{
+uint32_t Warehouse::get_planned_workers(Game& /* game */, WareIndex index) const {
for (const PlannedWorkers& pw : m_planned_workers) {
if (pw.index == index)
return pw.amount;
@@ -1018,23 +925,21 @@
*
* This is the current stock plus any incoming transfers.
*/
-std::vector<uint32_t> Warehouse::calc_available_for_worker
- (Game & /* game */, WareIndex index) const
-{
- const WorkerDescr & w_desc = *descr().tribe().get_worker_descr(index);
+std::vector<uint32_t> Warehouse::calc_available_for_worker(Game& /* game */,
+ WareIndex index) const {
+ const WorkerDescr& w_desc = *descr().tribe().get_worker_descr(index);
std::vector<uint32_t> available;
for (const std::pair<std::string, uint8_t>& buildcost : w_desc.buildcost()) {
- const std::string & input_name = buildcost.first;
+ const std::string& input_name = buildcost.first;
WareIndex id_w = descr().tribe().ware_index(input_name);
if (id_w != INVALID_INDEX) {
available.push_back(get_wares().stock(id_w));
} else if ((id_w = descr().tribe().worker_index(input_name)) != INVALID_INDEX) {
available.push_back(get_workers().stock(id_w));
} else
- throw wexception
- ("Economy::_create_requested_worker: buildcost inconsistency '%s'",
- input_name.c_str());
+ throw wexception(
+ "Economy::_create_requested_worker: buildcost inconsistency '%s'", input_name.c_str());
}
for (const PlannedWorkers& pw : m_planned_workers) {
@@ -1050,14 +955,12 @@
return available;
}
-
/**
* Set the amount of workers we plan to create
* of the given \p index to \p amount.
*/
-void Warehouse::plan_workers(Game & game, WareIndex index, uint32_t amount)
-{
- PlannedWorkers * pw = nullptr;
+void Warehouse::plan_workers(Game& game, WareIndex index, uint32_t amount) {
+ PlannedWorkers* pw = nullptr;
for (PlannedWorkers& planned_worker : m_planned_workers) {
if (planned_worker.index == index) {
@@ -1075,22 +978,17 @@
pw->index = index;
pw->amount = 0;
- const WorkerDescr & w_desc = *descr().tribe().get_worker_descr(pw->index);
+ const WorkerDescr& w_desc = *descr().tribe().get_worker_descr(pw->index);
for (const std::pair<std::string, uint8_t>& buildcost : w_desc.buildcost()) {
- const std::string & input_name = buildcost.first;
+ const std::string& input_name = buildcost.first;
WareIndex id_w = descr().tribe().ware_index(input_name);
if (id_w != INVALID_INDEX) {
- pw->requests.push_back
- (new Request
- (*this, id_w, &Warehouse::request_cb, wwWARE));
+ pw->requests.push_back(new Request(*this, id_w, &Warehouse::request_cb, wwWARE));
} else if ((id_w = descr().tribe().worker_index(input_name)) != INVALID_INDEX) {
- pw->requests.push_back
- (new Request
- (*this, id_w, &Warehouse::request_cb, wwWORKER));
+ pw->requests.push_back(new Request(*this, id_w, &Warehouse::request_cb, wwWORKER));
} else
- throw wexception
- ("plan_workers: bad buildcost '%s'", input_name.c_str());
+ throw wexception("plan_workers: bad buildcost '%s'", input_name.c_str());
}
}
@@ -1102,10 +1000,8 @@
* See if we can create the workers of the given plan,
* and update requests accordingly.
*/
-void Warehouse::_update_planned_workers
- (Game & game, Warehouse::PlannedWorkers & pw)
-{
- const WorkerDescr & w_desc = *descr().tribe().get_worker_descr(pw.index);
+void Warehouse::_update_planned_workers(Game& game, Warehouse::PlannedWorkers& pw) {
+ const WorkerDescr& w_desc = *descr().tribe().get_worker_descr(pw.index);
while (pw.amount && can_create_worker(game, pw.index)) {
create_worker(game, pw.index);
@@ -1114,7 +1010,7 @@
uint32_t idx = 0;
for (const std::pair<std::string, uint8_t>& buildcost : w_desc.buildcost()) {
- const std::string & input_name = buildcost.first;
+ const std::string& input_name = buildcost.first;
uint32_t supply;
WareIndex id_w = descr().tribe().ware_index(input_name);
@@ -1123,14 +1019,12 @@
} else if ((id_w = descr().tribe().worker_index(input_name)) != INVALID_INDEX) {
supply = m_supply->stock_workers(id_w);
} else
- throw wexception
- ("_update_planned_workers: bad buildcost '%s'", input_name.c_str());
+ throw wexception("_update_planned_workers: bad buildcost '%s'", input_name.c_str());
if (supply >= pw.amount * buildcost.second)
pw.requests[idx]->set_count(0);
else
- pw.requests[idx]->set_count
- (pw.amount * buildcost.second - supply);
+ pw.requests[idx]->set_count(pw.amount * buildcost.second - supply);
++idx;
}
@@ -1146,8 +1040,7 @@
* Needs to be called periodically, because some necessary supplies might arrive
* due to idle transfers instead of by explicit request.
*/
-void Warehouse::_update_all_planned_workers(Game & game)
-{
+void Warehouse::_update_all_planned_workers(Game& game) {
uint32_t idx = 0;
while (idx < m_planned_workers.size()) {
_update_planned_workers(game, m_planned_workers[idx]);
@@ -1161,51 +1054,35 @@
}
}
-void Warehouse::enable_spawn
- (Game & game, uint8_t const worker_types_without_cost_index)
-{
- assert
- (m_next_worker_without_cost_spawn[worker_types_without_cost_index]
- ==
- static_cast<uint32_t>(never()));
+void Warehouse::enable_spawn(Game& game, uint8_t const worker_types_without_cost_index) {
+ assert(m_next_worker_without_cost_spawn[worker_types_without_cost_index] ==
+ static_cast<uint32_t>(never()));
m_next_worker_without_cost_spawn[worker_types_without_cost_index] =
- schedule_act(game, WORKER_WITHOUT_COST_SPAWN_INTERVAL);
+ schedule_act(game, WORKER_WITHOUT_COST_SPAWN_INTERVAL);
}
-void Warehouse::disable_spawn(uint8_t const worker_types_without_cost_index)
-{
- assert
- (m_next_worker_without_cost_spawn[worker_types_without_cost_index]
- !=
- static_cast<uint32_t>(never()));
+void Warehouse::disable_spawn(uint8_t const worker_types_without_cost_index) {
+ assert(m_next_worker_without_cost_spawn[worker_types_without_cost_index] !=
+ static_cast<uint32_t>(never()));
m_next_worker_without_cost_spawn[worker_types_without_cost_index] = never();
}
-
-bool Warehouse::can_attack()
-{
+bool Warehouse::can_attack() {
return descr().get_conquers() > 0;
}
-void Warehouse::aggressor(Soldier & enemy)
-{
+void Warehouse::aggressor(Soldier& enemy) {
if (!descr().get_conquers())
return;
- Game & game = dynamic_cast<Game&>(owner().egbase());
- Map & map = game.map();
- if
- (enemy.get_owner() == &owner() ||
- enemy.get_battle() ||
- descr().get_conquers()
- <=
- map.calc_distance(enemy.get_position(), get_position()))
+ Game& game = dynamic_cast<Game&>(owner().egbase());
+ Map& map = game.map();
+ if (enemy.get_owner() == &owner() || enemy.get_battle() ||
+ descr().get_conquers() <= map.calc_distance(enemy.get_position(), get_position()))
return;
- if
- (game.map().find_bobs
- (Area<FCoords>(map.get_fcoords(base_flag().get_position()), 2),
- nullptr,
- FindBobEnemySoldier(&owner())))
+ if (game.map().find_bobs(Area<FCoords>(map.get_fcoords(base_flag().get_position()), 2),
+ nullptr,
+ FindBobEnemySoldier(&owner())))
return;
WareIndex const soldier_index = descr().tribe().worker_index("soldier");
@@ -1214,18 +1091,17 @@
if (!count_workers(game, soldier_index, noreq))
return;
- Soldier & defender = dynamic_cast<Soldier&>(launch_worker(game, soldier_index, noreq));
+ Soldier& defender = dynamic_cast<Soldier&>(launch_worker(game, soldier_index, noreq));
defender.start_task_defense(game, false);
}
-bool Warehouse::attack(Soldier & enemy)
-{
- Game & game = dynamic_cast<Game&>(owner().egbase());
+bool Warehouse::attack(Soldier& enemy) {
+ Game& game = dynamic_cast<Game&>(owner().egbase());
WareIndex const soldier_index = descr().tribe().worker_index("soldier");
Requirements noreq;
if (count_workers(game, soldier_index, noreq)) {
- Soldier & defender = dynamic_cast<Soldier&>(launch_worker(game, soldier_index, noreq));
+ Soldier& defender = dynamic_cast<Soldier&>(launch_worker(game, soldier_index, noreq));
defender.start_task_defense(game, true);
enemy.send_signal(game, "sleep");
return true;
@@ -1236,45 +1112,36 @@
return false;
}
-void Warehouse::PlannedWorkers::cleanup()
-{
+void Warehouse::PlannedWorkers::cleanup() {
while (!requests.empty()) {
delete requests.back();
requests.pop_back();
}
}
-Warehouse::StockPolicy Warehouse::get_ware_policy(WareIndex ware) const
-{
+Warehouse::StockPolicy Warehouse::get_ware_policy(WareIndex ware) const {
assert(ware < m_ware_policy.size());
return m_ware_policy[ware];
}
-Warehouse::StockPolicy Warehouse::get_worker_policy(WareIndex ware) const
-{
+Warehouse::StockPolicy Warehouse::get_worker_policy(WareIndex ware) const {
assert(ware < m_worker_policy.size());
return m_worker_policy[ware];
}
-Warehouse::StockPolicy Warehouse::get_stock_policy
- (WareWorker waretype, WareIndex wareindex) const
-{
+Warehouse::StockPolicy Warehouse::get_stock_policy(WareWorker waretype, WareIndex wareindex) const {
if (waretype == wwWORKER)
return get_worker_policy(wareindex);
else
return get_ware_policy(wareindex);
}
-
-void Warehouse::set_ware_policy(WareIndex ware, Warehouse::StockPolicy policy)
-{
+void Warehouse::set_ware_policy(WareIndex ware, Warehouse::StockPolicy policy) {
assert(ware < m_ware_policy.size());
m_ware_policy[ware] = policy;
}
-void Warehouse::set_worker_policy
- (WareIndex ware, Warehouse::StockPolicy policy)
-{
+void Warehouse::set_worker_policy(WareIndex ware, Warehouse::StockPolicy policy) {
assert(ware < m_worker_policy.size());
m_worker_policy[ware] = policy;
}
@@ -1283,8 +1150,7 @@
* Check if there are remaining wares with stock policy \ref SP_Remove,
* and remove one of them if appropriate.
*/
-void Warehouse::check_remove_stock(Game & game)
-{
+void Warehouse::check_remove_stock(Game& game) {
if (base_flag().current_wares() < base_flag().total_capacity() / 2) {
for (WareIndex ware = 0; ware < m_ware_policy.size(); ++ware) {
if (get_ware_policy(ware) != SP_Remove || !get_wares().stock(ware))
@@ -1299,7 +1165,7 @@
if (get_worker_policy(widx) != SP_Remove || !get_workers().stock(widx))
continue;
- Worker & worker = launch_worker(game, widx, Requirements());
+ Worker& worker = launch_worker(game, widx, Requirements());
worker.start_task_leavebuilding(game, true);
break;
}
@@ -1315,36 +1181,34 @@
/*
* SoldierControl implementations
*/
-std::vector<Soldier *> Warehouse::present_soldiers() const
-{
- std::vector<Soldier *> rv;
+std::vector<Soldier*> Warehouse::present_soldiers() const {
+ std::vector<Soldier*> rv;
WareIndex const ware = descr().tribe().safe_worker_index("soldier");
IncorporatedWorkers::const_iterator sidx = m_incorporated_workers.find(ware);
if (sidx != m_incorporated_workers.end()) {
- const WorkerList & soldiers = sidx->second;
+ const WorkerList& soldiers = sidx->second;
- for (Worker * temp_soldier: soldiers) {
- rv.push_back(static_cast<Soldier *>(temp_soldier));
+ for (Worker* temp_soldier : soldiers) {
+ rv.push_back(static_cast<Soldier*>(temp_soldier));
}
}
return rv;
}
-int Warehouse::incorporate_soldier(EditorGameBase & egbase, Soldier & soldier) {
+int Warehouse::incorporate_soldier(EditorGameBase& egbase, Soldier& soldier) {
incorporate_worker(egbase, &soldier);
return 0;
}
-int Warehouse::outcorporate_soldier(EditorGameBase & /* egbase */, Soldier & soldier) {
+int Warehouse::outcorporate_soldier(EditorGameBase& /* egbase */, Soldier& soldier) {
WareIndex const ware = descr().tribe().safe_worker_index("soldier");
if (m_incorporated_workers.count(ware)) {
- WorkerList & soldiers = m_incorporated_workers[ware];
+ WorkerList& soldiers = m_incorporated_workers[ware];
- WorkerList::iterator i = std::find
- (soldiers.begin(), soldiers.end(), &soldier);
+ WorkerList::iterator i = std::find(soldiers.begin(), soldiers.end(), &soldier);
soldiers.erase(i);
m_supply->remove_workers(ware, 1);
@@ -1357,13 +1221,10 @@
return 0;
}
-void Warehouse::log_general_info(const EditorGameBase & egbase)
-{
+void Warehouse::log_general_info(const EditorGameBase& egbase) {
Building::log_general_info(egbase);
if (descr().get_isport())
molog("Port dock: %u\n", m_portdock ? m_portdock->serial() : 0);
}
-
-
}
Follow ups