OIL vs MOVE

I will check it tomorrow, perhaps. I am very intrigued by the possibility of this working. :)

Good idea you had about the air units, and it kind of makes sense - suppose you suddenly got oil halfway through your turn. Well, it would be understandable that you couldn't use planes immediately, now wouldn't it? It'd take time to distribute that to all your airfields.
 
If the source code is available you should be able to adapt it to the current version of BTS.

By the way, I'm posting because I really like your signature: "The Pope? How many divisions has he got?" -Joseph Stalin.

Do you have a source for that?

I dont actually know much about SDK myself. I once ventured into that territory and almost put a golf club through my monitor :mad:

Hopefully someone who is keen on porting the code to BTS and creating a new DLL is welcome...but of course Duke would have to give permission ;)

The quote from Stalin has been around in various forms for a while. Of course with every quote that comes from Stalin, there is around 5 variants of the translation.

As for the context of the quote, I am not sure when he said it...but it cracked me up when I first read it....typical Stalin arrogance :lol:
 
Testing Results

The code works, and what's more, it does affect air units, but not wholly. When I got rid of the oil supply all modern naval units were immobilized, from the transport to the battleship. All land units that are mechanized - tanks, artillery (mobile and regular) and whatnot - also could not move. Funny thing though, mechanized infantry apparently is not classified as mechanized in the game, because it could still move! So could gunships and mobile SAMs. :crazyeye:

Now to the air units: no plane could conduct an aggressive action without oil, nor could they rebase to another city. They were basically frozen where they were. They could undertake recon missions, however, and fighters could still execute their air superiority missions even without oil. Finally, even airships, cruise missiles and tactical nukes could not move.

So it is a very good partial solution. The main thing that bothers me is that air units can still perform interception missions, which we'll have to change. Ironclads were also affected by the oil shortage, despite the fact that they are coal-fired. :lol: (I suppose this is irrelevant for those of you who want this for WW2 scenarios, though.)

In summary, the game basically does what it is supposed to, and with a little tweaking in XML for units like the mech infantry and gunship, I'm sure we could get those issues fixed. However, the air missions still need to be addressed, probably by forcing them to skip their turns until fuel supplies are restored.

EDIT: One other thing: I said that tactical nukes could not move when you have no oil (i.e. relocate to another city), but they are still able to nuke the enemy. This is good, because ICBMs and nukes would not be affected by an oil shortage, since they presumably have their own supplies stored with them for a one-way mission.
 
Now I tested this out with my quantified system and it was terrible. The thing slowed down so much it was impossible to move any unit to a distant area, let alone a stack of units. I was afraid this would happen, and I'm sure it's because of pickle.

I would love to have something like Duke176's oil counter, but I can't do any real programming in SDK and that's the only way to make it go faster. :( I wish Zebra 9 had his SDK version of QR out already, then maybe we could go from there. As it stands, Python is just too cumbersome for it.

Jeckel's code did slow things down noticeably, but I think it's still pretty much bearable given the gameplay value of it. Anything more complicated than that would simply be too much.
 
Quantative resources would be cool if it could be used properly... say each oil resource you own puts-out 20 units a turn or something... each unit that requires oil takes 1 unit to move per-turn... so if you have one oil source and 20 units, they could each move every turn... if you had 30 units that require oil, and only 1 oil source, you'd lose the ability to move 10 of your oil units a turn... of course if you owned TWO oil sources, then you'd have 40 units of oil per turn (could move 30 oil units and pocket 10 oil points a turn)...

Well... something like that... now I'm giving myself a headache... that's probably why it's not in the game.

Computer automation is a wonderful thing though... the computer could do all the math for you.
 
I agree completely - keep up work on this!!! A mod that does this would be awesome - dare I say you should expand it to other reasources though? Yes oil is important, but only since the late 1920s/1930s - before that everything was Iron and Coal. Perhaps every strategic resource should have it's own counter?
 
Snafusmith, if you'd like to do that, then I'd bet you're buying a one-way ticket to lag-central, :lol:
 
I also noticed that mech infantry arn't considered mechanized. I am chalking this up to an xml typo on firaxis's part. Because of all the various glitches in this method I was thinking it might be better to check the units required bonuses and if none of those are avaliable then can't build the unit. I'll whip up an example code after I eat lunch and post in a few other threads.
 
Quantative resources would be cool if it could be used properly... say each oil resource you own puts-out 20 units a turn or something... each unit that requires oil takes 1 unit to move per-turn... so if you have one oil source and 20 units, they could each move every turn... if you had 30 units that require oil, and only 1 oil source, you'd lose the ability to move 10 of your oil units a turn... of course if you owned TWO oil sources, then you'd have 40 units of oil per turn (could move 30 oil units and pocket 10 oil points a turn)...

Well... something like that... now I'm giving myself a headache... that's probably why it's not in the game.

Computer automation is a wonderful thing though... the computer could do all the math for you.

I did this already. I have code that takes the number of oil deposits you have and adds a specific amount to a stockpile using simple arithmetic. 1 oil source might be 10 oil/turn, so 2 sources = 20/turn... Then I added a cost for mechanized unit moves, 1 oil per tile.

The result? When I tried to move a fleet of seven battleships across the world on a duel sized map, it took about a minute or two for the thing to calculate that! :lol: (And I have a pretty fast computer.)

