Author Topic: Damage type and Resist mod is this possible ?  (Read 916 times)

celludriel

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Damage type and Resist mod is this possible ?
« on: April 03, 2015, 12:25:45 PM »
I've been thinking about something. After quite a few games now, I'm missing something and was wondering if I could get my hands dirty and jump into a mod.

My main objective is to start simple
- Create three types of damage: Heat, Corrosive, Particle (names just placeholders)
- Create three types of resist: Anti heat, Anti corrosive, Anti particl (names just placeholders)

Then take those damages and resists and create weapons and armor with them. For each damage type a variation in laser , missile, torpedo. Just reusing existing art maybe giving it a new colour or something in that line.

heat would do 150% damage against anti corrosive, 50% vs anti heat, 100% vs particle
corrosive would do 100% damage against anti heat, 50% vs anti corrosive, 150% vs particle
particle would do 150% damage against anti heat, 50% vs anti particle, 100% vs corrosive

A simple tri damage system

Just wondering before I start learning everything if this is possible. I'm a professional java dev with extensive knowledge of C# and god knows how many script languages I encountered over the years.

GGLucas

  • Dr. Evil
  • BMS Staff
  • Delusional
  • *
  • Posts: 1877
  • Karma: +300/-6
    • View Profile
Re: Damage type and Resist mod is this possible ?
« Reply #1 on: April 03, 2015, 01:10:41 PM »
Sure, this is possible. The main files you'll want to be looking at are data/effectors/*, which define turret behaviors. data/effects/*, which define the effects applied by projectiles to the things they hit, as well as the effects that armor uses for damage resistance, and scripts/server/combat.as, which holds all the script code that deals with the implementation of the effects. Then you'll want to change/create new subsystems in data/subsystems that actually use the turrets to implement weapons or the resist effects to implement armors.

celludriel

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Damage type and Resist mod is this possible ?
« Reply #2 on: April 03, 2015, 01:16:39 PM »
Well I'm on the right track then those where the files I already started reading especially the combat.as.  Some things I'll have to wrap my head around though.  I see all the methods and the implementations are quite easy to understand once I learn the syntax of AngelScript I'll figure out the few lines I don't get.  However I do not quite understand yet who calls the methods in combat.as.  I assume the game engine calls those on certain events (aka an onHit() or something)

