Author Topic: [DONE][Suggestion] Moddable country funding algorithm  (Read 2292 times)

Offline Nord

  • Commander
  • *****
  • Posts: 1625
  • The Gate is open.
    • View Profile
[DONE][Suggestion] Moddable country funding algorithm
« on: April 23, 2023, 03:53:52 pm »
[SUGGESTION]Question about funding.

Why countries with zero alien activity rise x-com funding at the end of month? Is it more logical, that they will not change their payments, because we do not do anything?
« Last Edit: May 11, 2023, 08:53:31 am by Meridian »

Offline Solarius Scorch

  • Global Moderator
  • Commander
  • *****
  • Posts: 11408
  • WE MUST DISSENT
    • View Profile
    • Nocturmal Productions modding studio website
Re: [Suggestion] Moddable country funding algorithm
« Reply #1 on: April 23, 2023, 05:27:56 pm »
Why countries with zero alien activity rise x-com funding at the end of month? Is it more logical, that they will not change their payments, because we do not do anything?

It is said that ancient Chinese paid their doctors when they were healthy, and stopped paying them when they got ill... :)

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8597
    • View Profile
Re: [Suggestion] Moddable country funding algorithm
« Reply #2 on: April 23, 2023, 05:39:07 pm »
Is this a suggestion or a question?

If suggestion, what are you suggesting?

If question: countries decide based on both xcom activity and alien activity, not just on alien activity... and they also consider a fraction of total world-wide activity, not just the country activity... and then there's also RNG...
So if there is zero alien activity and a lot of xcom activity... they are happy... I would be too :)

Offline Nord

  • Commander
  • *****
  • Posts: 1625
  • The Gate is open.
    • View Profile
Re: [Suggestion] Moddable country funding algorithm
« Reply #3 on: April 23, 2023, 09:29:45 pm »
My problem is, that in my mod first part of the game goes with a single base, and missions are limited with starting region. And it is strange to see, that other countries increase their funding, while player does nothing for them.
Maybe there is a way to limit funding increasing by country? I dont ask about changing global formula, but maybe something can be... optionized?

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8597
    • View Profile
Re: [Suggestion] Moddable country funding algorithm
« Reply #4 on: April 23, 2023, 09:44:47 pm »
My problem is, that in my mod first part of the game goes with a single base, and missions are limited with starting region. And it is strange to see, that other countries increase their funding, while player does nothing for them.

Research activity/points are global, that's why they are happy even though you were never there.

Maybe there is a way to limit funding increasing by country? I dont ask about changing global formula, but maybe something can be... optionized?

Country satisfaction algorithm is nicely separated/isolated... so I can easily replace it without breaking anything.
Try to describe what your ideal global formula would be, and I can try to integrate it (and maybe give it a few parameters too).

Offline Nord

  • Commander
  • *****
  • Posts: 1625
  • The Gate is open.
    • View Profile
Re: [Suggestion] Moddable country funding algorithm
« Reply #5 on: April 24, 2023, 12:41:35 pm »
Country satisfaction algorithm is nicely separated/isolated... so I can easily replace it without breaking anything.
Try to describe what your ideal global formula would be, and I can try to integrate it (and maybe give it a few parameters too).
Thanks, but if you change algorithm for me, it will cause other mods balance problems.
Maybe some part of that algorithm can be unhardcoded?

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8597
    • View Profile
Re: [Suggestion] Moddable country funding algorithm
« Reply #6 on: April 24, 2023, 01:07:24 pm »
Thanks, but if you change algorithm for me, it will cause other mods balance problems.
Maybe some part of that algorithm can be unhardcoded?

I would of course make a setting to choose between the original and a new algorithm.

Offline Nord

  • Commander
  • *****
  • Posts: 1625
  • The Gate is open.
    • View Profile
Re: [Suggestion] Moddable country funding algorithm
« Reply #7 on: April 24, 2023, 03:04:40 pm »
Good then.
So my changes are as simple: if a country has no alien activity in their borders, it will not change funding, regardless X-com activity.

Offline MaxMahem

  • Captain
  • ***
  • Posts: 60
    • View Profile
Re: [Suggestion] Moddable country funding algorithm
« Reply #8 on: April 24, 2023, 03:45:14 pm »
I know I'm a broken record about this, but might be another place where a script enables custom logic. I don't think `Country` is currently very wired up for scripting, but it's not a complex object so it seems like doing so would be straightforward. The hook here could be very simple, when `newMonth` is called, at the very end, a `CountryNewMonth` hook is called, passing in the country, funding calculated by the current method, xcom score, alien score, and the average funding. The hook would pass out an adjusted funding amount. Which, if set by the default script, would simply be the amount passed in.

