Help needed with scripting supply ships

Creation, discussion, and balancing of game content such as techs, buildings, ship parts.

Moderators: Oberlus, Committer

Message
Author
Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Help needed with scripting supply ships

#1 Post by Ophiuchus »

Hi,

I am currently in the process of scripting supply ships to allow for faster deep space expansion.

1)
It seems though that I misunderstood how scope works.
The following ship part should be unloaded if the ship is in a system with a planet with the BLD_UNLOAD_SUPPLY building.
The scope in the code below should only consist of that single planet. It seems though that currently the effect is triggered on all planets which contain the BLD_UNLOAD_SUPPLY building.
Freeorion version is 0.4.5+ from June 6th

Code: Select all

//... ship part CO_SUPPLIES_030...
    effectsgroups = [
        EffectsGroup    
            scope = And [
                Planet
                InSystem id = Source.SystemID
                Contains Building name = "BLD_UNLOAD_SUPPLY"
                Not HasSpecial name = "UNLOADING_SUPPLIES_SPECIAL"
                OwnedBy empire = Source.Owner
            ]
            effects = [

2) Also is there a way to access the value of the capacity? E.g. via something like Source.Capacity or similar?

Thanks in advance :)
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

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

Re: Help needed with scripting supply ships

#2 Post by Geoff the Medio »

Ophiuchus wrote:2) Also is there a way to access the value of the capacity? E.g. via something like Source.Capacity or similar?
Something like

Code: Select all

Source.PartCapacity name = "SHIP_PART_NAME"
For (1), maybe add an extra InSystem in the scope? Perhaps a ship in no system is causing the scope to match planets in any system.

User avatar
MatGB
Creative Contributor
Posts: 3310
Joined: Fri Jun 28, 2013 11:45 pm

Re: Help needed with scripting supply ships

#3 Post by MatGB »

For one you need both a scope and an activation normally (although I'm never clear on this, I normally copy/paste from something that works and edit). Beyond that I'm not sure what you're trying to do, but a ship part that mimics the solar hull flagship fuel effect might be a viable approach.
Mat Bowles

Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Help needed with scripting supply ships

#4 Post by Ophiuchus »

Geoff the Medio wrote:
Ophiuchus wrote:2) Also is there a way to access the value of the capacity? E.g. via something like Source.Capacity or similar?
Something like

Code: Select all

Source.PartCapacity name = "SHIP_PART_NAME"
For (1), maybe add an extra InSystem in the scope? Perhaps a ship in no system is causing the scope to match planets in any system.
MatGB wrote:For one you need both a scope and an activation normally (although I'm never clear on this, I normally copy/paste from something that works and edit). Beyond that I'm not sure what you're trying to do, but a ship part that mimics the solar hull flagship fuel effect might be a viable approach.
@1)
Thanks, it seems an activation = InSystem helps.

@2)
Will try to use the capacity approach

@MatGb In the long run I want to play a game where my hidden ships cross enemy lines and add production to my hidden planets (e.g. building scanning stations or exobot colonies on outposts). At the moment I want to boost production on a system which is outside of my supply range. I am doing this via 'supply ships' which add some capacity to a planet which gradually gets used up.

Also thanks for both the fast replies :)
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

dbenage-cx
Programmer
Posts: 389
Joined: Sun Feb 14, 2016 12:08 am

Re: Help needed with scripting supply ships

#5 Post by dbenage-cx »

In case it helps (I constantly have issues with getting it correct), the detailed description (alt link) of EffectsGroup might clarify activation.
Contains one or more Effects, a Condition which indicates the objects in the scope of the Effect(s), and a Condition which indicates whether or not the Effect(s) will be executed on the objects in scope during the current turn.
Since Conditions operate on sets of objects (usually all objects in the universe), the activation condition bears some explanation.
It exists to allow an EffectsGroup to be activated or suppressed based on the source object only (the object to which the EffectsGroup is attached).
It does this by considering the "universe" containing only the source object.
If the source object meets the activation condition, the EffectsGroup will be active in the current turn.

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Help needed with scripting supply ships

#6 Post by Ophiuchus »

