File: DamageArray.h

package info (click to toggle)
spring 104.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 47,512 kB
  • sloc: cpp: 391,093; ansic: 79,943; python: 12,356; java: 12,201; awk: 5,889; sh: 1,826; xml: 655; makefile: 486; perl: 405; php: 211; objc: 194; sed: 2
file content (121 lines) | stat: -rw-r--r-- 2,520 bytes parent folder | download
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef DAMAGE_ARRAY_H
#define DAMAGE_ARRAY_H

#include <algorithm>
#include <vector>
#include "System/creg/creg_cond.h"

class float3;

class DamageArray
{
	CR_DECLARE(DamageArray)

public:
	DamageArray(float damage = 1.0f)
		: paralyzeDamageTime(0)

		, impulseFactor(1.0f)
		, impulseBoost(0.0f)

		, craterMult(1.0f)
		, craterBoost(0.0f)
	{
		SetDefaultDamage(damage);
	}


	DamageArray(const DamageArray& da) { *this = da; }
	DamageArray(DamageArray&& da) { *this = std::move(da); }

	virtual ~DamageArray() {}

	DamageArray& operator = (const DamageArray& da) {
		paralyzeDamageTime = da.paralyzeDamageTime;

		impulseFactor = da.impulseFactor;
		impulseBoost = da.impulseBoost;

		craterMult = da.craterMult;
		craterBoost = da.craterBoost;

		damages = da.damages;
		return *this;
	}
	DamageArray& operator = (DamageArray&& da) {
		paralyzeDamageTime = da.paralyzeDamageTime;

		impulseFactor = da.impulseFactor;
		impulseBoost = da.impulseBoost;

		craterMult = da.craterMult;
		craterBoost = da.craterBoost;

		damages = std::move(da.damages);
		return *this;
	}

	DamageArray operator * (float damageMult) const {
		DamageArray da(*this);

		for (unsigned int a = 0; a < damages.size(); ++a)
			da.damages[a] *= damageMult;

		return da;
	}


	int GetNumTypes() const { return damages.size(); }

	void SetDefaultDamage(float damage);
	void Set(int typeIndex, float d) { damages[typeIndex] = d; }

	float Get(int typeIndex) const { return damages[typeIndex]; }
	float GetDefault() const { return damages[0]; }

public:
	int paralyzeDamageTime;

	float impulseFactor;
	float impulseBoost;

	float craterMult;
	float craterBoost;

protected:
	std::vector<float> damages;
};


class DynDamageArray : public DamageArray
{
	CR_DECLARE(DynDamageArray)

public:
	DynDamageArray(float damage = 1.0f);
	DynDamageArray(const DynDamageArray& da) { *this = da; fromDef = false; refCount = 1; }
	~DynDamageArray();

	void PostLoad();

	DamageArray GetDynamicDamages(const float3& startPos, const float3& curPos) const;

	static const DynDamageArray* IncRef(const DynDamageArray* dda);
	static void DecRef(const DynDamageArray* dda);
	static DynDamageArray* GetMutable(const DynDamageArray*& dda);

	float dynDamageExp;
	float dynDamageMin;
	float dynDamageRange;
	bool dynDamageInverted;
	float craterAreaOfEffect;
	float damageAreaOfEffect;
	float edgeEffectiveness;
	float explosionSpeed;
	mutable int refCount;
	bool fromDef;
};

#endif