Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check each trigger-condition in each cycle #626

Merged
merged 5 commits into from Mar 7, 2024

Conversation

zzam
Copy link
Contributor

@zzam zzam commented Mar 6, 2024

Run all check-functions of all triggers in each cycle. Also improve the API of the called functions to get the index of the trigger [0,n-1] instead of an (shifted) index into a lua-table of triggers.

Contrary to the documentation [1] only one trigger condition is run in every Cycle. This state is even saved to a saved game file.

[1]

** Add a trigger. A trigger is a set of two functions. The first is run every
** cycle and checks a condition. Once it returns <code>true</code>, the second
** function runs. If the second function returns <code>false</code>, the
** trigger is removed and never runs again. Otherwise, it is kept and may run
** again next cycle.

zzam added 4 commits March 6, 2024 15:33
Now behaviour matches the description of CclAddTrigger.
Triggers that check GameCycle for exact values should now work

Saves one global variable / one value written to saved games.
@Jarod42
Copy link
Contributor

Jarod42 commented Mar 6, 2024

Can you see if unit tests can be added for triggers?
https://github.com/Wargus/stratagus/blob/master/tests/stratagus/test_depend.cpp might be a base.

@zzam
Copy link
Contributor Author

zzam commented Mar 6, 2024

Can you see if unit tests can be added for triggers? https://github.com/Wargus/stratagus/blob/master/tests/stratagus/test_depend.cpp might be a base.

I will try to write a test.

@Jarod42 Jarod42 merged commit b5e5bb0 into Wargus:master Mar 7, 2024
3 checks passed
@zzam zzam deleted the trigger-each-cycle branch March 7, 2024 18:45
zzam added a commit to zzam/wargus that referenced this pull request Apr 9, 2024
With the original TransformUnit the unit-peasant become unit-attack-peasant
only in GameCycle=2.
But the Defeat-Trigger that counts them is already executed in in GameCycle=1.
This trigger then counts 0 units of type 'unit-attack-peasant' and the
mission is lost.

This happens since Wargus/stratagus#626 was
merged: b5e5bb0c6a18ccbf ("Merge pull request #626 from zzam/trigger-each-cycle")

Before the code was fragile but it worked due to the ordering of
triggers.

Closes: Wargus#458
zzam added a commit to zzam/wargus that referenced this pull request Apr 9, 2024
With the original TransformUnit the unit-peasant become unit-attack-peasant
only in GameCycle=2.
But the Defeat-Trigger that counts them is already executed in in GameCycle=1.
This trigger then counts 0 units of type 'unit-attack-peasant' and the
mission is lost.

This happens since Wargus/stratagus#626 was
merged: b5e5bb0c6a18ccbf ("Merge pull request #626 from zzam/trigger-each-cycle")

Before the code was fragile but it worked due to the ordering of
triggers.

Closes: Wargus#458
Jarod42 pushed a commit to Wargus/wargus that referenced this pull request Apr 10, 2024
With the original TransformUnit the unit-peasant become unit-attack-peasant
only in GameCycle=2.
But the Defeat-Trigger that counts them is already executed in in GameCycle=1.
This trigger then counts 0 units of type 'unit-attack-peasant' and the
mission is lost.

This happens since Wargus/stratagus#626 was
merged: b5e5bb0c6a18ccbf ("Merge pull request #626 from zzam/trigger-each-cycle")

Before the code was fragile but it worked due to the ordering of
triggers.

Closes: #458
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants