File: Script.c

package info (click to toggle)
openclonk 8.1-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 169,520 kB
  • sloc: cpp: 180,479; ansic: 108,988; xml: 31,371; python: 1,223; php: 767; makefile: 145; sh: 101; javascript: 34
file content (67 lines) | stat: -rw-r--r-- 1,745 bytes parent folder | download | duplicates (5)
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",
		};
}