OpenXcom Forum

Modding => OpenXcom Extended => OXCE Suggestions DONE => Topic started by: Meridian on January 09, 2022, 09:00:10 pm

Title: [DONE][Suggestion] Access to object counters within Arc/Mission/Event scripts
Post by: Meridian on January 09, 2022, 09:00:10 pm
All 3 script types now have access to 3 different kinds of counters:

1. mission script `varName` counter... you can find it under `alienStrategy:` in the save file

2. global object counter... you can find it under `ids:` in the save file
- this contains the number of various generated game objects, most notably mission markers

3. custom global object counter... this is also under the same `ids:` in the save file
- this contains modder-defined counters, that can increase or decrease after mission success/failure/despawn

The `varName` can be accessed via `missionVarName`.
Global counters (both default and custom) can be accessed via `missionMarkerName`.

The counter is then compared against the limits defined via `counterMin` and `counterMax`.

IMPORTANT: please note that `ids:` in the save file hold a value of the counter plus 1. For example if the game generated 2 terror site, the save will contain `STR_TERROR_SITE: 3`.

Example for an event script (same syntax is valid for mission scripts and arc scripts):

Code: [Select]
eventScripts:
  - type: STR_TEST
...
    missionVarName: shippingLanes           # varName from mission scripts
    missionMarkerName: STR_TERROR_SITE      # marker name from alien deployment
    missionMarkerName: CUST_TERROR_SUCCESS  # custom counter name from alien deployment
    counterMin: 3
    counterMax: 3                           # -1 = infinity/unlimited
...

Please only use one of the `missionVarName` and `missionMarkerName` at a time; they share the `counterMin` and `counterMax` values.
Default for `counterMin` is 0 (zero).
Default for `counterMax` is -1 (unlimited).
Title: Re: [DONE][Suggestion] Access to object counters within Arc/Mission/Event scripts
Post by: Meridian on January 09, 2022, 09:06:35 pm
Custom mission counters are defined via 8 new alienDeployment attributes:
1. `counterSuccess` - increases on mission success
2. `counterFailure` - increases on mission failure and on mission site despawn (which is also a failure, duh)
3. `counterDespawn` - increases on mission site despawn
4. `counterAll` - increases on mission success, failure and despawn

5. `decreaseCounterSuccess` - decreases on mission success
6. `decreaseCounterFailure` - decreases on mission failure and on mission site despawn (which is also a failure, duh)
7. `decreaseCounterDespawn` - decreases on mission site despawn
8. `decreaseCounterAll` - decreases on mission success, failure and despawn

Example:

Code: [Select]
alienDeployments:
  - type: STR_TERROR_MISSION
...
    counterSuccess: CUSTOM_TERROR_SUCCESS
    counterFailure: CUSTOM_TERROR_FAILURE
    counterDespawn: CUSTOM_TERROR_DESPAWN
    counterAll: CUSTOM_TERROR_ALL
...

PS: note that just like the default game object counters, also these custom counters have a value in the save file increased by one... keep that in mind when testing/investigating

PS2: counters cannot decrease below zero

PS3: don't decrease non-custom counters, you'll break/crash the game
Title: Re: [DONE][Suggestion] Access to object counters within Arc/Mission/Event scripts
Post by: Finnik on February 12, 2022, 07:13:51 pm
How do you think, can we affect those variables with research discovery?
Title: Re: [DONE][Suggestion] Access to object counters within Arc/Mission/Event scripts
Post by: Meridian on February 12, 2022, 07:52:05 pm
It is feasible.
Do you need it?
If yes, do you have any preferences how to do it?
Title: Re: [DONE][Suggestion] Access to object counters within Arc/Mission/Event scripts
Post by: Finnik on February 12, 2022, 08:53:41 pm
I do, and I think as researches are a very common way to affect campaign, some other modders might need it as well.

I think `increaseCounter: ALIEN_TECHNOLOGY` and `decreaseCounter: TIME_BEFORE_ALIEN_RAMPAGE` would be nice.
Title: Re: [DONE][Suggestion] Access to object counters within Arc/Mission/Event scripts
Post by: Finnik on February 19, 2022, 10:56:25 pm
If anything - I need it for getOneFree as well (actually, mostly for it). Do you want me to code that?
Title: Re: [DONE][Suggestion] Access to object counters within Arc/Mission/Event scripts
Post by: Meridian on February 20, 2022, 09:50:22 am
I have put it on todolist.
It will be added in the next release.
Title: Re: [DONE][Suggestion] Access to object counters within Arc/Mission/Event scripts
Post by: mutantlord on February 21, 2022, 03:21:37 am
Hi, new to the event modding, I like to know if events can spawn a mission via eventscript?
Title: Re: [DONE][Suggestion] Access to object counters within Arc/Mission/Event scripts
Post by: Finnik on February 21, 2022, 10:32:13 pm
Nope, but mission can be spawned with mission script  ;)
Tho, you can make the event that would enable conditions for mission script. Traditionally, it can be done with unlocking "hidden" research project (the one without ufopedia and unavailable to the player). Or, ofc, you can make this project visible with attaching pedia article to it. You can spawn item, that would be in turn trigger the mission.

