Bug: Railgun, Force Lance, Station graphics

General Stars in Shadow Discussion Forum
User avatar
sven
Site Admin
Posts: 1620
Joined: Sat Jan 31, 2015 10:24 pm
Location: British Columbia, Canada
Contact:

Re: Bug: Railgun, Force Lance, Station graphics

Postby sven » Thu Mar 15, 2018 6:47 pm

harpy eagle wrote:Correct me if I'm wrong, but if you define

Code: Select all

function WeaponProperty.foo(w)
  --return stuff
end


Then any time you evaluate w.foo it will call the foo function to determine what value results?


Not exactly... The property values can be overwritten by values defined in the weapon or the weapon's weapon info table. So, for example, if we're evaluating the shield_piercing_level of a Force Lance, we should always return 2 (because that's the value defined in the Force Lance entry in WEAPONS.lua). If you have a weapon that has the "Shield Piercing" property, but no shield_piercing_level defined (like a Coilgun), you'll w.get shield_piercing_level == 1, because of the property function logic.

Re: siyoa's year-old bug, I'm *guessing* what happened was that I had a typo or missing data entry in the WEAPONS.lua entry for Force Lance. But, I think that should be fixed now...

User avatar
siyoa
Posts: 182
Joined: Fri Apr 21, 2017 3:19 pm

Re: Bug: Railgun, Force Lance, Station graphics

Postby siyoa » Thu Mar 15, 2018 7:33 pm

hi Sven,

this should be what is in current build code (I am at work and only have a copy of Lua State folder, it is about a week old, so latest released build, I think)

Code: Select all

define_weapon "Force Lance" {
  tier=3,
  sound_fun = "FORCE_LANCE",
  type = "kinetic",
  power_mult=3,
  drawer_type = 'force_beam',
  damage_fun = dmg_range(25,35),
  beam_color=("pink"),
  desc = df([=[
    Uses rapidly oscillating gravity fields to tear apart the target,
    causing large amounts of damage without the use of particles or
    projectiles that could be intercepted via energy shields.  The Shield
    Piercing ability of Force Lances is stronger than that of other kinetic
    weapons, capable of fully bypassing both [[Battle Shields]] and
    [[Force Fields]].
  ]=]),

  shield_piercing_level = 2,
  specials =set("Shield Piercing"),
--  mods = set("Rapid Fire"),
}

function WeaponProperty.shield_piercing_level(w)
  if not w:special 'Shield Piercing'
    return 0
  end
  return 1
end


so, I think what happens is that the function after Force Lance overwrites Force Lance shield_piercing_level to 1 because Force Lance has specials =set("Shield Piercing") ... I cannot upload save game at the moment, but Force Lance with this vanilla file was not piercing Force Fields and as soon as I added my "SP2" shenanigans it was piercing it ... I will try to remove specials =set("Shield Piercing") from Force Lance and just leave shield_piercing_level = 2, in Force Lance definition, then I would revert function WeaponProperty.shield_piercing_level(w) back to vanilla (i.e., remove that "SP2" if section of mine) and see if it works ... when I get home

EDIT: hmm, thinking about it more, it may not work, if Force Lance is missing specials =set("Shield Piercing"), than that function will overwrite Force Lance shield_piercing_level property to 0 ... do that function needs to exist at all ? isn't it enough to define shield_piercing_level for each weapon that needs it and be done with it ?

EDIT2: this should be able to read shield_piercing_level directly from the weapon, right ? so the function function WeaponProperty.shield_piercing_level(w) in WEAPONS.lua is not necessary ?

Code: Select all

function deal_damage(weapon, damage, ship, shield)

  -- shield damage logic

  --print('hrm', ..ship.resists_shield_piercing)

  local shield_damage_p = 1.0-
    saturate(weapon.shield_piercing_level -  ship.resists_shield_piercing)

  if shield_damage_p > 0

    local shield_damage = round | damage*shield_damage_p
    local direct_damage = damage - shield_damage

    if (ship.max_shields > 0) and ship[shield]
   
      if( weapon:special "Enveloping" )
        local d0 = damage_shield(shield_damage,ship,SHIELD_NAMES[1])
        local d1 = damage_shield(shield_damage,ship,SHIELD_NAMES[2])
        d0=max(d0,d1)
        local d1 = damage_shield(shield_damage,ship,SHIELD_NAMES[3])
        d0=max(d0,d1)
        local d1 = damage_shield(shield_damage,ship,SHIELD_NAMES[4])
        shield_damage=max(d0,d1)
      else
        shield_damage=damage_shield(shield_damage,ship,shield)
      end
 

    elseif(ship.planetary_shield)

      ship.planetary_shield_damage = ship.planetary_shield_damage or 0

      shield_damage=damage_shield(shield_damage,ship,"planetary_shield_damage")
    end

    -- recombine the direct and shield damage levels
    damage = direct_damage + shield_damage

  end
How did YOU get a key? All right, go in.

User avatar
siyoa
Posts: 182
Joined: Fri Apr 21, 2017 3:19 pm

Re: Bug: Railgun, Force Lance, Station graphics

Postby siyoa » Thu Mar 15, 2018 7:46 pm

sven wrote:Not exactly... The property values can be overwritten by values defined in the weapon or the weapon's weapon info table. So, for example, if we're evaluating the shield_piercing_level of a Force Lance, we should always return 2 (because that's the value defined in the Force Lance entry in WEAPONS.lua). If you have a weapon that has the "Shield Piercing" property, but no shield_piercing_level defined (like a Coilgun), you'll w.get shield_piercing_level == 1, because of the property function logic.

Re: siyoa's year-old bug, I'm *guessing* what happened was that I had a typo or missing data entry in the WEAPONS.lua entry for Force Lance. But, I think that should be fixed now...


just re-reading this, so the value in weapon's definition has a precedent over the function which is setting the property ? if that is the case my previous post is moot point :D
How did YOU get a key? All right, go in.

User avatar
sven
Site Admin
Posts: 1620
Joined: Sat Jan 31, 2015 10:24 pm
Location: British Columbia, Canada
Contact:

Re: Bug: Railgun, Force Lance, Station graphics

Postby sven » Thu Mar 15, 2018 7:52 pm

siyoa wrote:just re-reading this, so the value in weapon's definition has a precedent over the function which is setting the property ? if that is the case my previous post is moot point :D


Yes, it has precedence. (The details are a bit complex, but, basically, WeaponProperty is hooking into a Lua technique called "metamethods", and those methods tend to have very low-precedence -- in particular, an __index metamethod, like WeaponProperty, will only be triggered if the value we're trying to read doesn't actually exist in the underlying table.)

User avatar
siyoa
Posts: 182
Joined: Fri Apr 21, 2017 3:19 pm

Re: Bug: Railgun, Force Lance, Station graphics

Postby siyoa » Fri Mar 16, 2018 2:45 am

sooo, I removed this function from WEAPONS.lua and added a bit of a code (in shipdamage.lua or what ever the name of the file is) that if shield_piercing_level is nil, it is set to 0

Code: Select all

function WeaponProperty.shield_piercing_level(w)
  if not w:special 'Shield Piercing'
    return 0
  end
  return 1
end


now this shield_piercing_level = 2 has proper effect for Force Lance

I know what you said about precedence Sven, but it seems that that function was overwriting it
How did YOU get a key? All right, go in.

User avatar
sven
Site Admin
Posts: 1620
Joined: Sat Jan 31, 2015 10:24 pm
Location: British Columbia, Canada
Contact:

Re: Bug: Railgun, Force Lance, Station graphics

Postby sven » Fri Mar 16, 2018 4:44 am

siyoa wrote:sooo, I removed this function from WEAPONS.lua and added a bit of a code (in shipdamage.lua or what ever the name of the file is) that if shield_piercing_level is nil, it is set to 0
I know what you said about precedence Sven, but it seems that that function was overwriting it


Oh no. I think you're right. The complete precedence chain when evaluating weapon fields is actually this:

  1. Variables inside the weapon itself.
  2. Any defined WeaponProperty functions.
  3. Variables inside the weapon's associated info table (the thing in WEAPONS.lua).
  4. Any defined WeaponInfo_Property functions.
  5. Any defined WeaponMethod functions.

So, um, yes, that code is definitely buggy. I'll push an official fix in the next patch :oops: :oops:

edit: The patched code I'm currently considering looks like this:

Code: Select all

function WeaponProperty.shield_piercing_level(w)
  local shield_piercing_level in w.info
  if shield_piercing_level
    return shield_piercing_level
  end
  if not w:special 'Shield Piercing'
    return 0
  end
  return 1
end

Chasm
Posts: 568
Joined: Sat Feb 06, 2016 9:14 pm

Re: Bug: Railgun, Force Lance, Station graphics

Postby Chasm » Fri Mar 16, 2018 3:23 pm

Sven, tested your code, and force lances do pierce force fields with it used. Haven't checked to see it there are unintended results though.

User avatar
sven
Site Admin
Posts: 1620
Joined: Sat Jan 31, 2015 10:24 pm
Location: British Columbia, Canada
Contact:

Re: Bug: Railgun, Force Lance, Station graphics

Postby sven » Fri Mar 16, 2018 3:55 pm

Chasm wrote:Sven, tested your code, and force lances do pierce force fields with it used. Haven't checked to see it there are unintended results though.


Thanks for the testing. Sadly, it does appear to be buggy in the case of damage done via reactor explosions. That's fixable as well, but, the patch isn't quite as clean as the code I posted :(

User avatar
siyoa
Posts: 182
Joined: Fri Apr 21, 2017 3:19 pm

Re: Bug: Railgun, Force Lance, Station graphics

Postby siyoa » Fri Mar 16, 2018 5:00 pm

sven wrote:So, um, yes, that code is definitely buggy. I'll push an official fix in the next patch :oops: :oops:

no worries, Sven, you guys are doing great job and we are here all together to make this game the best of them all ;)
How did YOU get a key? All right, go in.


Return to “General Forum”

Who is online

Users browsing this forum: No registered users and 19 guests

cron