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: Select all
/*
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"
Code: Select all
/*
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"
Code: Select all
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: Select all
scope = NumberOf number = 1 condition = And [
Ship
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: Select all
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
]
Code: Select all
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"