For more complex story, you can use this new counters as triggers, but you can only spawn specific missions from mission scripts or from alien bases.
Title: Re: [DONE][Suggestion] Access to object counters within Arc/Mission/Event scripts
Post by: mutantlord on February 22, 2022, 01:13:28 am
That is a bit complicated for me thanks for the explanation.
Title: Re: [DONE][Suggestion] Access to object counters within Arc/Mission/Event scripts
Post by: Finnik on May 11, 2022, 10:52:36 pm
I have put it on todolist.
It will be added in the next release.

Sorry for bothering, but is there any approximate ETA for it?
I will be glad to contribute, if needed  ;)
Title: Re: [DONE][Suggestion] Access to object counters within Arc/Mission/Event scripts
Post by: Meridian on May 11, 2022, 11:01:01 pm
in OXCE 7.6

when that is going to happen is not easy to say
earliest end of May
more probably mid June
worst case beginning of July
Title: Re: [DONE][Suggestion] Access to object counters within Arc/Mission/Event scripts
Post by: Finnik on May 12, 2022, 09:45:58 pm
OK, thanks for sharing detailed plans! =)
Title: Re: [DONE][Suggestion] Access to object counters within Arc/Mission/Event scripts
Post by: Meridian on May 16, 2022, 08:47:45 pm
https://github.com/MeridianOXC/OpenXcom/commit/48569ab0feff4392ff8964259e3d4ec96b0028ea

pls check if this is ok for you

Code: [Select]
research:
  - name: STR_SECTOID_NAVIGATOR
    decreaseCounter: [COUNTER_BBB, COUNTER_EEE]
  - name: STR_SECTOID_SOLDIER
    increaseCounter: [COUNTER_AAA, COUNTER_BBB, COUNTER_CCC]
Title: Re: [DONE][Suggestion] Access to object counters within Arc/Mission/Event scripts
Post by: Finnik on May 17, 2022, 02:27:15 pm
That's great. That property is also taken into account on `getOneFree` and other cases where I unlock research (event, deployment), right?
Title: Re: [DONE][Suggestion] Access to object counters within Arc/Mission/Event scripts
Post by: Meridian on May 17, 2022, 02:29:40 pm
That's great. That property is also taken into account on `getOneFree` and other cases where I unlock research (event, deployment), right?

on all places where `handlePrimaryResearchSideEffects()` is called
most places, but not everywhere
Title: Re: [DONE][Suggestion] Access to object counters within Arc/Mission/Event scripts
Post by: Finnik on May 17, 2022, 03:45:37 pm
How do you think, maybe it can be more agile if instead of 2 different properties with array you'd just load a map of <string, int> where hey is custom counter name and value is, well, value, that is added to it? As the map can handle negative integers at the same time, we'd need only one property...
Title: Re: [DONE][Suggestion] Access to object counters within Arc/Mission/Event scripts
Post by: Meridian on May 17, 2022, 04:20:13 pm
I have explicitly asked you, and you said 2 properties (see above)

I'm not interested in being "agile", being "agile" only ever brought me problems
I want to be "stable", "dependable" and "consistent"

consider what you need and tell me... and don't change your mind every 2 hours, please
Title: Re: [DONE][Suggestion] Access to object counters within Arc/Mission/Event scripts
Post by: robin on August 23, 2022, 10:45:01 pm
I don't fully grasp counters. Are there examples of them implemented?
I'm thinking of using them to simulate alien infiltration level of human factions, but I need to understand better how they work.
Title: Re: [DONE][Suggestion] Access to object counters within Arc/Mission/Event scripts
Post by: zee_ra on April 23, 2023, 06:50:02 pm
I don't fully grasp counters. Are there examples of them implemented?
I'm thinking of using them to simulate alien infiltration level of human factions, but I need to understand better how they work.

They're global variables, operated by triggers at designated points, specified by constructs like increaseCounter and decreaseCounter in the config.