[SDK MODCOMP] Unit Fuel Mod (includes Global Fuel)

Grey Fox

Master of Points
Joined
Dec 19, 2001
Messages
8,726
Location
Sweden
Unit Fuel Mod
By: Grey Fox

Version: 1.1 - Last Updated 04/08/2008
Patch Compatibility: BTS v3.13
Download Mod v1.1
NOTICE: This mod is not intended as a standalone mod, but as a system for other mods to incorporate into theirs and to further modify it to their wishes. But example changes have been made and a new building have been added, so it can be played as a mod. I will hopefully add more features to this mod in the future, but as I do not have an internet connection at home, the updates can be sporadic.​
Spoiler Interface :

What Is the Unit Fuel Mod?
This mod adds the attribute iFuel to units. If you set the attribute to above 0 the unit will require fuel to move and operate. If a land unit runs out of fuel it can't move. If a sea unit runs out of fuel it will sink. I chose not to add any fuel value for Air units in this example mod, since they are always situated in a location where they would be refueled.
But if you want to use the Global Fuel part of this mod giving Air units fuel might be a good idea.
(Currently only Gunships require fuel).

This mod consists of two parts. The Unit Fuel attribute, and the Global Fuel attribute which is a Player attribute and just like Gold tells you how much money you have. The player's Fuel determines how much fuel your units have access to.

Example with Global Fuel activated:
- if your civilization has 60 Fuel and a fuel income of 100 per turn, you can't build a destroyer which requires 300 Fuel
- if a tank that has been out in the field comes to a city to refuel and you have a total of 1400 Fuel, and your Tank has 35 Fuel, the next turn (you need to rest the unit in the city one turn to refuel) your total fuel will be 1365 (+any fuel income).

New Global Defines have been added to enable/disable the two systems:
- FUEL_SYSTEM_ACTIVE to enable or disable the entire mod
- GLOBAL_FUEL_SYSTEM_ACTIVE to enable or disable the Global Fuel system

There are also Global Defines to control fuel spending.

NEW!(v.1.1)
Fuel income is now determined in the Civ4BonusInfos.xml, this means that multiple types of bonuses can now give fuel.

On the main interface, next to the Gold display, you can see how much fuel your civilization has atm. As well as your fuel income per turn.

XML (All New Tags Are Optional)

Spoiler :

All changes marked with:
<!-- UnitFuel: Added by GreyFox xx/xx/200x -->
(where xx/xx/200x is the date, it should be 03/28/2008 on all currently)
<!-- UnitFuel: End Add ->

CIV4UnitInfos.xml
- iFuel

CIV4PromotionInfos.xml
- bUnlimitedFuel

CIV4BuildingInfos.xml
- iGlobalFuelModifier

NEW!(v.1.1)
CIV4BonusInfos.xml
- iFuelPerTurn

Supplied with the mod is two modules;
- FuelUnits: Tank, Modern Armor, etc with fuel attribute
- Refinery: A new example building to test the iGlobalFuelModifier


Python
Spoiler :

All changes marked with:
# UnitFuel: Added by Grey Fox
# UnitFUel: End Add

MainInterface.py
- To display fuel on units and for the player.
CvUnitFuelEvents.py (custom event manager)
- onUnitBuilt(): To set promotions on build
CvUnitFuelUtils.py
- doFuel(): Used to update how much fuel you get from various sources
You can use this to override the SDK function run every turn
- cannotTrain(): Guess what this does


SDK (following methods exposed to python)
Spoiler :

The Changed SDK Files have been supplied with the mod in the
"Changed SDK Files"-folder located in the root folder of the mod.

All changes in the SDK marked with:
//UnitFuel: Added by Grey Fox xx/xx/200x (filename.cpp/h)
//UnitFuel: End Add

Functions exposed to python:

CyUnitInfo
- int getFuel()

CyPromotionInfo
- bool isUnlimitedFuel()

CyBuildingInfo
-int getTileSpaceChange()

CyCultureLevelInfo
-int getTileSpaceChange()

CyUnit
- int getFuel()
- int getFuelLeft()
- void setFuel(int iNewValue)
- void changeFuel(int iChange)
- void setFuelLeft(int iNewValue)
- void changeFuelLeft(int iChange)
- bool isUnlimitedFuel()

CyPlayer
- int getFuel()
- int getFuelPerTurn()
- void setFuel(int iNewValue)
- void changeFuel(int iChange)

"Terms" of Use:
All I ask if you do use this mod, is the following:
• Give credit where credit is due (to the author).

• Let me know personally of any major enhancements you may give to this mod (I promise to give you credit if I use it/them in future versions!)​
Credits and Thanks
Programmed by GreyFox
Includes graphics made by Sevo.

Spoiler Changelog :

----------------
Version 1.1
----------------

Fixes:
- Fixed a bug where units who started with 0 fuel couldn't move.
- Added CvEnums.h in the Changed SDK Folder. Sorry for forgetting that last version.

Additions
- Added iFuelPerTurn to Civ4BonusInfos.xml
- Added the FUEL_RESTORED_IN_CITIES Define, which defines whether or not fuel should be restored to units in cities.

Removed
- The Defines that determined what Bonus gave Fuel and how much it gave.
This is now done through Civ4BonusInfos instead.
 

