[SDK MODCOMP] Dynamic Unique Units

Dom Pedro II

Modder For Life
Joined
Apr 3, 2002
Messages
6,811
Location
Exit 16, New Jersey
Dynamic Unique Units for Beyond the Sword

The File: Dynamic Unique Units

What it does: This mod allows you the ability to set unique units for different players. Without getting too technical, rather than drawing the player's unique units from the XML, it's now done internally from within the SDK, so you can add and remove them as you please.

New XML Tags

CIV4TechInfos.xml

<FirstUnlockUnit> - This assigns a Unique Unit to be assigned to the first player to research this tech. If the player already has a unique unit in this unit class, it will pass over this player and assign it to the next player to research (or be gifted) this tech. See below for further moddable restrictions...

CIV4BuildingInfos.xml

<UnlockUnit> - This assigns a Unique Unit to be assigned when a player builds a Wonder. If the player already has a unique unit in this unit class, the unit will not be assigned to this player. Players who conquer other players with Wonders that give UUs will get the UUs for themselves. See below for further possible restrictions...

CIV4EventInfos.xml

<UnlockUnit> - This assigns a UU to a player when a particular event occurs. Works just the same as any other event feature. Like the others, if the player already has a unique unit in this unit class slot, the player will not get the unit.

Global Defines

MAX_ASSIGNED_UNIQUE_UNITS - This sets a limit on how many unique units a player can have per game. This value is the most important of the global defines. A value of -1 means unlimited UUs for all players. A value of 0 means no UUs for any player. Once a player has reached the maximum number of UUs, later techs or buildings that unlock UUs will not give anything if you research or build them.

NOTE: The techs give UUs to the first to discover them. If you have a limit on the number of unique units per player, then it's not considered to be "the first" and the next player with a free unique unit slot will get the unit. (This has no effect on any other "first to discover receives" items the tech might give). If there are more than one player on a team, the game will try to assign a unique unit to the discoverer of the tech. If the discoverer is inelligible, it will try with the other teammates.

UPDATE_UNITS_ON_UU_ASSIGNMENT - This causes the game to automatically update all of your default units from the UU unit class (if you have any) to unique units when you unlock a new UU.

LIMIT_UU_WONDER_CONSTRUCTION - This causes you to be unable to train a Wonder that gives a unique unit if you have already reached your maximum number of UUs as defined in the first global definition.


Python

The functions getUniqueUnits(UnitClassTypes eIndex) and setUniqueUnits(UnitClassTypes eIndex, int iUnit) have been exposed to python to allow players to set their own conditions for adding and removing UUs.

Demo: The demo mod included in the zip file removes the unique units for all civilizations and instead makes them acquireable through technologies (and one through a Wonder). I couldn't find tech spaces for all of the units, and it's a little silly to have the Aztecs fighting with Numidian Cavalry, but hey... you go to war with the unique units you've got and not the unique units you wish you had. It's just a proof of concept mod.


From this picture, you can see that we start the game with a regular default warrior. The Quechua has set to be unlocked with the discovery of Meditation.




This is after I've discovered Meditation.



Possible Applications:

I don't like to tell people what to do or not to do with my modcomps, but here's some suggestions that have occurred to me as I was designing this... You could remove all the Civilization Units and instead have 34 non-civ specific UUs or whatever the maximum number of possible players would be in any given game.

You could have a couple of free UUs given for the first person to research techs or get a Wonder. For example, you could create a wonder called Lockheed Skunk Works that would replace the regular Jet Fighter with the F-117. Or make the B-2 a unique unit and give it to the first player to research stealth and some other default stealth bomber for everybody else.

Lots of possibilities even for those who don't want to totally revamp the system but would just like to add a little spice to existing techs, buildings, and events.

Someone good with python could also add UUs that would be assigned when a player gets a particular Resource, adopts a certain Civic, or converts to a particular Religion. You could also have players capture the UUs of other civs when they've conquered them.



Also... if this turns out to be popular (and I hope it does), I'll do the same thing for Unique Buildings.
 
Very cool and original mod Dom, I personally think the Wonder linked Unique Units are the funnest possibility especially for late game High tech Wonders as you pointed out, I can for see Area 51 and LosAlamos Labratories as wonders that could use this system, it looks a lot cleaner implementation of what I've seen done with a wonder providing a resources required for a unit that cant be found any other way or other python based efforts to get Wonders to give exclusive access to a unit.
 