Geoff the Medio wrote:
Ophiuchus wrote:2) Also is there a way to access the value of the capacity? E.g. via something like Source.Capacity or similar?
Something like

Code: Select all

Source.PartCapacity name = "SHIP_PART_NAME"
Just for reference, the part capacity seems to be accessed without a reference, i.e. like this:

Code: Select all

PartCapacity name = "SHIP_PART_NAME"
As I also didnt find a setter, I guess that part capacity is global and may only be set on on initialisation using

Code: Select all

capacity = 
.
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

dbenage-cx
Programmer
Posts: 389
Joined: Sun Feb 14, 2016 12:08 am

Re: Help needed with scripting supply ships

#7 Post by dbenage-cx »

For effects there are SetCapacity and SetMaxCapacity

e.g. SH_KRAKEN_2_BODY

Code: Select all

SetMaxCapacity partname = "SR_TENTACLE" value = Value + min(Source.Age*0.15, 4)
SetCapacity partname = "SR_TENTACLE" value = Value + min(Source.Age*0.15, 4)

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

Re: Help needed with scripting supply ships

#8 Post by Geoff the Medio »

Ophiuchus wrote:Just for reference, the part capacity seems to be accessed without a reference, i.e. like this:

Code: Select all

PartCapacity name = "SHIP_PART_NAME"
Ah, yes. sorry. That is returning the "capacity" in the part definition script, eg.

Code: Select all

Part
    name = "FT_BAY_1"
    description = "FT_BAY_1_DESC"
    class = FighterBay
    capacity = 2        /// <<=== This value
    mountableSlotTypes = External
    buildcost = 20 * [[FLEET_UPKEEP_MULTIPLICATOR]]
    buildtime = 1
    location = OwnedBy empire = Source.Owner
    icon = "icons/ship_parts/fighters-1.png"
That is often, but not always, the value of a particular ship's capacity meter for that particular part. It could be different if another effect, such as a refinement tech, has modified the meter. (There are also separate max capacity and capacity meters which are modified and behave differently, but the one you'd generally want to base stuff on would be capacity itself.)

I don't think there's actually a way to get the value of a particular part's capacity or max capacity on a particular ship to use in a calculation (eg. multiplying it by something and adding something). However, you can write a condition that checks the actual capacity of a part meter, using something like

Code: Select all

Source.ShipPartMeter part = "PART NAME" Capacity low = 10 high = 100
As I also didnt find a setter, I guess that part capacity is global and may only be set on on initialisation using

Code: Select all

capacity = 
.
The term "setter" is unclear; this isn't an object-oriented general-purpose programming language. You should refer to scripting the content definitions, then modifying the gamestate using effects.

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Help needed with scripting supply ships

#9 Post by Ophiuchus »

Geoff the Medio wrote: I don't think there's actually a way to get the value of a particular part's capacity or max capacity on a particular ship to use in a calculation (eg. multiplying it by something and adding something). However, you can write a condition that checks the actual capacity of a part meter, using something like

Code: Select all

Source.ShipPartMeter part = "PART NAME" Capacity low = 10 high = 100
Does that mean that every ship has internally exactly two values for every "PART NAME" (one capacity and one max capacity), regardless of how often the part is in a ship?
(Any hint where I should start reading c-code?)


Another question regarding industry and outposts - I wanted to add industry to outposts as well as for planets (to speed up building initial buildings on disconnected ) using my scripted supply ships. But it seems industry is always zero on outposts. Is there a specific reason for this or am I doing something wrong?
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

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

Re: Help needed with scripting supply ships

#10 Post by Geoff the Medio »

Ophiuchus wrote:Does that mean that every ship has internally exactly two values for every "PART NAME" (one capacity and one max capacity), regardless of how often the part is in a ship?
Yes.
(Any hint where I should start reading c-code?)
Ship.h maybe?
https://github.com/freeorion/freeorion/ ... Ship.h#L14
But it seems industry is always zero on outposts. Is there a specific reason for this or am I doing something wrong?
I'm seeing a similar result, and I'm not sure why; an effect increasing all empire-owned planets' industry meter doesn't seem to have any affect on an outpost, even when its target industry is well above zero.

