Having been trudging with this since March; I have found myself stuck.
In the last week, I've been trying to replicate
HPD's Zed; but I got rather stuck. First I made a list of what I need to check from the CO's units; and added what I knew was needed:
I. Turn unit was produced (done)
II. Unit's X and Y position at turn start (done)
III. Unit's HP, Fuel, and Ammo at turn start [for SCOP] (done)
IV. If the unit was loaded at turn start (done)
V. What unit the unit was loaded in at turn start (maybe not necessary)
VI. What units the unit has loaded in it at turn start, and 1-5 for these units (done)
And what I need the power method to execute:
1. Un-produce all units that were produced this turn (destroy unit and add funds equal to the unit's price). (fully functional)
2. Revert all unit's X/Y positions to turn start. (mostly functional)
2a/3. Any units that were loaded need their sprite un-disposed (how?!)
4. Revert all unit's HP, Fuel, and Ammo counts to turn start, refresh/un-act if SCOP (functional).
5. Re-load any units that performed unload actions
6. Delete any units that were unloaded (currently just disposes their sprite without properly removing them)
To these ends I've added a number of variables: (and of course I've also -actually added them- to the unit methods)
# Disable the units that have a disabled flag, initialize day variables
@player_turn.units.each{|u|
u.stx = u.x
u.sty = u.y
u.HPD = u.health
u.stf = u.fuel
u.sta = u.ammo
u.stl = u.loaded
u.stc = u.holding_units
if u.disabled
u.acted = true
u.disabled = false
end
}
And of course for health and fuel/ammo, those are changed when the unit gets repaired or resupplied via the daily method as well (and in the daily fuel method).
I also changed unit producing to include the day that the unit gets built, and this is stored as "madeday". (by changing initialize to include day as a fourth variable; because I couldn't think of a better way that certainly exists)
And the actual method looks like this presently:
def use_scop
super
@army.units.each{|u|
if u.madeday == $game_map.day #if it was made this day
u.unmake
else #if it wasn't
u.holding_units.each{|v| #unit(s) v that u is holding [lander]
v.holding_units.each{|i| #unit(s) that v was holding [with an apc]
i.x = i.stx #[that has an infantry, i guess]
i.y = i.sty
i.loaded = false unless i.stl
i.fuel = i.stf
i.ammo = i.sta
i.health = i.HPD
i.acted = false
i.holding_units = i.stc
} #i
v.x = v.stx
v.y = v.sty
v.loaded = false unless v.stl
v.fuel = v.stf
v.ammo = v.sta
v.health = v.HPD
v.acted = false
v.holding_units = v.stc
} #v
u.x = u.stx
u.y = u.sty
u.loaded = false unless u.stl
u.fuel = u.stf
u.ammo = u.sta
u.health = u.HPD
u.acted = false
u.holding_units = u.stc
end #made this day
} #u
end
[In the unit class]
# For Zed's use, since the current destroy method isn't quite right.
def unmake
@army.funds += cost(true)
@holding_units.each{|u|
u.holding_units.each{|i| #unloads units, just in case. >_>
i.x = i.stx
i.y = i.sty
if @army.scop #resets them if it's SCOP
i.fuel = i.stf
i.ammo = i.sta
i.health = i.HPD
i.acted = false
end
} #i
} #u
index = @army.units.index(self)
@army.units[index] = nil
$game_map.set_unit(@x,@y,nil)
@needs_deletion = true
@sprite.dispose
end
But this doesn't properly do everything as lamented above in 2a/3; I can't fully figure out step 5 either.
Currently, 2a/3 is impossible for me.
5, on the other hand, works... but it leaves a ghost unit where the unit was dropped off with no sprite. >< I'm sure I missed something that I need to do but I legitimately can't figure it out.
So I'm, unfortunately, asking for help.