Yes, although this does nothing for you if you want access to a new unit class. So if you wanted to have it so that you had the F-117 in addition to the Jet Fighter, for example, it would be better to add a new tag to the CIV4UnitInfos.xml that would require only that the player own one of a particular building anywhere in the empire to be able to train the unit.. sort of a GlobalBuildingPrereq.

But there are ways to use this one to do effectively the same thing... make it so you can't build the default, and then you award the UU to the player who builds the wonder.
 
Nice. I had a similar system being built around the secret tech modcomp. This does it much, much better. Thanks for the work, Dom. It's much appreciated.
 
I'm thinking about making a slight change in the code so that if you set a globally defined value to true, cities will add to its list the UUs of the highest culture player in the city, so this could potentially allow conquerors to inherit the UUs of their enemies (only in conquered cities naturally).

The only problem I can see is that since these values aren't stored city by city but would rather be just drawn from the player values, you might actually end up with a weird instance (in some games) where an already conquered city will be able to build the unique unit of their original civ eventhough it was captured before the original civ gained the tech to be able to build that unit.
 
wow!

for some reason i didnt encountered this modpack before!

its so awesome and so very original,

it give so much applications to be made, i dunno where to begin!


say dom,

using this modcomp,

say i take off all uus written in the xml,

and work the uus to be given with the techs,

will it speed up the game? cause i know the more stuff goes through the sdk, the faster the game is...
 
wow!

for some reason i didnt encountered this modpack before!

its so awesome and so very original,

it give so much applications to be made, i dunno where to begin!


say dom,

using this modcomp,

say i take off all uus written in the xml,

and work the uus to be given with the techs,

will it speed up the game? cause i know the more stuff goes through the sdk, the faster the game is...
No because you'd still have to load them from the XML from the tech info. In fact, everything from the XML is loaded into the program at start up. So it's not like python where it's pulling this information at runtime. When people talk about running it through the SDK, what they really mean is as opposed to doing a particular action in python which is much, much slower.

The main purpose of this particular mod came from someone who wanted to make it so that instead of every civ getting the same UUs every game, you could make it based on techs to make it so that a player could earn their UU essentially.

I'm planning on extending this to Traits, Civics and Religion. The reason I want it for Traits is because in my mod, I'm planning on making it so that when you found your first city, the game takes an appraisal of the tiles around your city and assigns you a trait based on the type of terrain, and then you'll have special bonuses for those terrains. I may want to include some terrain-specific UUs that will replace normal units.

As for the civics and the religion, I don't see them being terribly useful in a normal game, however, for fantasy mods, these could be really great. Let's say you have several religions in a fantasy mod that correspond to different elements like Earth, Wind, Fire and Water. You could make it so that when you adopt that religion as your state religion, you'd get a whole set of UUs based on that element. So your swordsmen would get bright red uniforms with fiery swords if you converted to the Fire religion and blue uniforms and the ability to walk on water or something if you converted to the Water religion.

You could do something similar with Civics as well. Maybe some kind of Dark Magic/Light Magic choice or something. I don't know. I want to do a fantasy mod at some point, so this maybe something I use. The problem with Civics and Religions though is that you can flip from one to another fairly easily. So it will either A) have to become more difficult to switch between civics/religions, or B) the UUs will have to be toned down, which kind of takes the fun out of it.
 
hey,

nice set of ideas i must say,

the trait thing is really nice,
but, theres alot of traits and less terrain types, maybe adding something else then traits, say like you add a new tag to the civ regarding the terrain, like i dunno....call it a "skill" or somthing like that, like on desert terrain, you get the skill of surrvaival, or gathererer that give some food bonuses and such :)

keep up the good work.
 
hey,

nice set of ideas i must say,

the trait thing is really nice,
but, theres alot of traits and less terrain types, maybe adding something else then traits, say like you add a new tag to the civ regarding the terrain, like i dunno....call it a "skill" or somthing like that, like on desert terrain, you get the skill of surrvaival, or gathererer that give some food bonuses and such :)

keep up the good work.

