Civil_War, add condition

globosud

Warlord
Joined
Jul 7, 2017
Messages
109
I wanted to know if anyone could tell me how to add a condition to the CivilWar script
, such as the city must be on another continent, and it must have this resource.
here for example, when compared to the downloadable file, two have been added, again by the author of the script.
thanks
 

Attachments

  • Screenshot 2024-02-12 121439.jpg
    Screenshot 2024-02-12 121439.jpg
    84.2 KB · Views: 11
It seems that you've already found the proper place for your conditions. So I guess the remaining question is how to express them in Python code – which depends on the specific conditions. To check whether the rebellious city is on a different landmass than the capital, this would probably work (not tested):
Code:
if pCity.getArea() == player.getCapitalCity().getArea():
    return False
getCapitalCity can return None when the player in question has no capital (Babrbarians or no city founded yet), so one should generally check is None before calling methods of the capital city object. However, in this case, there's already a getNumCities check (and the existence of pCity also already demonstrates that there is at least one city), and events don't trigger for the Barbarians, so this should be fine.
For the available bonus resource:
Code:
if not pCity.hasBonus(gc.getInfoTypeForString("BONUS_IRON")):
    return False
This check will include resources available through the trade network. If the resource needs to be in the workable radius of the city, a loop over the nearby plots will be needed. Such conditions mostly use the DLL-to-Python interface defined by the Cy... files in the CvGameCoreDLL source folder. But those are not documented and aren't always intuitively named; e.g. "area" and "bonus" are somewhat unexpected terms for a player.
 
first of all thank you - what I would like from this event is that the first city that the Spaniards create on the American continent, by connecting the event to a technology, becomes American, so let's say I want only the cities on the American continent to suffer the effects of the event. An excellent way would be to know before it happens the name of the city that would create Spain on another continent, so as to connect the event to a specific name of the city.
 
it gives me an error., I put the error with the script in the link
 

Attachments

  • Screenshot 2024-02-13 231258.png
    Screenshot 2024-02-13 231258.png
    38.3 KB · Views: 5
  • Screenshot 2024-02-13 231028.png
    Screenshot 2024-02-13 231028.png
    333.6 KB · Views: 6
Oh, I see. I've checked in CyCity.h. It's named area instead of getArea. (Both exist in the DLL, but only the former is exposed to Python.) The city name will be whichever is next in the Spanish city list, I suppose. So I don't think the name will tell us anything about where the city is located. Maybe you could just check whether the x-coordinate pCity.getX() is small enough, i.e. far enough west. As for technology, if it's sufficient to check for that by the time that the event triggers, then
Code:
gc.getTeam(player.getTeam()).isHasTech(gc.getInfoTypeForString("TECH_GUNPOWDER"))
should work. (Techs are handled at the level of teams. player.getTeam() provides the team ID, the "global context" gc provides the respective team object. Naming a function "isHasTech" is poor style and inconsistent with e.g. "hasBonus" mentioned previously – but that's how Firaxis named those functions.)
 
so it will be like this?
if pCity.Area() == player.getCapitalCity().Area():
return False

I tried that too, it doesn't work
if pCity.area() == player.getCapitalCity().area():
return False
 
Last edited:
With a small "a". Doesn't work - meaning no exception (popup), but not the correct result? I guess it should be
Code:
if pCity.area().getID() == player.getCapitalCity().area().getID():
    return False
Those C-based Python objects (such as areas) probably shouldn't be tested for equality directly. Sorry, someone with more experience in Python could answer these questions more competently. I've only been using Python for the user interface, always C++ for the game logic.
 
Top Bottom