Country could be immutable or mutable for this, though I think having it be partially mutable here would make sense, letting things like pacts formation be controlled by custom scripting logic in this hook as well.

I'm up for taking a crack at this as well, in part because I'd like to look into how objects are wired up for scripting.

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8597
    • View Profile
Re: [Suggestion] Moddable country funding algorithm
« Reply #9 on: April 24, 2023, 04:34:35 pm »
Sounds OK to me.

Country (and everything else) should be immutable within the script.

Only script output values should be used to modify the country (within c++, immediately after the script execution).

Inputs:
1. xcomTotal
2. alienTotal
3. pactScore
4. averageFunding
5. rng handle (not sure how that works)
6. maybe also results of the default algorithm?
(and script getters should be available for various Country internal members)

Outputs:
a/ new satisfaction
b/ funding change (or new funding)
c/ pact change(s)
d/ score change

Or in other words, similar approach as let's say for damageUnit script hook in BattleUnit.
« Last Edit: April 24, 2023, 05:10:32 pm by Meridian »

Offline Nord

  • Commander
  • *****
  • Posts: 1625
  • The Gate is open.
    • View Profile
Re: [Suggestion] Moddable country funding algorithm
« Reply #10 on: April 24, 2023, 08:32:20 pm »
Sounds goodto me too.

Offline Yankes

  • Commander
  • *****
  • Posts: 3194
    • View Profile
Re: [Suggestion] Moddable country funding algorithm
« Reply #11 on: April 24, 2023, 08:47:03 pm »
For "rng handle (not sure how that works)", there is option to send RNG object that is copy based on current seed (probably used in one or two other scripts already).
This will have benefits that gave will roll same effects independent of what script will do with rng.

Offline Meridian

  • Global Moderator
  • Commander
  • *****
  • Posts: 8597
    • View Profile
Re: [Suggestion] Moddable country funding algorithm
« Reply #12 on: May 11, 2023, 08:56:43 am »
Good then.
So my changes are as simple: if a country has no alien activity in their borders, it will not change funding, regardless X-com activity.

Done in OXCE 7.9.3

Here's your script:

Code: [Select]
extended:
  scripts:
    newMonthCountry:
      - offset: 10
        code: |
          var int alienScore;

          country.getCurrentActivityAlien alienScore;

          #debug_log "getCurrentActivityAlien" alienScore;
          #debug_log "fundingChange" fundingChange;

          if eq alienScore 0;
            #debug_log "NO BUDGET RAISE FROM ME!";
            set fundingChange 0;
          end;

          return fundingChange satisfaction formPact cancelPact;

or a more fancy version:

Code: [Select]
extended:
  scripts:
    newMonthCountry:
      - offset: 10
        code: |
          var int alienScore;
          var int inPact;

          country.getCurrentActivityAlien alienScore;
          country.getPact inPact;

          #debug_log "getCurrentActivityAlien" alienScore;
          #debug_log "fundingChange" fundingChange;
          #debug_log "satisfaction" satisfaction;
          #debug_log "formPact" formPact;
          #debug_log "getPact" inPact;

          # (alienScore = 0) and (fundingChange > 0) and (satisfaction in [unhappy, satisfied or happy]) and (not about to form a pact) and (not in pact already)
          if eq alienScore 0;
            if gt fundingChange 0;
              if gt satisfaction SATISFACTION_ALIENPACT;
                if eq formPact 0;
                  if eq inPact 0;
                    #debug_log "NO BUDGET RAISE FROM ME!";
                    set fundingChange 0;
                    set satisfaction SATISFACTION_SATISIFIED;
                  end;
                end;
              end;
            end;
          end;

          return fundingChange satisfaction formPact cancelPact;

Offline Nord

  • Commander
  • *****
  • Posts: 1625
  • The Gate is open.
    • View Profile
Re: [DONE][Suggestion] Moddable country funding algorithm
« Reply #13 on: May 11, 2023, 12:14:56 pm »
This is great!

Offline Alpha Centauri Bear

  • Colonel
  • ****
  • Posts: 462
    • View Profile
Re: [DONE][Suggestion] Moddable country funding algorithm
« Reply #14 on: December 25, 2023, 03:24:46 pm »
Keep in mind that country zones do not cover whole globe. So it is only logical that they take global activity into account for their funding increase. Otherwise, one can keep fighting aliens in between zones and nobody would care. Especially in the Pacific.