Attachments

  • UnitFuel_Interface.jpg
    UnitFuel_Interface.jpg
    367.4 KB · Views: 3,459
Seems interesting, and useful for World War mods.

I know Gaius Octavius was working on something along these lines.

Good work, nonetheless :)
 
Bravo, Grey Fox, this will make it much easier for me to generalize for Quantified Resources. :goodjob:

I must admit I'm not too crazy about the ships sinking or the need to move into a city to get refueled, but that shouldn't be too hard to change. ;) You've undoubtedly simplified my work by a factor of ten. :thumbsup:

Quick question: is the cannot train portion of it handled exclusively in SDK, or did you invoke the Python check? (Might be an issue on big maps as far as slowdown goes.)
 
I used the python cannotTrain for simplicity, (simpler to remove and change for the user of the mod) but it can easily be moved to the SDK.

Yeah the ships sinking is easily removed. The need for a city to refuel is a one-line change. You could change it so that the unit needs to be in your territory, or whatever. Maybe write a function to check how far from home the unit is etc.
 
Yeah, I was even thinking about combining this with a dynamic supply line, so that naval units have specific ranges beyond which they cannot travel without starting to lose supplies. There's lots of possibilities here. :)
 
one quastion, does the ai will know how to manipulate this feature? is it aware not to spend all of his fual and avoid reaching zeor fual?

I would think a more important feature would be to train the AI to seek as much fuel as possible, so that it tries to avoid getting down to zero, if possible. I guess that's essentially what you were saying. :)
 
No worries, it may not even be an issue. :)

I nominate this mod for discussion in the next Apolyton ModCast. :D

I think it will be an issue. The AI will not understand that it's running low on fuel and has to "rebase" in order to resupply. Even if you implement code when the unit is running low on fuel that it should make its way back to the nearest city when it reaches a certain fuel level, the AI still will not have the human understanding that it might not need to refuel because it's on a suicide mission or may conquer an enemy city and rebase there instead.


But, this mod is better than I thought on my initial first glance. I love what you've done with the interface: it looks great!

Very nice job :goodjob:
 
I think it will be an issue. The AI will not understand that it's running low on fuel and has to "rebase" in order to resupply. Even if you implement code when the unit is running low on fuel that it should make its way back to the nearest city when it reaches a certain fuel level, the AI still will not have the human understanding that it might not need to refuel because it's on a suicide mission or may conquer an enemy city and rebase there instead.
:

i agree,

this mod is crucial to ai use, they ai will max out his fual, and wouldnt know how to raise the amount of fual.

also ships will surly sink.

i love this mod idea it gives a whole different strategy tactics,
indeed i would rather wait until some upadatewill be made to the ai prior i integrate this modcomp to my overlord2,

another suggestion grey,

pehaps to aircrafts you can come up with some system that will make airmissions to "cost" fual? this will be some answer to the fual with aircrafts :)

also,
does helicopters , counts as air? meaning can the current version can be applied to heli's aswell?


i will watch closely on this thread , it gives a suitble answer to everyone who talked about quantetive resuorse system ...

keep up the develomment and this great promissing addition.

***edit***

oh two more thing, i think it would be proper to create a refuling unit, some unit that can affect fueled units and refill them, maybe in a system , with a small area of effect, say like you have a tank needs refueling, you fortify or make it rest in the vacinity of the refueling unit .

second,
i would also suggest,
making fuel , tradble between nations, fuel agreements and such - wow so much possibilities with this mod :)
 
Helicopters are land units so they function as tanks would. (And don't crash if they run out of fuel, helicopters can land ya know)

If anyone want to give the AI update of this mod a stab, be my guest. I will probably not be able to update this for a while since I don't have a internet connection at home.
 
ye heli's can land hehe...sometimes..

well, ill integate this mod comp today into overlord2, then release it to the public,
and then ill report you hows the ai doing :).

well, if you dont hvae int at home,
im sending you a box through the post, return it to me in a disc, dont worry , the stamps on me.
 
This is an extremely interesting mod. Thanks for the work, Grey Fox! :goodjob:
 
Oh yeah, I forgot to mention. This mod is built on top of Bhruic's Unofficial patch.
 
I think it will be an issue. The AI will not understand that it's running low on fuel and has to "rebase" in order to resupply.

i agree,
this mod is crucial to ai use, they ai will max out his fual, and wouldnt know how to raise the amount of fual.

Which is why I would suggest removing the rebase micromanagement altogether... :D

Here's a related question: can you tie the AI thinking into resources directly? What I mean is, how does the AI judge the value of specific resources, such as oil? Does it assign an intrinsic value, or does it judge it based on the number of units currently available (by tech) that need oil in order to be trained? What I'm thinking is, if it's just a flat intrinsic value, then you could increase that value and make fuel directly proportional to the number of oil resources a player has. This way, the AI will be less likely to run out, because it would already be seeking new supplies by default.
 
Removing the need for units to return to cities to refuel would make it a whole lot easier, yeah.

Anyways, I will be AWOL awhile again now. So I see ya all when I see ya. Hopefully with updates from both sides! :)
 
If you remove the need to return to cities to refuel, can u keep that version up for those of us who would like it. Also, is the fuel based on a resource like oil?
 
Top Bottom