How do I do custom trade, infrastructure meters?

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
Gault.Drakkor
Space Floater
Posts: 40
Joined: Sat Jul 01, 2017 4:54 am

How do I do custom trade, infrastructure meters?

#1 Post by Gault.Drakkor »

I am wanting to experiment with custom meters for trade and infrastructure (and probably population later on).

I would like to get some help with where/what to modify.
It looks like I should create something like PopCenter for both trade, infrastructure to do custom calculations for the meter targets and growth values.
Not seeing how target_meter_value is set/determined ATM. Where would I find that? Having trouble back tracking: float target_meter_value = target->Current(); That is, where is population taking specials and tech into consideration?

For trade I want to iterate over all colonies/planets of current empire( and trade allied empires).
Info I want to use: distance as uu, distance as jumps(supply limit), pop size, species, planet type, planet focus
Where is good example that I can copy+modify?

In ResourceCenter.h I see METER_CONSTRUCTION but no infrastructure, is METER_CONSTRUCTION === infrastructure?

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13586
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: How do I do custom trade, infrastructure meters?

#2 Post by Geoff the Medio »

Gault.Drakkor wrote:Not seeing how target_meter_value is set/determined ATM. Where would I find that? Having trouble back tracking: float target_meter_value = target->Current(); That is, where is population taking specials and tech into consideration?
Not sure exactly what you're asking. Are you aware that scripted effects are used to set meter values? Are you asking in what functions effects are executed? Or where / when those functions are run? Or where the API for effects scripting is defined? Or how meter-setting effects work internally when executed?
For trade I want to iterate over all colonies/planets of current empire( and trade allied empires).
Info I want to use: distance as uu, distance as jumps(supply limit), pop size, species, planet type, planet focus
Most of that is accessible in scripted effects. There are lots of examples in the scripting directory, eg. https://github.com/freeorion/freeorion/ ... D.focs.txt or https://github.com/freeorion/freeorion/ ... H.focs.txt and https://github.com/freeorion/freeorion/ ... macros#L57
I'm not sure whether you want / need to add new meters to something, or just change / add effects that determine existing meters' values.
Where is good example that I can copy+modify?
If you can be more clear / specific about what you're trying to do, a relevant example can probably be found. I'm not yet sure if you want / need to modify C++ code, or just effect scripting.
is METER_CONSTRUCTION === infrastructure?
Yes.

Gault.Drakkor
Space Floater
Posts: 40
Joined: Sat Jul 01, 2017 4:54 am

Re: How do I do custom trade, infrastructure meters?

#3 Post by Gault.Drakkor »

Geoff the Medio wrote: I'm not sure whether you want / need to add new meters to something, or just change / add effects that determine existing meters' values.
Where is good example that I can copy+modify?
If you can be more clear / specific about what you're trying to do, a relevant example can probably be found. I'm not yet sure if you want / need to modify C++ code, or just effect scripting.
Thank you for your reply.

I'll describe what I want to try doing. Hopefully it will be clear enough for you to point me in the right direction.

Trade:
I want to implement something along the lines of an inverse square law:

Code: Select all

def update_planet_trade(current_planet):
    trade = 0
    for planets in empire:
        if planet in supply_range:
            trade += empire_trade_bonus * current_planet.pop * planet.pop/
                        (distance_in_uu(current_planet, planet)**2)
    current_planet.target_trade = trade
With additional values going into it. such as:
  • The supply of current planet and other planet.
  • The infrastructure of current planet and other planet.
  • If trade is current focus of either planet.
  • Species of current planet and other planet, (and their trade bonus/malus).
  • Planet type, different types would be a small bonus.
I would want to keep track of, say top 5, trade partners and display that in the tool tip.

I don't believe I can do this in the FOCS.

Infrastructure:
I haven't firmed up my formulas yet.
So far:
  • Cost of each point of infrastructure to be exponential.
  • Production multiplier for each unit of infrastructure to have diminishing returns.
  • Perhaps a capacity factor like what moo3 had. (will probably not include this)
  • Maintenance cost.
  • Current infrastructure to be used for current trade, current trade to be used to determine next/increment of infrastructure.
  • Planning to siphon off 10% of trade /production every turn.
