wargus icon indicating copy to clipboard operation
wargus copied to clipboard

ActionVictory and ActionDefeat SinglePlayerTriggers

Open DinkyDyeAussie opened this issue 7 years ago • 15 comments

I was editing the scripts for the campaign the other day while testing the Victory/Defeat messagebox delay, in other words I was making sure the time it took for the "You are Victorious!" and "You have been Defeated" message boxes matched the original games time of delay - in this case 120 milliseconds.

I soon found out that I had to add this contingency to EVERY Victory/Defeat condition in EVERY campaign script file, which is arduous and stupid.

I eventually found this in 'stratagus.lua'

function SinglePlayerTriggers()
  AddTrigger(
    function() return GetPlayerData(GetThisPlayer(), "TotalNumUnits") == 0 end,
    function() return ActionDefeat() end)

  AddTrigger(
    function() return GetNumOpponents(GetThisPlayer()) == 0 end,
    function() return ActionVictory() end)
end

and, based on the code from the second mission of the human campaign that I originally observed having a delay when you rescued the four archers and returned them to the circle of power, I took that code from that mission script and modified the 'stratagus.lua' file to that which is below

function SinglePlayerTriggers()
local cycle2Win = 120
  AddTrigger(
    function() return GetPlayerData(GetThisPlayer(), "TotalNumUnits") == 0 end,
		function()
		if (cycle2Win == 120) then
		end		
		cycle2Win = cycle2Win - 1
		if (cycle2Win <= 0) then
			ActionDefeat() 
			return false
		end
	return true end)

  AddTrigger(
    function() return GetNumOpponents(GetThisPlayer()) == 0 end,
	function()
	if (cycle2Win == 120) then
		cycle2Win = cycle2Win - 1
                end
		if (cycle2Win <= 0) then
			ActionVictory() 
			return false
		end
	return true end)
end

But the delay won't work. I cannot figure this out, and would like some help please.

DinkyDyeAussie avatar May 11 '17 18:05 DinkyDyeAussie

I've seen that thing in human mission 2 as well. I dont know why it wouldn't work since you've put that in stratagus.lua. Did you try out in a campaign mission? I think it must be because the code doesn't consider the campaign missions as singleplayer, since the campaign missions has their own victory and defeat conditions. And the code you've added might only apply to the singleplayer custom games.

But if you ask me, I think it's better that you dont have to wait for the victory or defeat screen to show up. I think that's an improvement in wargus.

Erenussocrates avatar May 12 '17 06:05 Erenussocrates

First, the things you modified there in stratagus.lua only applies to the victory and defeat when all units are gone... The missions have their own conditions, so it won't apply to them.

If you really want the delay, patch the ActionDefeat and ActionVictory functions directly so they handle the delay internally.

timfel avatar May 12 '17 06:05 timfel

When you say patch them internally, you mean in the engine right? I am happy to try and do that but I haven't coded the engine for a long time. Will maybe try modifying the github code instead...idk.

DinkyDyeAussie avatar May 12 '17 22:05 DinkyDyeAussie

No, you can monkeypatch the function in lua. I can post an example of what I mean tomorrow

DinkyDyeAussie [email protected] schrieb am Sa., 13. Mai 2017, 00:06:

When you say patch them internally, you mean in the engine right? I am happy to try and do that but I haven't coded the engine for a long time. Will maybe try modifying the github code instead...idk.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/Wargus/wargus/issues/238#issuecomment-301196737, or mute the thread https://github.com/notifications/unsubscribe-auth/AAC0m_u3iILM0GROFEj0U9hLvYyHKvrCks5r5Nf-gaJpZM4NYaE1 .

timfel avatar May 12 '17 22:05 timfel

No worries. Thanks in advance.

DinkyDyeAussie avatar May 13 '17 03:05 DinkyDyeAussie

Sorry for the delay, here's what I mean you could do (I have just written this, not run it):

-- configure the total cycle count before ActionVictory here
local CYCLE2END_COUNT = 120
-- patch the ActionVictory (same for ActionDefeat)
local ImmediateActionVictory = ActionVictory
local cycle2win = 0
function ActionVictory()
    if cycle2win <= 0 then
        -- the counter will be shared across missions, so
        -- reset the local counter when it was used up
        cycle2win = CYCLE2END_COUNT
    else
        cycle2win = cycle2win - 1
        if cycle2win == 0 then
            return ImmediateActionVictory()
        else
           return true -- continue this trigger
        end
    end
end

timfel avatar May 15 '17 07:05 timfel

Does that code go in stratagus.lua too Tim?

DinkyDyeAussie avatar May 15 '17 19:05 DinkyDyeAussie

Yes.

DinkyDyeAussie [email protected] schrieb am Mo., 15. Mai 2017, 21:34:

Does that code go in stratagus.lua too Tim?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/Wargus/wargus/issues/238#issuecomment-301580313, or mute the thread https://github.com/notifications/unsubscribe-auth/AAC0mw3yoSMeDXe2RaMA7y_KYH0Xzxf8ks5r6KjYgaJpZM4NYaE1 .

timfel avatar May 15 '17 20:05 timfel

Just finished testing that code out. Changed CYCLE2END_COUNT and cycle2win values around, otherwise no condition was reached. Works now for both Victory and Defeat conditions in the Campaign 👍

-- configure the total cycle count before ActionVictory here
local CYCLE2END_COUNT = 0
-- patch the ActionVictory (same for ActionDefeat)
local ImmediateActionVictory = ActionVictory
local cycle2win = 120
function ActionVictory()
    if cycle2win <= 0 then
        -- the counter will be shared across missions, so
        -- reset the local counter when it was used up
        cycle2win = CYCLE2END_COUNT
    else
        cycle2win = cycle2win - 1
        if cycle2win == 0 then
            return ImmediateActionVictory()
        else
           return true -- continue this trigger
        end
    end
end

DinkyDyeAussie avatar May 16 '17 01:05 DinkyDyeAussie

Just wondering, now that this variable is in 'stratagus.lua' instead of the respective mission files, if there is a rescue mission and you need to return a unit to the 'circle of power', the "rescue" sound no longer plays when the unit crosses the circle of power anymore. Can we hack that feature back in as well in lua? Or will it need to be a per misson script thing still?

DinkyDyeAussie avatar May 16 '17 02:05 DinkyDyeAussie

Those missions (e.g. Human 2) should be simplified now, the cycle2win is no longer needed there, jus use a boolean local variable to see if the sound was already played, and call ActionVictory always (because it keeps its own counter)

timfel avatar May 16 '17 05:05 timfel

Yeeeeeeah how do I do that? lol. I hace no idea how to do that or where to implant it.

DinkyDyeAussie avatar May 16 '17 07:05 DinkyDyeAussie

Ill medel with it though.

DinkyDyeAussie avatar May 16 '17 07:05 DinkyDyeAussie

Did you update the wargus on this? My missions wont work out of blue.

Erenussocrates avatar May 24 '17 12:05 Erenussocrates

@DinkyDyeAussie if you feel up to it, try to add a configuration option and use that in a condition to decide if you should patch the ActionVictory and ActionDefeat or not. The option handling in the scripts is mostly in stratagus.lua. You can also add the option to the game options menu, if you want.

timfel avatar Jun 05 '17 15:06 timfel