Edit: Figured it out, I think. When a planet has 0 population, during post-combat meter updating, a special Depopulate() function is called on the planet, which resets all the planets' resource meters to 0. The idea for this is that when a planet "starves" or otherwise loses all its population, it doesn't have big resource output for many turns afterwards as the meter slowing ticks down towards its (presumable) new target value of 0. So, for outposts to have functional resource outputs, some adjustments to the game rules will be needed...

If you comment out the ->Reset() lines in that function, it might/should work, though I suspect we don't want to do that in master until after the release due to potential balance / bugs that could result...

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Help needed with scripting supply ships

#11 Post by Ophiuchus »

Geoff the Medio wrote: Figured it out, I think. When a planet has 0 population, during post-combat meter updating, a special Depopulate() function is called on the planet, which resets all the planets' resource meters to 0. The idea for this is that when a planet "starves" or otherwise loses all its population, it doesn't have big resource output for many turns afterwards as the meter slowing ticks down towards its (presumable) new target value of 0. So, for outposts to have functional resource outputs, some adjustments to the game rules will be needed...

If you comment out the ->Reset() lines in that function, it might/should work, though I suspect we don't want to do that in master until after the release due to potential balance / bugs that could result...
Second that. Hm. Will come back to that after 0.4.6
Thanks for the research.
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Help needed with scripting supply ships

#12 Post by Ophiuchus »

0.4.6 is out, I am back :)

It looks the Depopulate is called only on population centers, does that include outposts?

I added a condition to skip the call to Depopulate in empty species name. But can't check it
because my visual studio is broken again :(
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Supply ships are ready

#13 Post by Ophiuchus »

Supply ships are in quite ok/polished shape now, need some feedback from you guys

To use:
0) use the branch https://github.com/agrrr3/freeorion/tre ... pply-ships
1) Research the technology "Generic Industrial Supplies"
2) Use the encyclopedia

I need feedback on the following topics:
* do you like the feature?
* did i handle the git branches correctly? should i create a pull request?
* can someone review the code and the stringtables (my mother tongue is not english)?
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

dbenage-cx
Programmer
Posts: 389
Joined: Sun Feb 14, 2016 12:08 am

Re: Help needed with scripting supply ships

#14 Post by dbenage-cx »

I haven't tested it yet, but it certainly looks interesting ;)
This seems like it might take a lot of attention from the user, but I will reserve further judgment until I actually try it.
did i handle the git branches correctly? should i create a pull request?
No merges from master, please use rebase instead.
You might move the change to universe/PopCenter.cpp to a new PR, this change alone needs testing with the rest of the game.
Does default/scripting/specials/UNLOADING_SUPPLIES.focs.txt need all of these comments? I find it hard to read through.
Stringtable look great on first pass, For sitrep messages, it is preferred to start them with some context, e.g. "At %system%: ..."

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Help needed with scripting supply ships

#15 Post by Ophiuchus »

Ok, first thanks for the review :)

Done
* I rebased the code. And squashed the commits.
* I threw the bulk of comments away
* I rearranged the sitreps

Todo
* Splitting out the population center change (rebasing? cherry picking? dunno)

Question
* in default/scripting/specials/UNLOADING_SUPPLIES.focs.txt I use some min-/maxing to prevent hypothetical situations where industry is below zero. Is that bullshit and should be done away, or does it make sense and should handle this situation like I did?
* Regarding the 'takes a lot of attention'. I did three real games using a species which has bad supply (see below). Even with that experience, supply ships were ok, not too much micromanagement.
Handling monsters (even on low setting) took much more attention from me.

p.s.: If you like to try; meet the Travelers:
https://github.com/agrrr3/freeorion/tree/sp_travelers
supply ships come in really handy, as it is hard to set up supply lines with the Travelers. The species is I think a little overpowered, probably will nerf the population down to bad. Also I am not decided on what kind of planets they should be specialized on. They live in the same ecological niche as do the Trith.
I actually didn't build on outposts, but used mostly colonies.
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

Post Reply