Oh, well, using traits is just easier than creating a new game feature like "skills" to do essentially the same thing. Combine this with something like TheLopez's scriptable traits modcomp, and you can make it so that at the start of the game, you assign the civilization a new trait based on whatever criteria you want. You wouldn't necessarily need to do it just on terrain types though, you could base it on the number of water tiles, hills, or forests/jungles, even tile latitude.
This would allow you to create civs that could be specialized for deserts, jungles, arctic climate, or hilly terrain, or they could be specialized seafarers.
 
Seriously awesome Modcomp :) I fell in love with it at the title, and I think it just got worse when I read the description ;)


I've pretty much completely integrated it into Fall from Heaven 2 now. But I was wondering about one part in CvInfos:
bool CvTechInfo::readPass3()

What is the purpose of doing this exactly? Kael has created the function himself for a Religion Pre-Req, and placing yours inside of his worked as poorly as I expected, so right now I am compiling it as a readPass4 instead. But not knowing the reason for bumping the read to come after everthing else means I don't know if some heirarchy exists. Logic tells me that the numbering is completely irrelevant and the functions are run when they are called, so what they are called doesn't matter, so long as it is consistent.

I did manage to compile it with the pass being 4 instead of 3, but right now my test Technology doesn't display properly that it Unlocks a new unit :( And then when I attempted to go in-game to test if it worked anyway I got a crash. Still working on precisely what caused that one.

Also wanted to note that while you included an Event folder in the XML, it appears nothing was changed. I added the new field to the schema myself, but haven't had time to play with it as yet to see if it is fully functional.

EDIT:

I understand now that the Pass 3 information is being stored in an array to be handled later when other information to which you are referring has already been loaded. So to combine the two I am just using the Pass 3 array, but shifting the other one to read index 1 instead of index 0. Hopefully it will work.

Also noticed that the CVPlayerAI.cpp contained a portion of the code for your Conquest mod. Since it is only partial it gives some errors if not removed obviously.

EDIT 2: It works for the most part now. The only remaining bug is that when a new unit is unlocked it is not showing up as buildable, and neither is the base unit it was formed off of. However... all currently existing units are being updated properly to the new unit. So it is assigning the new Unique Unit to the Player, but for some reason it seems that the CanTrain function is failing.

EDIT 3: Got it all working now. In the CvPlayer.cpp ::canTrain function, I removed the change which you made for the Assert and then UniqueUnit = eUnit check. Instead I placed a definition to force eUnit = UniqueUnit. This got it to start looking at the Unique Unit's Build requirements instead of the Base Unit.

Nice thing about having it work this way of course is that you can create a new Unitclass which has an unbuildable base unit. Then you create a Unique Unit version which IS buildable, and when someone unlocks that unique unit it actually just grants them a completely new unit which is exclusive to their Civilization.
 
I'm glad you got it working :) and I'm certainly glad you enjoy it.

I'm considering a future edition where it will be possible to have UU's for individual cities... this could be cool because it will allow you to conquer your enemies and then continue to build their UU's in those conquered cities. This would be similar to how many large empires raised special forces from among their subject territories.

I've been pretty busy though, so I haven't given this a lot of attention... it'll be a little bit tricky because you have to make sure that everything works together and that you don't have cases where it's overwriting UU's in some cities that should be kept.

I'm also not sure if I want it because I'd hate to add bloat to the program for something that's a relatively minor addition. Balancing would also be an issue because players who conquer several cities from their enemies might get a really powerful (and potentially unstoppable) combination of UU's. I should certainly just do it at some point though because maybe somebody out there has an idea for a mod where this would be an integral component.
 
Dom Pedro, would it be possible to set this modcomp so that upon discovery of a tech several unit types are automatically upgraded to a new unit? And can several techs be set to upgrade the same (older) unit to a new unit?
Also, can it be set that not only the first civ to discover such a tech will see its units upgraded, but all civs when they get that tech?
 
All respect your Majesty!

But I couldn't manage to make this mod worth. It simply doesn't produce any effect in game (BtS 3.13). Are there any special procedure to install it properly?
 
This is a smart idea. I like the flavor unique units add to the game, and randomization helps spice things up even more, especially the event-driven capabilities you've added.
 
Does this work with BTS 3.17?

Also are the tags required in the schema? So will I have to go and add it to every tech or only the ones I want to unlock units.

Thanks for a great idea for a mod.

-J
 
Top Bottom