FreeOrion

Forums for the FreeOrion project
It is currently Wed Dec 13, 2017 7:06 am

All times are UTC




Post new topic Reply to topic  [ 50 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
PostPosted: Wed Sep 21, 2016 12:11 am 
Offline
Space Kraken

Joined: Mon Nov 16, 2015 5:57 am
Posts: 105
During the course of my questions the current script has grown larger.
So all the original questions are below the following which is current.

I am however placing the script, as it is currently that i am making. in order to learn with here.
So that it is easier to reference. It's gotten much larger then when i first began.

This is basically done as far as i can tell, it is working properly. I didn't actually test this out for cost or time or requirements to build, (for whats reasonable). As well, im not sure exactly were it would go in the tech tree. As this is just for learning right now, and it is a random idea that seemed cool.

Here is the script as it is for October 6 2016

The comments are not required in the scripts but i have left them in for reference.

PlanetaryGuns.focs.txt
Code:
/*
Planet Gun tech
*/

Tech
    name = "DEF_PLANET_GUN"
    description = "DEF_PLANET_GUN_DESC"
    short_description = "DEFENSE_SHORT_DESC"
    category = "DEFENSE_CATEGORY"
    researchcost = 10
    researchturns = 6
    prerequisites = "DEF_ROOT_DEFENSE"
    unlock = Item type = Building name = "BLD_PLANETARY_GUN"
    graphic = "icons/tech/defense.png" 
   
#include "/scripting/common/priorities.macros"
#include "/scripting/common/base_prod.macros"


PLANETARY_GUN.focs.txt
Code:
/*
Planetary gun

Description.
Allowed 1 per planet. 
Drains a small amount of fuel from the target it hits.
The gun hits un-shielded targets very hard a small amount of additional damage is done as the gun is improved over time.
((60  / (20 + Target.Shield * 4) ) * (CurrentTurn / 20 + 4) )

The planetary gun must be able to see its opponents to reliably hit them, unlike mines which maybe collided into. The gun will fire at suspected cloaks with a 33% chance to hit.

Tactical
Purpose: early added defense to systems considered valuable and to prevent loitering.
Role: Defense, Sneaky offense, tactical fortification.
Strength: vs single un-shielded targets.
Weakness: vs shielded targets
Comments: It's meant to be fairly early tech it's strength increases over time but not a even proportion to the expected technology unlocked. Better shields reduce the firepower of these guns greatly.

I may make a another version particularly to drain fuel.

Tested for.
+build only one gun per planet and working encue
+correct hits by one gun via script on a target.
+correct hits on multiple targets by multiple guns in the same system
+correct hits by multiple guns on the same target
+proper damage and destroyed messages
+if the hits are actually registering.
+minor fuel hit on targets
+auto upgrading damage over time, this is done over time by the damage calculation via the game turns
+will target cloaks with random chance to hit.
+tested vs ai attacking.
-tested vs ai defending.
-kinda wanted new images but this way its just copy and paste to try it.
*/

BuildingType
name = "BLD_PLANETARY_GUN"
description = "BLD_PLANETARY_GUN_DESC"
buildcost = 10
buildtime = 1
location = And
[
   Planet
   Not Contains Building name = "BLD_PLANETARY_GUN"
   Not Planet type = [GasGiant]
   OwnedBy empire = Source.Owner
]
EnqueueLocation = And
[
   Not Contains Building name = "BLD_PLANETARY_GUN"
   Not Enqueued type = Building name = "BLD_PLANETARY_GUN"
   Not Planet type = [GasGiant]
   OwnedBy empire = Source.Owner
]
effectsgroups =
[
   EffectsGroup
   scope = NumberOf number = 1 condition = And
   [
      Ship
      InSystem id = Source.SystemID
      OwnedBy affiliation = EnemyOf empire = Source.Owner         
   ]
   effects =
   [
      //
      // Non cloaked ships
      //
      If condition = and
      [
         // destroy visible ship check
         VisibleToEmpire empire = Source.Owner
         Structure high = ((60  / (20 + Target.Shield * 4) ) * (CurrentTurn / 20 + 4) )
      ]
      effects =
      [
         Destroy
         
         //
         // msg to the player firing the gun
         //
         GenerateSitrepMessage
            message = "EFFECT_PLANETARY_GUN_HIT_DESTROYED"
            label = "EFFECT_PLANETARY_GUN_LABEL"
            icon = "icons/sitrep/combat_destroyed.png"
            parameters =
            [
               tag = "planet" data = Source.PlanetID
               tag = "building" data = Source.ID
               tag = "target" data = Target.Owner
               tag = "ship" data = Target.ID
               tag = "rawtext" data = ((60  / (20 + Target.Shield * 4) ) * (CurrentTurn / 20 + 4) )
            ]
            empire = Source.Owner
         //
         // msg to the player hit
         //
         GenerateSitrepMessage
            message = "EFFECT_PLANETARY_GUN_DESTROYED_ME"
            label = "EFFECT_PLANETARY_GUN_LABEL"
            icon = "icons/sitrep/combat_destroyed.png"
            parameters =
            [
               tag = "planet" data = Source.PlanetID
               tag = "building" data = Source.ID
               tag = "ship" data = Target.ID
            ]
            empire = Target.Owner
      ]
      else = If condition = and
      [
         // damage visible ship check
         VisibleToEmpire empire = Source.Owner
         Structure low = ((60  / (20 + Target.Shield * 4) ) * (CurrentTurn / 20 + 4) )
      ]
      effects =
      [       
     
         SetStructure value = Value -((60  / (20 + Target.Shield * 4) ) * (CurrentTurn / 20 + 4) )
         SetFuel value = Value -(.5+ Target.MaxFuel / 5)
         
         //   
         // msg to the player firing the gun
         //
         GenerateSitrepMessage
            message = "EFFECT_PLANETARY_GUN_HIT"
            label = "EFFECT_PLANETARY_GUN_LABEL"
            icon = "icons/meter/damage.png"
            parameters =
            [
               tag = "planet" data = Source.PlanetID
               tag = "building" data = Source.ID
               tag = "target" data = Target.Owner
               tag = "ship" data = Target.ID
               tag = "rawtext" data = ((60  / (20 + Target.Shield * 4) ) * (CurrentTurn / 20 + 4) )
               tag = "targethp" data = Target.Structure
            ]
            empire = Source.Owner
           
         //   
         // msg to the player that was hit
         //
         GenerateSitrepMessage
            message = "EFFECT_PLANETARY_GUN_HIT_ME"
            label = "EFFECT_PLANETARY_GUN_LABEL"
            icon = "icons/meter/damage.png"
            parameters =
            [
               tag = "planet" data = Source.PlanetID
               tag = "building" data = Source.ID
               tag = "rawtext" data = ((60  / (20 + Target.Shield * 4) ) * (CurrentTurn / 20 + 4) )
               tag = "ship" data = Target.ID
            ]
            empire = Target.Owner
      ]
      //
      // Cloaked ships
      //
      else = If condition = and
      [
         // destroy cloak check
         Not VisibleToEmpire empire = Source.Owner
         Structure high = ((60  / (20 + Target.Shield * 4) ) * (CurrentTurn / 20 + 4) )
         Random probability = 0.33
      ]
      effects =
      [
     
         Destroy
         
         //
         // cloak destroyed message
         //
         GenerateSitrepMessage
            message = "EFFECT_PLANETARY_GUN_HIT_DESTROYED_CLOAK"
            label = "EFFECT_PLANETARY_GUN_LABEL"
            icon = "icons/sitrep/combat_destroyed.png"
            parameters =
            [
               tag = "planet" data = Source.PlanetID
               tag = "building" data = Source.ID
               tag = "target" data = Target.Owner
               tag = "ship" data = Target.ID
            ]
            empire = Source.Owner
           
         //
         // msg to the player hit
         //
         GenerateSitrepMessage
            message = "EFFECT_PLANETARY_GUN_DESTROYED_ME"
            label = "EFFECT_PLANETARY_GUN_LABEL"
            icon = "icons/sitrep/combat_destroyed.png"
            parameters =
            [
               tag = "planet" data = Source.PlanetID
               tag = "building" data = Source.ID
               tag = "ship" data = Target.ID
            ]
            empire = Target.Owner
      ]
      else = If condition = and
      [
         // damage cloak check
         Not VisibleToEmpire empire = Source.Owner
         Structure low = ((60  / (20 + Target.Shield * 4) ) * (CurrentTurn / 20 + 4) )
         Random probability = 0.33
      ]
      effects =
      [
     
         SetStructure value = Value -((60  / (20 + Target.Shield * 4) ) * (CurrentTurn / 20 + 4) )
         SetFuel value = Value -(.5+ Target.MaxFuel / 5)
         
         //
         // cloak damaged message
         //
         GenerateSitrepMessage
            message = "EFFECT_PLANETARY_GUN_HIT_CLOAK"
            label = "EFFECT_PLANETARY_GUN_LABEL"
            icon = "icons/meter/damage.png"
            parameters =
            [
               tag = "planet" data = Source.PlanetID
               tag = "building" data = Source.ID
               //tag = "rawtext" data = ((60  / (20 + Target.Shield * 4) ) * (CurrentTurn / 20 + 4) )
               tag = "target" data = Target.Owner
               tag = "ship" data = Target.ID
            ]
            empire = Source.Owner
           
         //   
         // msg to the player that was hit
         //
         GenerateSitrepMessage
            message = "EFFECT_PLANETARY_GUN_HIT_ME"
            label = "EFFECT_PLANETARY_GUN_LABEL"
            icon = "icons/meter/damage.png"
            parameters =
            [
               tag = "planet" data = Source.PlanetID
               tag = "building" data = Source.ID
               tag = "rawtext" data = ((60  / (20 + Target.Shield * 4) ) * (CurrentTurn / 20 + 4) )
               tag = "ship" data = Target.ID
            ]
            empire = Target.Owner
      ]
      else =
      [ 
     
         //
         // cloak missed message
         //
         GenerateSitRepMessage
            message = "EFFECT_PLANETARY_GUN_MISSED_CLOAK"
            label = "EFFECT_PLANETARY_GUN_LABEL"
            icon = "icons/meter/ammo.png"
            parameters =
            [
               tag = "planet" data = Source.PlanetID
               tag = "building" data = Source.ID
            ]
      ]
   ]
]
icon = "icons/meter/damage.png"

#include "/scripting/common/priorities.macros"
#include "/scripting/common/base_prod.macros"


en.txt additions
Code:
DEF_PLANET_GUN
Planetary Gun
 
DEF_PLANET_GUN_DESC
'''A planetary gun these massive brute force weapons can fire at enemy ships in the system. Hit's from it may also reduce a enemy's power or fuel crippling it and leaving it unable to escape. The gun is slowly upgraded over time. Such a weapon makes occupying a enemy system with one, more difficult. Some argue that such a gun diverts time and resources away from other needed military offensive weaponry, as well as industrial ship production ability. However it can be used tactically to help fortify a critical system. It could be used offensively if installed at a outpost on a large asteroid, in a enemy system.'''

BLD_PLANETARY_GUN
Planetary Gun

BLD_PLANETARY_GUN_DESC
'''A planet defense gun is capable of firing a highly charged shot at it's target, hit's on un-shielded or larger ships typically result in more damage. Due to its nature hit's may drain power as well leaving targets crippled, each gun in a system may fire once per turn.'''

EFFECT_PLANETARY_GUN_LABEL
Planetary Gun

EFFECT_PLANETARY_GUN_HIT
At %planet% the %building% fired on and Hit %empire:target% ship %ship% with %rawtext:targethp% hp causing %rawtext% damage.

EFFECT_PLANETARY_GUN_HIT_DESTROYED
At %planet% the %building% fired on and Destroyed the %empire:target% ship %ship% with a shot for %rawtext% damage.

EFFECT_PLANETARY_GUN_HIT_CLOAK
The %planet% the %building% fired a blind shot and Hit the %empire:target% cloaked ship %ship%.

EFFECT_PLANETARY_GUN_HIT_DESTROYED_CLOAK
The %planet% the %building% fired a blind shot and Destroyed the %empire:target% cloaked ship %ship%.

EFFECT_PLANETARY_GUN_MISSED_CLOAK
At %planet% the %building% fired a blind shot at a suspected cloaked target but scored no hit.

EFFECT_PLANETARY_GUN_HIT_ME
At %planet% the %building% fired on and Hit your ship %ship% causing %rawtext% damage.

EFFECT_PLANETARY_GUN_DESTROYED_ME
At %planet% the %building% fired on and Destroyed your ship %ship%.



___________________________________________________________________
The original starting post

I have a couple in general questions as well as some specific problems as examples.

I've been for the last couple days trying to get a script to work but the real problem is i don't fully understand how to control the flow of the script to get the results i want. The results i get are not as i desire and not a total failure either the problem is really that things are not exactly always clear as to what they will do.

For example for a planet gun, i copied and altered the mine code primarily so i could see the output in the sitrep. In particular functional control of what the output will be however eludes me. As to what is actually happening, not all of the enemy ships are hit, yet neither is the expected number for 2 guns vs more then one enemy fleet. I might get multiple hits or just two it seems to vary depending on the composition and number of enemy fleets. The code is at the bottom.

The intent of the script is as follows...
For each gun on a planet in each system i want it to fire on one ship out of all enemy fleets that is not allied to the owner of that gun in the same system as the gun. Essentially i want foreach gun to fire on a single enemy ship in the same system.

Now i thought this snippet from the code at the bottom would solve the "select 1 ship from all target fleets problem", but im not sure it does what i would think it should do.
Code:
scope = NumberOf number = 1 condition = And [
Ship


There are some basic questions that are really hard to get without clear definition, elaboration or example.

If i want to get one ship out of all fleets must i first get one fleet then one ship from it ?
What is the practical usage difference between activation vs scope ? a example would help.
Effect firing depends on scope, or activation, or if both are used,or also location, or it depends on what ? E.G. script in Effect can be override or limited or ignored by script in ?
What has priority over what. What is passed to what as a result ?

Which side of the operators returns or passes or does it depend ?
Ship > ContainedBy And [ > System > Contains And [
Ship < ContainedBy And [ < System < Contains And [

Ship <> ContainedBy And [ (arg1 and arg 2) ] OR [ (arg1 and not arg 2) ]
Limits searches to ships and Gets ships that match the containedBy and or arguments ?

The structural idea...

Things are either a container or a object or they are both ?
A Fleet is a container.
A Fleet is a object.
A Fleet can be both ?

The code.

The portion that seems to be problematic is shown with the macro manually copied into place, below for clarity, with the macro inputs as they would be typically used directly.
Code:
EG_PLANET_GUN
'''// Empire owned planet, damage enemy ship; sitreps issued below
EffectsGroup
scope = NumberOf number = 1 condition = And
[
    Ship
    ContainedBy And
    [
          System
          Contains And
          [
              Building name = "BLD_PLANET_GUN"
              OwnedBy empire = Source.Owner
          ]
          Or
          [
            OwnedBy affiliation = EnemyOf empire = Source.Owner
            Unowned
          ]
             Structure low = 5 + 0.0001  // low?
    ]
    activation = Not Unowned
    stackinggroup = "DEF_GUN_DAMAGE_STACK"
    priority = 50
    effects =
    [
       SetStructure value = Value - 3
    ]


The building i made so that, it will later have a effect of firing once per turn on enemy fleets in system.
Code:
BuildingType
    name = "BLD_PLANET_GUN"
    description = "BLD_PLANET_GUN_DESC"
    buildcost = 25
    buildtime = 5
    location = And
    [
        Planet
        Not Contains Building name = "BLD_PLANET_GUN"
        Not Planet type = [GasGiant]
        OwnedBy empire = Source.Owner
    ]
    effectsgroups =
    [
        [[EG_PLANET_GUN(5,55,EMPIRE)]]
    ] //Priority deliberately not a macro and before all priority macros
    icon = "icons/ship_parts/spinal_antimatter.png"


(this is about as close as i have gotten without either errors or even worse behavior resulting)


Last edited by xlightwavex on Thu Oct 06, 2016 6:43 pm, edited 31 times in total.

Top
 Profile  
 
PostPosted: Wed Sep 21, 2016 3:35 am 
Offline
Programmer

Joined: Sun Feb 14, 2016 12:08 am
Posts: 359
Quote:
What is the practical usage difference between activation vs scope ?

Quote:
Effect firing depends on scope, or activation, or if both are used,or also location, or it depends on what ?

location is not specified in EffectsGroup

Description of EffectsGroup:
universe/Effect.h:29 wrote:
/** 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.


Scope is for selecting objects as targets, Activation is for checking if the EffectsGroup applies each turn.

Code:
scope = And [
    Planet type = Asteroids
    WithinStarlaneJumps high = 3 condition = Source
]
activation = OwnerHasBuilding name = "ASTEROID_MAGNET"
effects = SomeEffect

scope determines that the effects will apply to all asteroids within 3 jumps from the source object
activation determines that the effects only take place if the Source owner has the specified building

Code:
scope = And [
    Planet type = Asteroids
    OwnerHasBuilding name = "ASTEROID_MAGNET"
    WithinStarlaneJumps high = 3 condition = Source
]
effects = SomeEffect

The effects apply to all asteroids whose owner has the specified building, and is within 3 jumps from the source.

It is my understanding that activation should be used whenever possible, I assume scope does not need to be processed if activation fails.

Quote:
If i want to get one ship out of all fleets must i first get one fleet then one ship from it ?

Nope, "scope = Ship" applies to all ships everywhere.

Quote:
Which side of the operators returns or passes or does it depend ?

If I understand your question correctly, Ship will evaluate, then the And block for ContainedBy will evaluate before constraining those results.

Quote:
Ship <> ContainedBy And [ (arg1 and arg 2) ] OR [ (arg1 and not arg 2) ]
Limits searches to ships and Gets ships that match the containedBy and or arguments ?

Not sure what the "<>" signifies here.

Code:
Ship
    ContainedBy Or [
        And [
            arg1
            arg2
        ]
        And [
            arg1
            Not arg2
        ]
    ]

All ships containedBy (arg1 and arg2) or (ang1 and not arg2).
All ship objects are gathered, then each is checked to satisfy either (arg1 and arg2) or (arg1 and Not arg2)

A ship is automatically assigned to a fleet, even if solo, the ship might also be contained by a System.
Planets can not contain fleets/ships currently.

Code:
// param 1: int Minimum structure of target
// param 2: int_const Priority
EG_PLANET_GUN
'''// Empire owned planet, damage enemy ship; sitreps issued below
EffectsGroup
    scope = NumberOf number = 1 condition = And [
        Ship
        Not OwnedBy affiliation = AllyOf empire = Source.Owner
        Not OwnedBy affiliation = TheEmpire empire = Source.Owner  // for safety, not certain if AllyOf includes self
        ContainedBy And [
            System
                Contains And [
                    Building name = "BLD_PLANET_GUN"
                    OwnedBy empire = Source.Owner
                ]
        ]
        Structure low = @1@  // low? value must equal or be greater than
    ]
    activation = Not Unowned  // activate only if the source object is not unowned
    stackinggroup = "DEF_GUN_DAMAGE_STACK" // if more than one of these guns are in the same system, this effectsgroup will only apply any specific ship once, if all of the guns target the same ship it has the same net effect as one gun
    priority = @2@
    effects = SetStructure value = Value - 3

Not certain what "EMPIRE" was to signify in your macro.


Top
 Profile  
 
PostPosted: Wed Sep 21, 2016 9:05 am 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12041
Location: Munich
Quote:
Code:
EffectsGroup
    scope = NumberOf number = 1 condition = And [
        Ship
        Not OwnedBy affiliation = AllyOf empire = Source.Owner
        Not OwnedBy affiliation = TheEmpire empire = Source.Owner  // for safety, not certain if AllyOf includes self
        ContainedBy And [
            System
                Contains And [
                    Building name = "BLD_PLANET_GUN"
                    OwnedBy empire = Source.Owner
                ]
        ]
        Structure low = @1@  // low? value must equal or be greater than
    ]
This selects 1 ship (that meets other conditions) per source object. The selected ship needs to be in a system that contains a planet gun that the source's owner owns, but I think you really want the system that contains the source object. That is, a the gun that's firing, not ANY gun the same empire owns anywhere. Assuming the effectsgroup is only added to BLD_PLANET_GUN scripts:
Code:
ContainedBy Contains Source

or probably more efficiently:
Code:
InSystem id = Source.SystemID

Also, the ownership conditions can probably be simplified to
Code:
OwnedBy affiliation = EnemyOf empire = Source.Owner


Top
 Profile  
 
PostPosted: Wed Sep 21, 2016 10:46 pm 
Offline
Space Kraken

Joined: Mon Nov 16, 2015 5:57 am
Posts: 105
Thank you both for your help.

Quote:
The intent of the script is as follows...
...
Essentially i want For Each gun loop to fire on a single enemy ship in the same system.

To clarify yes.

If scope builds a list to effect. The desired affected targets (if that is what the word scope implies in this context ?) is a final list of enemy ships to be affected. One enemy ship should be affected, per owned gun, that is located in the same system as a owned gun.

Quote:
Code:
ContainedBy Contains Source

or probably more efficiently:
Code:
InSystem id = Source.SystemID

Also, the ownership conditions can probably be simplified to
Code:
OwnedBy affiliation = EnemyOf empire = Source.Owner


Thank you for the help as well geoff

If you look at my original posted example i am already using.
OwnedBy affiliation = EnemyOf empire = Source.Owner

I have attempted to use InSystem id = Source.SystemID , though i have little context of how to actually use it yet in usage. It seems to me that System id is a constraint to limit the matching ? However effectively the contains i have been using already should be doing the same thing shouldn't it ?

Can you give a example of how InSystem id = Source.SystemID is to be used. As well as elaborate on the function it performs in the matching of the preceding and proceeding statements ?
Or how it is different to...
Code:
System.
Contains And
[
     Building name = "BLD_PLANET_GUN"
     OwnedBy empire = Source.Owner
]


ContainedBy Contains Source

What does the keyword Source imply or elude to.

Isn't the source already the building itself ?
Which would be in a system of a source.owner of the gun ?

Code:
ContainedBy Contains Source And
[
   ... ? ...
]


How does the above differ from the below with the keyword source added ?

Code:
...
ContainsBy and [
...
  Contains and [ .... ]
]


If its the same should it be like so then in order to trim down the systems.
Code:
ContainedBy Contains Source And
[
   OwnedBy affiliation = EnemyOf empire = Source.Owner
]



Unfortunately so far after 3 days off and on i have had no success in getting this script to work in the proper way. I have been trying to get it to work as well with the help from the above posted comments and reading posts, Which does help. However usage context on the effects page is a bit limited.

Thank's again for taking your time to answer my (poorly worded) scripting questions.


Top
 Profile  
 
PostPosted: Thu Sep 22, 2016 2:07 am 
Offline
Programmer

Joined: Sun Feb 14, 2016 12:08 am
Posts: 359
Quote:
What does the keyword Source imply or elude to.

The source of the effect(s)

Quote:
Isn't the source already the building itself ?
Which would be in a system of a source.owner of the gun ?

It is, but this check limits the scope of the effect to ships within the same system as the source.
(Only target ships in the same system as the building that is firing)

If an empire owns more than one of these buildings, then without this check you potentially target ships in other owned systems with a different building of the same type.
If System-A Planet1 and System-H Planet3 both have one of these buildings, the building in System-A includes the ships in System-H for target candidates.


If you are frustrated, here is a simplified working example which you can expand on.
Note it will only target enemy ships, not unowned (monsters). Nor does it check if the building can see the target.
For unexpected events like this, you may want to give a sitrep message to any empires that are affected as well.

Code:
BuildingType
    name = "BLD_PLANET_GUN"
    description = "BLD_PLANET_GUN_DESC"
    buildcost = 25
    buildtime = 5
    location = And [
        Planet
        Not Contains Building name = "BLD_PLANET_GUN"
        Not Planet type = [GasGiant]
        OwnedBy empire = Source.Owner
    ]
    effectsgroups = [
        EffectsGroup
            scope = NumberOf number = 1 condition = And [
                Ship
                InSystem id = Source.SystemID
                OwnedBy affiliation = EnemyOf empire = Source.Owner
                Structure low = 5
            ]
            effects = SetStructure value = Value - 3
    ]
    icon = "icons/ship_parts/spinal_antimatter.png"


An example sitrep for the target owner:
Code:
GenerateSitrepMessage
    message = "SITREP_PLANET_GUN_TARGET"
    label = "SITREP_PLANET_GUN_TARGET_LABEL"
    parameters = [
        tag = "system" data = Source.SystemID
        tag = "ship" data = Target.ID
        tag = "building" data = Source.ID
        tag = "planet" data = Source.PlanetID
    ]
    empire = Target.Owner


stringtables/en.txt
Code:
SITREP_PLANET_GUN_TARGET
At %system%: the ship %ship% was damaged by the %building% from %planet%

SITREP_PLANET_GUN_TARGET_LABEL
Planetary Gun Fire - Empire Ship

_________________
Any content posted should be considered licensed GNU GPL 2.0 and/or CC-BY-SA 3.0 as appropriate.


Top
 Profile  
 
PostPosted: Thu Sep 22, 2016 4:36 am 
Offline
Space Kraken

Joined: Mon Nov 16, 2015 5:57 am
Posts: 105
It's doing the same as mine was sort of but not nearly as bad that fixed the different ships in system from guns.

Very strangely though...
Those four lines cause the inner secondary macro in mine to error saying "Scope = required" when its clearly the first thing in the macro ? I have been using it all along with no problems with it till now.

On pulling it out of the macro it then didn't throw a error, but it should have still worked without pulling it out. Anyways from what you posted i figured out what the other problem is.

I figured out a couple things though from this and mine to compare.

Priority's bugs this all up.

// though i found this note in en.txt
# New Sitreps priorities should be added to
# `default/customizations/common_user_customizations.txt`.


Activation bugs this all up.

Edit:
the italicized below was wrong and was actually a misinterpretation of the test i was running.
{
The low call... Its ok unless...

Any ship's have less hp then the low value, in that case then it selects every ship with hp lower then the low value, which in this case is the (damage value for the gun) and tosses it in and kills it. Overriding the previous NumberOf number = 1 call.

That might be a problem. I sort of like the way the low high call switch out between a custom damage and destroyed sitrep as well.
}


Can we define these scripts within the effects = [ ... in this area itself... ]


Quote:
Number low = LOW high = HIGH condition = CONDITION

Matches all objects if the number of objects that match CONDITION is greater than or equal to LOW and less than HIGH. Objects matched may or may not themselves match CONDITION.


How is this used in a condition ?


Last edited by xlightwavex on Sat Sep 24, 2016 4:48 am, edited 6 times in total.

Top
 Profile  
 
PostPosted: Thu Sep 22, 2016 7:30 am 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12041
Location: Munich
xlightwavex wrote:
If you look at my original posted example i am already using.
OwnedBy affiliation = EnemyOf empire = Source.Owner

I have attempted to use InSystem id = Source.SystemID , though i have little context of how to actually use it yet in usage. It seems to me that System id is a constraint to limit the matching ?
InSystem matches objects that have a particular system ID (are in a particular system). The system id to match is specified by the id parameter. To get the value to specify for that parameter, you use Source.SystemID, which returns the ID of the system containing the source object. The scope condition is evaluated for every instance of the building type you're scripting that exists in the universe, so if there are two big guns in your empire, the scope will be evaluated separately for each of them, once with each of them as the source object.
Quote:
Can you give a example of how InSystem id = Source.SystemID is to be used.
There are many example uses in the existing scripts, including: https://github.com/freeorion/freeorion/ ... cs.txt#L18
It is generally used to limit a condition to match objects in the same system as the source object.
Quote:
As well as elaborate on the function it performs in the matching of the preceding and proceeding statements ?
I don't know what you mean by "the matching of the preceding and proceeding statements".
Quote:
Or how it is different to...
As [edit]dbenage-cx[/edit] noted, there is a difference between matching ships in any systems that contain a building of a particular type, and matching ships in the system that contains an individual building (eg. the source object). If you want a gun to fire on ships in the same system as the individual gun that is "firing", then you need to filter by where that individual gun (the source object) is located, not by where any copy of that type of gun is located.


Top
 Profile  
 
PostPosted: Thu Sep 22, 2016 8:57 am 
Offline
Space Kraken

Joined: Mon Nov 16, 2015 5:57 am
Posts: 105
Quote:
InSystem matches objects that have a particular system ID (are in a particular system). The system id to match is specified by the id parameter. To get the value to specify for that parameter, you use Source.SystemID, which returns the ID of the system containing the source object. The scope condition is evaluated for every instance of the building type you're scripting that exists in the universe, so if there are two big guns in your empire, the scope will be evaluated separately for each of them, once with each of them as the source object.

Quote:
I don't know what you mean by "the matching of the preceding and proceeding statements"
I should have said how it changes the nature of the instructions i guess.

Basically you answered the above question with your next answer.
Quote:
Ship
System Contains ... ect...
OwnedBy affiliation = EnemyOf empire = Source.Owner

Ship // preceding
InSystem id = Source.SystemID
OwnedBy affiliation = EnemyOf empire = Source.Owner // proceeding

Quote:
Or how it is different to...

Quote:
As xlightwavex noted, there is a difference between matching ships in any systems that contain a building of a particular type, and matching ships in the system that contains an individual building (eg. the source object). If you want a gun to fire on ships in the same system as the individual gun that is "firing", then you need to filter by where that individual gun (the source object) is located, not by where any copy of that type of gun is located.


Which, InSystem id = Source.SystemID does so by changing the context of how the source is used right. or in this example case the gun.

One more thing i keep forgetting to ask about Target usage in effects.

Quote:
Target

Matches the target object of an effect. This can be used within effect definitions, but not within scope or activation condition definitions, as when those conditions are evaluated, the target object hasn't yet been determined.


Is there a example of its use as well ?
Or can you elaborate on what kinds of things this can be used to do or when it might be helpful ?

Thanks dbenage as well, you have really been helping me out.
So right now this almost is working the high low values are turning out to be a bit of a problem though im going to try to solve that with the stackgroup, after testing it it a little more.


Last edited by xlightwavex on Thu Sep 22, 2016 9:18 am, edited 1 time in total.

Top
 Profile  
 
PostPosted: Thu Sep 22, 2016 9:11 am 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12041
Location: Munich
Quote:
Quote:
If you want a gun to fire on ships in the same system as the individual gun that is "firing", then you need to filter by where that individual gun (the source object) is located, not by where any copy of that type of gun is located.

Which, InSystem id = Source.SystemID does so by changing the context of how the source is used right. or in this example case the gun.
I don't know what "changing the context of how the source is used" or "changes the nature of the instructions" mean.

Source on its own is a condition that matches the source object (one instance of the gun for which the effects are currently being processed. It will be a different instance of the gun at other times when other instances' effects are being processed.).

Contains Source matches any object that contains the source object (the system and the planet the gun is in and on).

ContainedBy Contains Source matches any object in the same system as the source object (the source object itself, any fleets and ships also in the system, any other buildings or planets in the same system including the planet it's on).

Source.SystemID is not a condition; rather, it returns a number, which can be used as a parameter to an effect or condition that accepts number parameters.

InSystem id = Source.SystemID is a condition, which takes a single parameter called id, which is a number, and which is using the ID of the system that contains the source object as the value of that parameter. This condition will thus match any object in the same system as the source object, (the same objects as the ContainedBy Contains Source example).

InSystem id = 5 would also work, but would match objects in the system with ID 5. This is not very useful in a script, because you generally don't know before a game is started what system has id 5 (or if there even is such a system in the universe).

(There are a few quirks I'm not detailing, but this is the relevant situation for a building such as you're scripting.)


Top
 Profile  
 
PostPosted: Thu Sep 22, 2016 10:46 am 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12041
Location: Munich
xlightwavex wrote:
Is there a example of [the use of Target as a condition] as well ?
Not that I found with a quick search.
Quote:
Or can you elaborate on what kinds of things this can be used to do or when it might be helpful ?
You could use it to do something like a tech giving a bonus to some ship meter dependent on how many other ships were around it. The "Target" condition would be used as a subcondition to another condition inside a calculation that takes a condition as a parameter.

There are various uses of Target.Population to calculate some other meter modification, but that's not using Target as a condition.
xlightwavex wrote:
Quote:
Number low = LOW high = HIGH condition = CONDITION

Matches all objects if the number of objects that match CONDITION is greater than or equal to LOW and less than HIGH. Objects matched may or may not themselves match CONDITION.
How is this used in a condition ?

Code:
scope = And [
    Planet
    Number low = 10 condition = Ship
]
Matches all planets, if there are at least 10 ships in the universe. Otherwise matches nothing.


Top
 Profile  
 
PostPosted: Fri Sep 23, 2016 12:18 pm 
Offline
Space Kraken

Joined: Mon Nov 16, 2015 5:57 am
Posts: 105
So this is basically working. Here is the script, with the comments left in they can be deleted.

I thought it had a problem cause i thought it was killing a bunch of ships in one of my saves here it was an ai starting a 3 way battle that tripped me up.

Edit: there is still a couple minor problems with this.

Placed the current code at the top of the first post.

Thinking ill try to make a ship that can drop the building on a uninhabited planet with a outpost or something the effectgroups and effect scripting is still pretty tough to understand. I might try to make a ship part maybe a weapon that eats the enemy's fuel up or an orbital version of the gun like this maybe for another exercise.

A starbase that is actually a ship would be a nice counterpart to this gun, something that has value that could get picked off in orbit like it can produce industry points or something, say you can only have one per system make it so it cant move ect.

btw what did you guys make the ships with they look modeled ?


Last edited by xlightwavex on Sun Sep 25, 2016 5:58 am, edited 7 times in total.

Top
 Profile  
 
PostPosted: Fri Sep 23, 2016 1:53 pm 
Offline
Release Manager, Design
User avatar

Joined: Wed Nov 16, 2011 12:56 pm
Posts: 4288
Location: Sol III
xlightwavex wrote:
btw what did you guys make the ships with they look modeled ?
Whatever software the people who contributed those graphics used. What we recommend using is Blender, and we prefer models being provided in the Blender format (.blend files).


Top
 Profile  
 
PostPosted: Fri Sep 23, 2016 2:07 pm 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12041
Location: Munich
xlightwavex wrote:
Code:
               // humm is thier a way to save the damage in a variable ?
               // like
               // temp.value1 = ( 4 + RandomNumber(1.0, 5.0) )
               // to later pass it to a shiphull tag
No.
Quote:
Id also like to pass the before and after hull hp into the message ?
Not possible as far as I know / recall.
Quote:
but how do i pass in both the source empire and target empire ?
Source.Owner and Target.Owner don't work?
Quote:
//tag = "shiphull" data = Target.Structure // is shiphull the correct word
Not sure what you're trying to do, but if the tag is "shiphull" then the data should be the name of a hull type.


Top
 Profile  
 
PostPosted: Fri Sep 23, 2016 5:53 pm 
Offline
Space Kraken

Joined: Mon Nov 16, 2015 5:57 am
Posts: 105
Quote:
Source.Owner and Target.Owner don't work?

Not sure what you're trying to do, but if the tag is "shiphull" then the data should be the name of a hull type.


Two things really...

I wanted to get a random number early on and store that in a effect related (or locally persisting) variable, for use in all the shown math operations that would be done in the script after the first use. Including those to be passed to the tags later on, though i doubted that was likely possible.

source.UserValue = ((CurrentTurn / 20 + Target.MaxStructure / 6) + RandomNumber(1.0, 3.0) +5 - Target.Shield)
Something like that i could reference from the first occurrence of the formula were it is set to be used for the rest after.

You can see how random number changing on each call after the first with high low doing what it is doing becoming a problem, as well as for the damage output message text similarly.



Second thing...

I was trying to cheat with the "shiphull" tag and assign from target.owner to it because i was already using "empire" for the source.owner.

Basically all the same question relating to tags on how to store a value or string to be passed either from the effectgroup to a effect then into a tag. Or from the source and target variables of arbitrary type, to source target related tags of the same type i suppose.

for instance...

tag = "empire" data = Source.Owner
tag = "target_empire ?" data = Target.Owner

The %empire% %building% on %planet% fired on the %target_empire% ship %ship% for %rawtext% damage, destroying the ship.

Not really a big deal, just wondering if their was more tags or some way to specify source and target into tags from both owner variables to use in a message didn't know if i was missing something or not.

Edit just saw the below reply, i will try and post the result as a reply.


Last edited by xlightwavex on Fri Sep 23, 2016 6:29 pm, edited 10 times in total.

Top
 Profile  
 
PostPosted: Fri Sep 23, 2016 6:11 pm 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12041
Location: Munich
xlightwavex wrote:
tag = "empire" data = Source.Owner
tag = "target_empire ?" data = Target.Owner
There was something that I think does what you want for that added a while ago:

https://github.com/freeorion/freeorion/ ... baa278be12

but I don't think it's been used. From what I can see, you'd specify tag = "source" and tag = "target" in the script, and then put %empire:source% and %empire:target% in the stringtable. Haven't tested this, though.

Edit: this post has an example in the test patch: viewtopic.php?f=9&t=8819&p=69183#p69183


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 50 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group