Getting object Plot(x,y) ? additional question: UnitClass ?

mrtobacco

Chieftain
Joined
Mar 13, 2007
Messages
2
First of all, hello folks.

I´m new into modding civ4 so please be patient ;-) (also english isn´t my native language so forgive any grammar mistakes i make)

Downloaded stuff:
- SDK
- Python25

What i´m looking for is some function to get a plot (with fixed coordinates evaluated from the current active unit). Anyone got an idea ?

I guess i could make that plot give out all "information" about the units on it with CyPlot.getUnit(int iIndex) (index will be generated to cycle through all the units on the given plot). Perhaps someone could explain how the data of a civ game is arranged while playing. Are the Plots arranged in some mysthic multidimensional array ? Just the basics and in which .cpp file i can find the functions/declarations.

My next problem is:
CyUnit.getUnitClassType()
it returns an int value BUT in every xml file i browsed the UnitClassType is a string ? Are there some files where alphanumeric UnitClassTypes are related
to nummeric UnitClassType(-keys ?) ?
(In the next part remember i am new to python ;-)) In the documentation for python i read something like "Python converts the type of an value the way python needs it" - is this the answer ? Can i feed my script with an integer variable and compare it with a string ?

Would be great if someone could help me with this, i am bored of "Barbarian Kings" which are doing a walk in the park alone, while her minions are crawling right besides them. They should gather their forces and smash any unprepared players face ;-)

greetings
:smoke:mrtobacco:smoke:
 
First of all, hello folks.

I´m new into modding civ4 so please be patient ;-) (also english isn´t my native language so forgive any grammar mistakes i make)

Downloaded stuff:
- SDK
- Python25

What i´m looking for is some function to get a plot (with fixed coordinates evaluated from the current active unit). Anyone got an idea ?

I guess i could make that plot give out all "information" about the units on it with CyPlot.getUnit(int iIndex) (index will be generated to cycle through all the units on the given plot). Perhaps someone could explain how the data of a civ game is arranged while playing. Are the Plots arranged in some mysthic multidimensional array ? Just the basics and in which .cpp file i can find the functions/declarations.

My next problem is:
CyUnit.getUnitClassType()
it returns an int value BUT in every xml file i browsed the UnitClassType is a string ? Are there some files where alphanumeric UnitClassTypes are related
to nummeric UnitClassType(-keys ?) ?
(In the next part remember i am new to python ;-)) In the documentation for python i read something like "Python converts the type of an value the way python needs it" - is this the answer ? Can i feed my script with an integer variable and compare it with a string ?

Would be great if someone could help me with this, i am bored of "Barbarian Kings" which are doing a walk in the park alone, while her minions are crawling right besides them. They should gather their forces and smash any unprepared players face ;-)

greetings
:smoke:mrtobacco:smoke:

if you want int value related to text key (not only for unit class, but for other types too), you can use function CyGlobalContext().getInfoTypeForString("text") (mostly called as gc.getInfoTypeForString("text"), where gc = CyGlobaContext() )
example:
gc.getInfoTypeForString("UNITCLASS_WORKER") will return integer, which correspond to UNITCLASS_WORKER; in reality it is position for this UNITCLASS in CIV4UnitClassInfos.xml

regarding "Python converts the type of an value the way python needs it" - this is mean, that you don't need to explicitly specify variable type, or you don't need to explicitly convert integer to float etc... so you can't use this to "convert" this string to integer

plot functions: mostly all in-game objects can be represented in two ways:
one is integer ID (mostly named in python scripts as iPlayer or iPlot etc...) and second is pointer to C++ class in memory /instance/ (mostly named as pPlayer or pPlot etc..)

so if you have plot instance (pPlot), you can get number of of all units on plot as iNum = pPlot.getNumUnits() /iNum is your variable/
then you can get instance for each unit as pUnit = pPlot.getUnit(ID), where ID can be from 0 to (iNum-1)

python API is described in http://civilization4.net/files/modding/PythonAPI/ you can download this to your PC for off-line use
I suggest you start study this document and some simple scripts
 
thx for the input ! the part about the unitclasses was exactly what i were looking for !

About the Plot: how can i call the plot with the coordinates x,y ? Or otherwise, how to convert the x,y coordinates into the plotid ?


AND 1000 THX FOR THE API DOCUMENTATION !
 
Do this to set pPlot as a specific plot:

Code:
pPlot = CyMap().plot(x,y)

After this constant is defined, you can merely call the function

Code:
pPlot.getNumUnits()
(Mexico's example)

and Python will read it as

Code:
CyMap().plot(x,y).getNumUnits()
 
Top Bottom