Population:
Control population not by determining population cap, but by determining population growth. So probably a creation of an additional meter: population growth. With one unit of the growth meter being 0.1% growth to apply to the population meter. I would also need to modify techs, specials too affect growth not population cap, but that I know how to do If there is a separate growth meter.
I am pretty sure I can figure out creation of an additional meter, not sure how to display that in the UI though, but haven't looked into that at all.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13586
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: How do I do custom trade, infrastructure meters?

#4 Post by Geoff the Medio »

Gault.Drakkor wrote:Trade:
I want to implement something along the lines of an inverse square law:

Code: Select all

def update_planet_trade(current_planet):
    trade = 0
    for planets in empire:
        if planet in supply_range:
            trade += empire_trade_bonus * current_planet.pop * planet.pop/
                        (distance_in_uu(current_planet, planet)**2)
    current_planet.target_trade = trade
With additional values going into it. such as:
  • The supply of current planet and other planet.
  • The infrastructure of current planet and other planet.
  • If trade is current focus of either planet.
  • Species of current planet and other planet, (and their trade bonus/malus).
  • Planet type, different types would be a small bonus.
An effect like SetTargetTrade value = [stuff] can have arbitrarily complicated [stuff], which can (or can be made to on request) reference all of those properties.
I would want to keep track of, say top 5, trade partners and display that in the tool tip.
That would require C++. Doing it in a sitrep message might be possible just in FOCS.
Infrastructure:
  • Cost of each point of infrastructure to be exponential.
  • Production multiplier for each unit of infrastructure to have diminishing returns.
  • Perhaps a capacity factor like what moo3 had. (will probably not include this)
  • Maintenance cost.
  • Current infrastructure to be used for current trade, current trade to be used to determine next/increment of infrastructure.
  • Planning to siphon off 10% of trade /production every turn.
A SetTargetIndustry effect could refer to infrastructure (construction meter) with an arbitrary function to determine how to change the meter value. Similarly, SetConstruction (to increment construction meter) can refer to arbitrary combinations of meters. The rest are unclear / vague.
Population:
Control population not by determining population cap, but by determining population growth. So probably a creation of an additional meter: population growth. With one unit of the growth meter being 0.1% growth to apply to the population meter. I would also need to modify techs, specials too affect growth not population cap, but that I know how to do If there is a separate growth meter.
I am pretty sure I can figure out creation of an additional meter, not sure how to display that in the UI though, but haven't looked into that at all.
If you want a separate growth meter to appear in the UI, it would require C++ modifications. The actual population changes are currently implemented in C++ code, https://github.com/freeorion/freeorion/ ... r.cpp#L102 although this should probably be moved into an effect regardless of your plans.

Gault.Drakkor
Space Floater
Posts: 40
Joined: Sat Jul 01, 2017 4:54 am

Re: How do I do custom trade, infrastructure meters?

#5 Post by Gault.Drakkor »

Geoff the Medio wrote:An effect like SetTargetTrade value = [stuff] can have arbitrarily complicated [stuff], which can (or can be made to on request) reference all of those properties.
Ok, underestimated what you can do in FOCS.
Geoff the Medio wrote: If you want a separate growth meter to appear in the UI, it would require C++ modifications. The actual population changes are currently implemented in C++ code, https://github.com/freeorion/freeorion/ ... r.cpp#L102 although this should probably be moved into an effect regardless of your plans.
So something like this?

Code: Select all

POPULATION_CHANGE
'''EffectsGroup
            scope = Source
            activation = Planet
            effects = SetPopulation value = min(Value  * ( Target.Population + 1 - Value) / 100, Target.Population - Value)
'''
I see via orbital drydock how to do functions. Not sure about looping. The web page and the existing scripts don't seem to have much.

I believe I have enough info to write up what I want to do and try some of them(infrastructure and population growth) In game. I'll come back later with a more complete writeup of what I want to do with trade, and better understanding of FOCS.
Thank you for your help.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13586
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: How do I do custom trade, infrastructure meters?

#6 Post by Geoff the Medio »

Gault.Drakkor wrote:[So something like this?

Code: Select all

POPULATION_CHANGE
'''EffectsGroup
            scope = Source
            activation = Planet
            effects = SetPopulation value = min(Value  * ( Target.Population + 1 - Value) / 100, Target.Population - Value)
'''
That would set the population equal to what is currently the change in population each turn.
I see via orbital drydock how to do functions. Not sure about looping.
You don't need to loop; you need to sum, which is a statistic, eg. https://github.com/freeorion/freeorion/ ... ocs.txt#L2

Post Reply