1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
/**
Library_RangedWeapon
Adds functionality to overload weapon speed
@author: Sven2
*/
local animation_set;
local speed_multiplier = 100;
// To be overloaded by weapon
local DefaultLoadTime = nil;
local DefaultLoadTime2 = nil;
local DefaultShootTime = nil;
local DefaultShootTime2 = nil;
public func IsRangedWeapon()
{
return true; // identify this as a ranged weapon for the AI
}
public func Initialize(...)
{
// Set initial animation speeds
if (!animation_set) animation_set = {};
SetSpeedMultiplier(speed_multiplier);
return _inherited(...);
}
public func GetReloadTime()
{
// Get weapon reload time after speed adjustments
return animation_set.LoadTime;
}
public func GetShootTime()
{
// Get shoot time after speed adjustments
return animation_set.ShootTime;
}
public func SetSpeedMultiplier(int new_multiplier)
{
// Updates the weapon speed
if (GetType(DefaultLoadTime2)) animation_set.LoadTime2 = Max(1, DefaultLoadTime2 * 100 / new_multiplier);
if (GetType(DefaultLoadTime)) animation_set.LoadTime = Max(1+animation_set.LoadTime2, DefaultLoadTime * 100 / new_multiplier);
if (GetType(DefaultShootTime2)) animation_set.ShootTime2 = Max(1, DefaultShootTime2 * 100 / new_multiplier);
if (GetType(DefaultShootTime)) animation_set.ShootTime = Max(1+animation_set.ShootTime2, DefaultShootTime * 100 / new_multiplier);
// Remember setting
this.speed_multiplier = new_multiplier;
}
public func Definition(def, ...)
{
// Editor + Scenario saving
_inherited(def, ...);
if (!def.EditorProps) def.EditorProps = {};
def.EditorProps.speed_multiplier = {
Name = "$SpeedMult$",
EditorHelp = "$SpeedMultHelp$",
Set = "SetSpeedMultiplier",
Type = "int",
Min = 1,
Max = 20000,
Save = "SpeedMultiplier",
};
}
|