1 /* Apply upgrades to ranged weapons */
2 
3 #appendto Bow
4 #appendto Blunderbuss
5 #appendto GrenadeLauncher
6 #appendto Javelin
7 
8 local orig_shooting_strength;
9 
Initialize(...)10 public func Initialize(...)
11 {
12 	var r = _inherited(...);
13 	this.gidl_base_animation_set = this.animation_set;
14 	Gidl_UpdateLoadTimes();
15 	orig_shooting_strength = this.shooting_strength;
16 	Guardians_UpdateShootingStrength();
17 	return r;
18 }
19 
Entrance(...)20 public func Entrance(...)
21 {
22 	Gidl_UpdateLoadTimes();
23 	Guardians_UpdateShootingStrength();
24 	return _inherited(...);
25 }
26 
Gidl_UpdateLoadTimes()27 public func Gidl_UpdateLoadTimes()
28 {
29 	if (!Contained() || !g_homebases) return false;
30 	var base = g_homebases[Contained()->GetOwner()];
31 	if (base)
32 	{
33 		var base_set = this.gidl_base_animation_set, new_set;
34 		this.animation_set = new_set = new base_set {};
35 		if (GetType(base_set.LoadTime)) new_set.LoadTime = Max(1, base_set.LoadTime * base.tech_load_speed_multiplier / 100);
36 		if (GetType(base_set.LoadTime2)) new_set.LoadTime2 = Max(1, base_set.LoadTime2 * base.tech_load_speed_multiplier / 100); // Bow: add arrow
37 		if (GetType(base_set.ShootTime)) new_set.ShootTime = Max(1, base_set.ShootTime * base.tech_load_speed_multiplier / 100);
38 		if (GetType(base_set.ShootTime2)) new_set.ShootTime2 = Max(1, base_set.ShootTime2 * base.tech_load_speed_multiplier / 100);
39 		if (new_set.ShootTime <= new_set.ShootTime2)
40 			new_set.ShootTime = new_set.ShootTime2 + 1;
41 	}
42 	return true;
43 }
44 
Guardians_UpdateShootingStrength()45 public func Guardians_UpdateShootingStrength()
46 {
47 	if (!Contained() || !g_homebases) return false;
48 	if (GetID() == Blunderbuss) return false; // Update not for blunderbusses
49 	var base = g_homebases[Contained()->GetOwner()];
50 	if (base)
51 	{
52 		this.shooting_strength = orig_shooting_strength + orig_shooting_strength * base.tech_shooting_strength_multiplier / 100;
53 	}
54 	return true;
55 }
56 
Gidl_IsRangedWeapon()57 public func Gidl_IsRangedWeapon() { return true; }
58