PAC code questions

Started by mzimmer74, September 03, 2016, 05:05:24 PM

Previous topic - Next topic

mzimmer74

So every once in a while I look into the PAC code to see if there is a way to optimize it any more to fix some of the lag issues that occasionally come up.  Mainly I'm looking in Abraxis.crpl.  One of the parts that could theoretically take some time is the checking for a win condition.  Here is that code:

# Check to see if the game has been won. When no units marked as a 1 above are present, the game is won.
if (GetGameTimeFrames 60 gt) # Don't start checking until the 60th frame (2 seconds) to allow all units to be built if needed
1 ->Victory # Assume victory has been reached unless determined below
GetUnitsInRange(0 0 9999) 0 do # This finds all units on map and loops through them
->Unit
GetUnitType(<-Unit) ->Type # Get the unit type
if(<-Type <-!) # Look up the unit type in the list of units that count for victory
# If a victory unit is found, flag as no victory and leave this loop
0 ->Victory
Break
endif
loop
endif


What I'm wondering is if it would be faster to check to see if there are any landed CNs.  Realistically speaking, once you've gotten rid of all the CNs the game becomes mop up.  In looking at the wiki I found the Unit Command "GetCommandNodeCount" that says it returns the number of landed command nodes to the stack.  Now, assuming that works, wouldn't the following code work to replace the victory condition code:


if (GetGameTimeFrames 60 gt) # Don't start checking until the 60th frame (2 seconds) to allow all units to be built if needed
1 ->Victory # Assume victory has been reached unless determined below
if (GetCommandNodeCount 0 gt)
#There is at least one CN therefore no victory
0->Victory
endif
endif


Now, I haven't done much with CRPL or stack languages so I'm not completely certain on the structure, but doesn't it seem like that would work?  Also, would it make any difference?  I'm guessing the rebuild code is more intensive than this part, but it seems like this might help a bit.  Plus it would remove the "mop-up" portion of PAC maps.

Anyway, does anybody have any thoughts on this or better ideas?
Thanks.
Omnipotence doesn't mean the ability to do what is logically impossible. It's possible, therefore, for God to create beings with the kind of free will that can choose between good and evil, but he can't also force those creatures to choose good. If he forced their choice, it wouldn't be free.

J

The code immediatly stops after it has found any unit that prevents victory, so it's not checking for all units every frame. Changing the code to what you suggested would work (and it's slightly faster) in almost all PAC maps (just not in my #noCN PAC maps).
Quite often the CN is the last thing to remain while all other units are already gone. CN's have more health than other units, so it might sometimes even increase the wait time (which is not as fun as clearing some low-health units).

mzimmer74

Good point about the break in the loop.  Didn't think about how that would make it faster.  I actually made a dummy PAC map with this code and unfortunately while it did give me the "all humans have been purged" message, it didn't pop up a win dialog.  But, with the point you just made it's probably not worth trying to go through to figure out what I missed.
Omnipotence doesn't mean the ability to do what is logically impossible. It's possible, therefore, for God to create beings with the kind of free will that can choose between good and evil, but he can't also force those creatures to choose good. If he forced their choice, it wouldn't be free.