Another thing I'm looking for now is a decent IDE for angelscript, seems eclipse has no plugin for it so I'll need to be looking elsewhere :(

edit:

I think I understand how the methods get called now. 

Effect: Damage
   Value: Amount

   End: combat::Damage

combat:: is an object of the combat.as class I suppose and Damage is calling the damage method passing in an event and Amount.  Seems quite straightforward.  There doesn't seem to be any type safety though ?  Value can be anything then ?
« Last Edit: April 03, 2015, 01:25:58 PM by celludriel »

GGLucas

  • Dr. Evil
  • BMS Staff
  • Delusional
  • *
  • Posts: 1877
  • Karma: +300/-6
    • View Profile
Re: Damage type and Resist mod is this possible ?
« Reply #3 on: April 03, 2015, 01:33:23 PM »
Values passed through effects can only ever be doubles. Generally they're filled in by the block in the Effector or Subsystem that applies the Effect.

celludriel

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Damage type and Resist mod is this possible ?
« Reply #4 on: April 03, 2015, 01:53:40 PM »
I see, I compared the effects with the combat.as and indeed only doubles.  Seems quite straightforward to make a method then for each type of damage I like to create. 

evt.target.damage(dmg, -1.0, evt.direction);

This seems to be the method call to the target object for passing on damage, so if I want to program the damage mitigation for special type of armor I need to figure out what hex just got hit, what type it is, and then subtract/add an x amount of damage for the final amount of damage.

From what I can gather Event has a method const Subsystem@ get_destination( )  so I assume this will be the hex being hit and I precompute the final damage and pass that on to evt.target.damage() ?

I'm just wondering if evt.target.damage does some other kind of damage computing after I assign the DamageEvent to it.  I might be posing some beginner questions, but atm I find it hard to find reference material.  Each google search gives me results for star ruler 1 :(
« Last Edit: April 03, 2015, 02:01:48 PM by celludriel »

GGLucas

  • Dr. Evil
  • BMS Staff
  • Delusional
  • *
  • Posts: 1877
  • Karma: +300/-6
    • View Profile
Re: Damage type and Resist mod is this possible ?
« Reply #5 on: April 03, 2015, 02:08:22 PM »
evt.target.damage is the internal damage resolver. You don't actually know which hex is going to get damaged beforehand, and you have no way to intercept that. The way you're supposed to interact with it is by setting flags on the DamageEvent's flags member, and then checking for that in the subsystem that does the damage resisting. For that, you can check how the DamageResist and ReduceDamage effect and functions work.

celludriel

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Damage type and Resist mod is this possible ?
« Reply #6 on: April 03, 2015, 02:39:37 PM »
Aha ... I start to see the connection.  There is quite some liberal use of bitoperators switch(evt.flags & typeMask).  Never been a big fan of them it works though.

I'll have enough information to create a small prototype.  A weapon that adds a fixed amount of damage and an armor that subtracts a fixed value when it finds a DT_MYSPECIAL flag seems like a good first test.  Is there an equivalent of System.out.println("debug line") in the api or some kind of logging framework ?

Thanks for the info sofar
« Last Edit: April 03, 2015, 02:41:23 PM by celludriel »

GGLucas

  • Dr. Evil
  • BMS Staff
  • Delusional
  • *
  • Posts: 1877
  • Karma: +300/-6
    • View Profile
Re: Damage type and Resist mod is this possible ?
« Reply #7 on: April 03, 2015, 02:59:06 PM »
You can just call print("test"); to log out messages to the console and to Documents/My Games/Star Ruler 2/log.txt, the same places where script errors will be logged.

celludriel

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Damage type and Resist mod is this possible ?
« Reply #8 on: April 03, 2015, 05:49:21 PM »
Well I've been working on the basics but seems I must have missed something.  I've started on just copying most of Laser and just change a small amount of things.  I'm able to add this new laser to a design but it does not fire.

I've added the following:

combat.as
Code: [Select]
void SpecialDamage(Event& evt, double Amount) {
print("Calling special damage");
DamageEvent dmg;
dmg.damage = (Amount * double(evt.efficiency) * double(evt.partiality)) + 5000;
dmg.partiality = evt.partiality;
dmg.impact = evt.impact;

@dmg.obj = evt.obj;
@dmg.target = evt.target;
dmg.source_index = evt.source_index;
dmg.flags |= DT_Energy | ReachedInternals;

evt.target.damage(dmg, -1.0, evt.direction);
}

beams.txt
Code: [Select]
Effector: SpecialLaser
Value: Range
Value: DPS
Value: Duration
Value: Cooldown
Value: Tracking
Value: SupplyCost = 0
Value: FireArc = pi

Range: Range
Lifetime: Duration
Tracking: Tracking
FireArc: FireArc

TargetAlgorithm: SingleTarget
CanTarget: isEnemy && isDamageable
AutoTarget: isEnemy && (isShip || (isOrbital || isColonyShip || isCivilian || isFreighter) * 0.5)

EfficiencyMode: Duration Partial
Activation: VariableTimed(Cooldown+Duration, 0.25)
OnTrigger: combat::WeaponFire(SupplyCost)

Effect: SpecialDamage
Amount = DPS

GfxSize: 0.3
FirePitchVariance: 0.06
FireSfx: laser_fire
Material: Laser
ImpactGfx: ImpactFlareLaserRed
TrailCol: ff3300aa, ff33ffaa

Skin: Skin1
ImpactGfx: ImpactFlareLaserGold
TrailCol: ffee99aa, ffee99aa

Skin: Skin2
ImpactGfx: ImpactFlareLaserBlue
TrailCol: 00ccddaa, 00ccddaa

Skin: Skin3
ImpactGfx: ImpactFlareLaserViolet
TrailCol: ff99ffaa, ff99ffaa

Skin: Hyper
ImpactGfx: ImpactFlareHyperLaserViolet
TrailCol: ff00ffff, ff00ffff

effects.txt
Code: [Select]
Effect: SpecialDamage
Value: Amount

End: combat::SpecialDamage

Created my own SpecialLaser.txt
Code: [Select]
Subsystem: SpecialLaser
Name: #SPECIAL_LASER_NAME
Description: #SPECIAL_LASER_DESC
BaseColor: #ff0000
Picture: SubsystemButtonArt::7
Elevation: 2

Tags: BaseCost
Tags: BeamBase, Rotatable, HexLimitArc, Category:Weapons
Tags: ExteriorCore, Weapon, DefaultUnlock, IsBeamWeapon, HasInternals, MainDPS
Hull: Flagship, Station

Size := HexSize * Hexes
BeamDPS := 5.0 * Size
Duration := 6
Cooldown := 6
Range := Size + 450
Tracking := 0.5
SupplyCost := Size * 0.75
FireArc := 0.25 * pi
PowerUse := 5 * Size

Hex.HP := 12 * HexSize
Hex.Resistance := 0.2
Hex.Mass := HexSize
TypeColor: #ff0000

Requires:
Command = 1
Power = PowerUse

Module: Default

Module: Core
Hex.HP := Hex.HP * 2
Hex.BuildCost := 5.0 * Hex.BuildCost
Hex.Mass := 5.0 * Hex.Mass

Sprite: Laser::0
DrawMode: 1

Hex.DamageResist := ShipSize / 64.0
Effect: DamageResist
Resist = Hex.DamageResist

Effector: SpecialLaser
Range = Range
DPS = BeamDPS
Duration = Duration
Cooldown = Cooldown
Tracking = Tracking
SupplyCost = SupplyCost * Duration
FireArc = FireArc

Did I miss something ?  Do I need to declare that there is a new method SpecialDamage in an interface or something ?

GGLucas

  • Dr. Evil
  • BMS Staff
  • Delusional
  • *
  • Posts: 1877
  • Karma: +300/-6
    • View Profile
Re: Damage type and Resist mod is this possible ?
« Reply #9 on: April 03, 2015, 06:17:18 PM »
You didn't copy over the PhysicalType: Beam line from the laser effector to yours, which means the effector doesn't know what it is or how to fire.

celludriel

  • Newbie
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Damage type and Resist mod is this possible ?
« Reply #10 on: April 04, 2015, 02:27:31 AM »
Indeed, weird I did a full copy.  Must have gone lost switching from the ingame editor to my text editor and back.  Is there some kind of validator mechanic that can tell if a template is missing a required variable ?  I'm thinking something in the line of an XSD for the several templates.

I'll at least let a diff run over both files next time, so I can see my changes more clearly.  I've got it to work though but I had to figure out something else first ?  I first tried making this folder <root>/mods/test/scripts/server/  and put a copy of combat.as there.  But my ships still wouldn't shoot.  It's only later I noticed I had to restart my game to get it to work.

Could it be possible that when a call is made to a method in AS and it can't be found, we get a notice in the error.log ?  This would have saved me quite some time figuring things out why they don't work.  I assume you'll have some kind of runtime exceptions when a call is made to something none existing ?  It's not like we need the entire stacktrace just something in the line "method SpecialDamage(Evt, double) not found".

I'm trying to make my SpecialDamage method more generic.  I've added a value DamageType to my subsystem and appended the DamageType enum with X_DT.  Now I'm trying to fetch the value DamageType from the subsystem by using the event. evt.source gives me the subsystem but how can I fetch a value from it now ?  There doesn't seem to be a get_value(String name) method on either Object or Subsystem ?  Do I need to use some kind of reflection API ?  I'll experiment a bit further in the meantime


« Last Edit: April 04, 2015, 05:52:54 AM by celludriel »