My code is certainly not optimized, but it goes beyond that. Python is just not what we need here. We need SDK, but nobody seems willing to do a real quantified system in SDK, or else they're too busy and have been working on it for ages. Understandable, but it doesn't get us any closer to the solution. :(
 
I also noticed that mech infantry arn't considered mechanized. I am chalking this up to an xml typo on firaxis's part. Because of all the various glitches in this method I was thinking it might be better to check the units required bonuses and if none of those are avaliable then can't build the unit. I'll whip up an example code after I eat lunch and post in a few other threads.

Here is another way to do it.
Code:
	def unitCannotMoveInto(self,argsList):# getPrereqAndBonus() getPrereqOrBonuses(INT i)
		ePlayer = argsList[0]		
		iUnitId = argsList[1]
		iPlotX = argsList[2]
		iPlotY = argsList[3]
		pPlayer = gc.getPlayer(ePlayer)
		pUnit = pPlayer.getUnit(iUnitId)
		pUnitInfo = gc.getUnitInfo(pUnit.getUnitType())
		iAndBonus = pUnitInfo.getPrereqAndBonus()
		if (iAndBonus != -1):
                        if (pPlayer.getNumAvailableBonuses(iAndBonus) < 1):
                                return True
                iBonuses = 0
                for i in range(5):
                        iOrBonus = pUnitInfo.getPrereqOrBonuses(i)
                        if (iOrBonus == -1):
                                return False
                        if (pPlayer.getNumAvailableBonuses(iOrBonus) > 0):
                                return False
                return True

Units have an AndBonus requirment and 0 to many OrBonus requirments.
If it has no bonus reqs then it can move.
If it has an And req and the player doesn't have that bonus then no move.
If it has Or reqs and the player has any of those bonuses then can move.

This way will also require a bit of messing with unit xmls to get all units to play right, but this way has its advantages.
 
Units have an AndBonus requirment and 0 to many OrBonus requirments.
If it has no bonus reqs then it can move.
If it has an And req and the player doesn't have that bonus then no move.
If it has Or reqs and the player has any of those bonuses then can move.

This way will also require a bit of messing with unit xmls to get all units to play right, but this way has its advantages.

Although I don't understand anything about Python coding at all, it would seem that this could be the better approach. At least with the xml tag there's no question what units are affected. Hopefully this will also work with aircraft.

Rather than blocking moves 100% for the affected units, wouldn't it make more sense to give a % chance that a given unit won't move, to simulate the effect of oil scarcity? Usually, when a nation "runs out" of a resource, there might still be some, but only in very limited amount, thus variable "odds" that units will be "grounded".

The other idea to block a unit's move is to have it begin a player's turn with an "already moved" status (which means the player cannot move that unit again). Not sure if this is actually doable, but it might work better than trying to mess with movement per se.

----------------

EDIT

The latter approach would also prevent aircraft from being able to run other missions that aren't tied to movement (interception and recon), as G.O. mentioned.
 
I tried your unaltered code, Jeckel, in a fresh mod since I was concerned that maybe other things I'd done were slowing it down unnecessarily. I tested it out on a huge map with 24 battleships moving about halfway across the globe (eta 10 turns, ~60 tiles). It took 20 seconds for the pathfinder to plot the path to the destination, and over two minutes for the battleships to actually start moving.

Keep in mind that on my machine a typical turn on Carter's huge Earth map takes just a couple of seconds. :crazyeye:

Moral of the story is, there has to be a better way to do this. Is there some way you could test it just once, so that it doesn't need to iterate over every unit and every tile along the journey? What I am thinking is that it might be better to check at the start of the turn, and if you have no oil, then all your mechanized units have their movement cleared, so it doesn't even involve unitCannotMoveInto. Of course, this would not work if we wanted a true quantitative system, since you'd have to update your oil supply after each movement... but it's beginning to look like that must be done in SDK, for the sake of our patience and sanity!
 
G.O. -- Wouldn't my suggestion of marking units as "already moved" at the beginning of the turn actually take care of the problem you describe?

I believe that is what I said. :D

But I've given up on Python for this - I'm now looking into the SDK on how to mod this so it will go faster.
 
I believe that is what I said. :D

OK then. So would this not in fact eliminate the delays caused in the game? It seems what you describe is something dealing with movement directly at the time the unit is selected, whereas what I suggest is something that is taken care of entirely at the beginning of the players turn. This might save you the trouble of dealing with SDK. (If SDK is entirely better, then never mind!) :D
 
Finally got it work!

Here is the SDK mod I made. I have already tested it in WWII in the Pacific. If you do not have access to oil, you will not be able to move mechanized units. If you gain access to oil halfway through your turn, any units you previously could not move will now gain that ability. Best of all, this also affects air units! I was very surprised when I started the game and my Japanese Kates could not bomb Pearl Harbor. That American embargo really smarts!

Code:
    // Oil movement restriction - Gaius Octavius
    if (m_pUnitInfo->isMechUnit())
    {
        if (GET_PLAYER(getOwnerINLINE()).getNumAvailableBonuses((BonusTypes)GC.getInfoTypeForString("BONUS_OIL")) < 1)
        {
            return false;
        }
    }

I placed this in CvUnit.cpp under bool CvUnit::canMove() const. It's probably got some kind of inefficiency in it, but considering it's the first SDK snippet that I personally wrote, I'd say it's not bad for a start. :D

Somebody will have to check to see if this also affects ICBMs. I'd hate for it to nullify them as well, since they're really exempt to the oil necessity. I guess we could always just uncheck the bMechanized tag in XML. (In fact, I could not see that it actually does anything in the SDK...)
 
Back
Top Bottom