/// Gibt eine Liste mit möglichen Verbindungen zurück void nobHarborBuilding::GetShipConnections(std::vector<ShipConnection>& connections) const { // Is there any harbor building at all? (could be destroyed)? if(gwg->GetGOT(this->x,this->y) !=GOT_NOB_HARBORBUILDING) // Then good-bye return; // Is the harbor being destroyed right now? if (IsBeingDestroyedNow()) return; std::vector<nobHarborBuilding*> harbor_buildings; for(unsigned short sea_id = 0;sea_id<6;++sea_id) { if(sea_ids[sea_id] != 0) players->getElement(player)->GetHarborBuildings(harbor_buildings,sea_ids[sea_id]); } for(unsigned i = 0;i<harbor_buildings.size();++i) { ShipConnection sc; sc.dest = harbor_buildings[i]; // Als Kantengewicht nehmen wir die doppelte Entfernung (evtl muss ja das Schiff erst kommen) // plus einer Kopfpauschale (Ein/Ausladen usw. dauert ja alles) sc.way_costs = 2*gwg->CalcHarborDistance(GetHarborPosID(),harbor_buildings[i]->GetHarborPosID()) + 10; connections.push_back(sc); } }
/// Gibt eine Liste mit möglichen Verbindungen zurück std::vector<nobHarborBuilding::ShipConnection> nobHarborBuilding::GetShipConnections() const { std::vector<ShipConnection> connections; // Is the harbor being destroyed right now? Could happen due to pathfinding for wares that get notified about this buildings destruction if (IsBeingDestroyedNow()) return connections; // Should already be handled by the above check, but keep the runtime check for now (TODO: remove runtime check) RTTR_Assert(gwg->GetGOT(pos) == GOT_NOB_HARBORBUILDING); // Is there any harbor building at all? (could be destroyed)? if(gwg->GetGOT(pos) != GOT_NOB_HARBORBUILDING) return connections; std::vector<nobHarborBuilding*> harbor_buildings; for(unsigned short sea_id = 0; sea_id < 6; ++sea_id) { if(sea_ids[sea_id] != 0) gwg->GetPlayer(player).GetHarborBuildings(harbor_buildings, sea_ids[sea_id]); } for(unsigned i = 0; i < harbor_buildings.size(); ++i) { ShipConnection sc; sc.dest = harbor_buildings[i]; // Als Kantengewicht nehmen wir die doppelte Entfernung (evtl muss ja das Schiff erst kommen) // plus einer Kopfpauschale (Ein/Ausladen usw. dauert ja alles) sc.way_costs = 2 * gwg->CalcHarborDistance(GetHarborPosID(), harbor_buildings[i]->GetHarborPosID()) + 10; connections.push_back(sc); } return connections; }
/// Eine bestellte Ware konnte doch nicht kommen void nobHarborBuilding::WareLost(Ware* ware) { RTTR_Assert(!IsBeingDestroyedNow()); // ggf. neue Waren für Expedition bestellen if(expedition.active && (ware->type == GD_BOARDS || ware->type == GD_STONES)) OrderExpeditionWares(); nobBaseWarehouse::WareLost(ware); }
/// Bestellt die zusätzlichen erforderlichen Waren für eine Expedition void nobHarborBuilding::OrderExpeditionWares() { RTTR_Assert(!IsBeingDestroyedNow()); // Wares should already be canceled! if (this->IsBeingDestroyedNow()) // don't order new stuff if we are about to be destroyed return; if(!expedition.active) //expedition no longer active? return; // Waren in der Bestellungsliste mit beachten unsigned boards = 0, stones = 0; for(std::list<Ware*>::iterator it = dependent_wares.begin(); it!=dependent_wares.end(); ++it) { RTTR_Assert(*it); if((*it)->type == GD_BOARDS) ++boards; if((*it)->type == GD_STONES) ++stones; } // Prüfen, ob jeweils noch weitere Waren bestellt werden müssen unsigned todo_boards = 0; if(boards + expedition.boards < BUILDING_COSTS[nation][BLD_HARBORBUILDING].boards) { todo_boards = BUILDING_COSTS[nation][BLD_HARBORBUILDING].boards - (boards + expedition.boards); Ware* ware; do { ware = gwg->GetPlayer(player).OrderWare(GD_BOARDS, this); if(ware) { RTTR_Assert(IsWareDependent(ware)); --todo_boards; } } while(ware && todo_boards); } unsigned todo_stones = 0; if(stones + expedition.stones < BUILDING_COSTS[nation][BLD_HARBORBUILDING].stones) { todo_stones = BUILDING_COSTS[nation][BLD_HARBORBUILDING].stones - (stones + expedition.stones); Ware* ware; do { ware = gwg->GetPlayer(player).OrderWare(GD_STONES, this); if(ware) { RTTR_Assert(IsWareDependent(ware)); --todo_stones; } } while(ware && todo_stones); } // Wenn immer noch nicht alles da ist, später noch einmal bestellen if(!orderware_ev) orderware_ev = em->AddEvent(this, 210, 10); }