Create a new unit c++ code

Duke176

Warlord
Joined
Oct 19, 2006
Messages
241
Location
Turin - Italy
Hello,
does anyone have idea about which is the code that makes the city producing a unit or the code that makes the transport "produce" the units that are unloaded when you unload them.

In the end which is the code to set a botton for unit to produce a new unit?
Or something similar to modify for my uses?

Thx.
 
Kael uses this for FfH:

Code:
					newUnit = bPlayer.initUnit(gc.getInfoTypeForString('UNIT_ORTHUS'), pUnit.getX(), pUnit.getY(), UnitAITypes.NO_UNITAI)

It's python and not c++, so I'm not sure if that's what you want...
 
I will try. Thx.

I'm not so experienced in changing code of C++ and Python, so I'm sorry If could be not so much clear.

What I was looking for is the part of the code that effectively create the object (that's why I was looking for Workers code or city code). I dunno if it's python or c++ code so any help is welcome.

Err... a question: if I modify the phython code I should compile c++ files? (I ask this becuase I know some c++ files recall some phyton files.

I found that a row of c++ cvunit.cpp call for function "trainUnit" and I thought this could be the one I'm looking for.

More than this the resoult I want to reach is to create a "button" appliable to a unit that let it create a new unit in spite of for ex. steal plans or build roads.

Lemme know if I haven't been clear.
 
What I quoted is a python command that executes the initUnit function (which is a c++ function). As long as you only use initUnit within python files and don't modify the function itself, you don't need to recompile the SDK. In fact, you can even modify python files while the game is running and it (usually) won't break.

Creating a unit in python is actually very simple (just look at some examples in the Fall from Heaven CvEventManager); creating a button is much harder. You might want to use someone else's work here, namely talchas' action button.
 
so to continue on the same logic, do you think this idea could go well?

here it is:

1) find initUnit function and how does it work
2) get all files necessary to create a "new mission" (so colled functions activated by clicking a botton in actions list ingame ex. steal plans) = already done and got working
3) change the function that I call inside cvunit.cpp with the initUnit function as needed modified

Game done.
Correct?
 
Why would you want to modify the initUnit function? You'd probably break the game if you did. All you need to do is execute the function with the right parameters.
 
yes sorry, missunderstanding.
I meant make a copy of InitUnit change it, rename it and make it working simplified.
It would be quite simple (If I only had studied programming at the University :D) becuase this function will have some standard parameters like the kind unit can be created...
 
Back
Top Bottom