From 82e851b43d63d2f4e8d9824cb9a7284c38aeea45 Mon Sep 17 00:00:00 2001 From: Andrettin Date: Thu, 26 May 2016 22:45:10 +0200 Subject: [PATCH] Added BordersModifier GSM province function --- src/include/grand_strategy.h | 1 + src/stratagus/grand_strategy.cpp | 42 +++++++++++++++++++++---- src/stratagus/script_grand_strategy.cpp | 10 ++++++ 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/include/grand_strategy.h b/src/include/grand_strategy.h index 1e63bb803..a9a3bcda3 100644 --- a/src/include/grand_strategy.h +++ b/src/include/grand_strategy.h @@ -170,6 +170,7 @@ class CGrandStrategyProvince : public CProvince void SetBorderProvinceConnectionTransportLevel(CGrandStrategyProvince *province, int transport_level); bool HasBuildingClass(std::string building_class_name); bool HasModifier(CUpgrade *modifier); + bool BordersModifier(CUpgrade *modifier); bool HasFactionClaim(int civilization_id, int faction_id); bool HasResource(int resource, bool ignore_prospection = false); bool BordersProvince(CGrandStrategyProvince *province); diff --git a/src/stratagus/grand_strategy.cpp b/src/stratagus/grand_strategy.cpp index 93ae0a5b5..aa035436a 100644 --- a/src/stratagus/grand_strategy.cpp +++ b/src/stratagus/grand_strategy.cpp @@ -1382,10 +1382,12 @@ void CGrandStrategyGame::DoEvents() { for (int i = 0; i < MAX_RACES; ++i) { for (size_t j = 0; j < PlayerRaces.Factions[i].size(); ++j) { - for (size_t k = 0; k < GrandStrategyGame.AvailableEvents.size(); ++k) { - CclCommand("EventFaction = GetFactionFromName(\"" + PlayerRaces.Factions[i][j]->Name + "\");"); - if (GrandStrategyGame.AvailableEvents[k]->CanTrigger(GrandStrategyGame.Factions[i][j])) { - GrandStrategyGame.AvailableEvents[k]->Trigger(GrandStrategyGame.Factions[i][j]); + if (GrandStrategyGame.Factions[i][j]->IsAlive()) { + for (size_t k = 0; k < GrandStrategyGame.AvailableEvents.size(); ++k) { + CclCommand("EventFaction = GetFactionFromName(\"" + PlayerRaces.Factions[i][j]->Name + "\");"); + if (GrandStrategyGame.AvailableEvents[k]->CanTrigger(GrandStrategyGame.Factions[i][j])) { + GrandStrategyGame.AvailableEvents[k]->Trigger(GrandStrategyGame.Factions[i][j]); + } } } } @@ -3324,6 +3326,30 @@ bool CGrandStrategyProvince::HasModifier(CUpgrade *modifier) return std::find(this->Modifiers.begin(), this->Modifiers.end(), modifier) != this->Modifiers.end(); } +bool CGrandStrategyProvince::BordersModifier(CUpgrade *modifier) +{ + //see if any provinces bordering this one have the modifier (count provinces reachable through water as well) + + for (size_t i = 0; i < this->BorderProvinces.size(); ++i) { + CGrandStrategyProvince *border_province = this->BorderProvinces[i]; + if (border_province->HasModifier(modifier)) { + return true; + } + } + + for (size_t i = 0; i < this->LandProvincesReachableThroughWater.size(); ++i) { + CGrandStrategyProvince *border_province = this->LandProvincesReachableThroughWater[i]; + if (this->HasBuildingClass("dock") == false || border_province->HasBuildingClass("dock") == false) { + continue; + } + if (border_province->HasModifier(modifier)) { + return true; + } + } + + return false; +} + bool CGrandStrategyProvince::HasFactionClaim(int civilization_id, int faction_id) { for (size_t i = 0; i < this->Claims.size(); ++i) { @@ -5377,6 +5403,8 @@ CGrandStrategyEvent::~CGrandStrategyEvent() void CGrandStrategyEvent::Trigger(CGrandStrategyFaction *faction) { +// fprintf(stderr, "Triggering event \"%s\" for faction %s.\n", this->Name.c_str(), PlayerRaces.Factions[faction->Civilization][faction->Faction]->Name.c_str()); + CclCommand("EventFaction = GetFactionFromName(\"" + PlayerRaces.Factions[faction->Civilization][faction->Faction]->Name + "\");"); CclCommand("GrandStrategyEvent(EventFaction, \"" + this->Name + "\");"); CclCommand("EventFaction = nil;"); @@ -5390,6 +5418,8 @@ void CGrandStrategyEvent::Trigger(CGrandStrategyFaction *faction) bool CGrandStrategyEvent::CanTrigger(CGrandStrategyFaction *faction) { +// fprintf(stderr, "Checking for triggers for event \"%s\" for faction %s.\n", this->Name.c_str(), PlayerRaces.Factions[faction->Civilization][faction->Faction]->Name.c_str()); + if (this->MinYear && GrandStrategyYear < this->MinYear) { return false; } @@ -5737,7 +5767,7 @@ void SetWorldMapTileRiver(int x, int y, std::string direction_name, std::string int river_id = GetRiverId(river_name); - return; //deactivate this for now, while there aren't proper graphics for the rivers +// return; //deactivate this for now, while there aren't proper graphics for the rivers if (direction_name == "north") { GrandStrategyGame.WorldMapTiles[x][y]->River[North] = river_id; @@ -5826,7 +5856,7 @@ void SetWorldMapTileRiverhead(int x, int y, std::string direction_name, std::str int river_id = GetRiverId(river_name); - return; //deactivate this for now, while there aren't proper graphics for the rivers +// return; //deactivate this for now, while there aren't proper graphics for the rivers if (direction_name == "north") { GrandStrategyGame.WorldMapTiles[x][y]->River[North] = river_id; diff --git a/src/stratagus/script_grand_strategy.cpp b/src/stratagus/script_grand_strategy.cpp index a774aad03..796fe4781 100644 --- a/src/stratagus/script_grand_strategy.cpp +++ b/src/stratagus/script_grand_strategy.cpp @@ -235,6 +235,16 @@ static int CclGetGrandStrategyProvinceData(lua_State *l) lua_rawseti(l, -2, i); } return 1; + } else if (!strcmp(data, "BordersModifier")) { + LuaCheckArgs(l, 3); + + CUpgrade *modifier = CUpgrade::Get(LuaToString(l, 3)); + if (modifier == NULL) { + LuaError(l, "Modifier doesn't exist."); + } + + lua_pushboolean(l, province->BordersModifier(modifier)); + return 1; } else if (!strcmp(data, "Governor")) { if (province->Governor != NULL) { lua_pushstring(l, province->Governor->GetFullName().c_str());