1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #ifndef _WEAPON_DEF_H
4 #define _WEAPON_DEF_H
5 
6 #include <map>
7 
8 #include "System/float3.h"
9 #include "Sim/Misc/DamageArray.h"
10 #include "Sim/Misc/GuiSoundSet.h"
11 #include "Sim/Projectiles/WeaponProjectiles/WeaponProjectileTypes.h"
12 
13 struct AtlasedTexture;
14 class CColorMap;
15 struct S3DModel;
16 class LuaTable;
17 
18 struct WeaponDef
19 {
20 private:
21 	CR_DECLARE_STRUCT(WeaponDef)
22 
23 public:
24 	WeaponDef();
25 	WeaponDef(const LuaTable& wdTable, const std::string& name, int id);
26 
27 	S3DModel* LoadModel();
28 	S3DModel* LoadModel() const;
29 
IsHitScanWeaponWeaponDef30 	bool IsHitScanWeapon() const {
31 		switch (projectileType) {
32 			case WEAPON_BEAMLASER_PROJECTILE:      { return true; } break;
33 			case WEAPON_LARGEBEAMLASER_PROJECTILE: { return true; } break;
34 			case WEAPON_LIGHTNING_PROJECTILE:      { return true; } break;
35 		}
36 
37 		return false;
38 	}
39 
40 public:
41 	std::string name;
42 	std::string type;
43 	std::string description;
44 
45 	unsigned int ptrailExplosionGeneratorID; // must be custom, defined by ptrailExpGenTag
46 	unsigned int impactExplosionGeneratorID; // can be NULL for default explosions
47 	unsigned int bounceExplosionGeneratorID; // called when a projectile bounces
48 
49 	GuiSoundSet fireSound;
50 	GuiSoundSet hitSound;
51 
52 	float range;
53 	float heightmod;
54 	float accuracy;            ///< INaccuracy (!) of whole burst
55 	float sprayAngle;          ///< INaccuracy of individual shots inside burst
56 	float movingAccuracy;      ///< INaccuracy (!) while owner moving
57 	float ownerExpAccWeight;   ///< if 0, accuracy is not increased with owner experience (max. 1)
58 	float targetMoveError;     ///< fraction of targets move speed that is used as error offset
59 	float leadLimit;           ///< maximum distance the weapon will lead the target
60 	float leadBonus;           ///< factor for increasing the leadLimit with experience
61 	float predictBoost;        ///< replaces hardcoded behaviour for burnblow cannons
62 
63 	DamageArray damages;
64 	float craterAreaOfEffect;
65 	float damageAreaOfEffect;
66 	bool noSelfDamage;
67 	float fireStarter;
68 	float edgeEffectiveness;
69 	float size;
70 	float sizeGrowth;
71 	float collisionSize;
72 
73 	int salvosize;
74 	float salvodelay;
75 	float reload;
76 	float beamtime;
77 	bool beamburst;
78 
79 	bool waterBounce;
80 	bool groundBounce;
81 	float bounceRebound;
82 	float bounceSlip;
83 	int numBounce;
84 
85 	float maxAngle;
86 
87 	float uptime;
88 	int flighttime;
89 
90 	float metalcost;
91 	float energycost;
92 
93 	int projectilespershot;
94 
95 	int id;
96 	int tdfId;                  ///< the id= tag in the tdf
97 
98 	bool turret;
99 	bool onlyForward;
100 	bool fixedLauncher;
101 	bool waterweapon;           ///< can target underwater objects/positions if true
102 	bool fireSubmersed;         ///< can fire even when underwater if true
103 	bool submissile;            ///< Lets a torpedo travel above water like it does below water
104 	bool tracks;
105 	bool paralyzer;             ///< weapon will only paralyze not do real damage
106 	bool impactOnly;            ///< The weapon damages by impacting, not by exploding
107 
108 	bool noAutoTarget;          ///< cant target stuff (for antinuke,dgun)
109 	bool manualfire;            ///< if true, slave us to the ManualFire button
110 
111 	bool interceptSolo;
112 	int interceptor;            ///< if >= 1, weapon will fire at any interceptable projectiles
113 	int targetable;             ///< nuke (can be shot by interceptor)
114 	bool stockpile;
115 	float coverageRange;        ///< range of anti nuke
116 
117 	float stockpileTime;        ///< builtime of a missile
118 
119 	///< determines alpha-fading for BeamLasers (UNSYNCED);
120 	///< combines with falloffRate for Lasers to determine
121 	///< when projectile should be deleted (SYNCED) instead
122 	///< of TTL
123 	float intensity;
124 	float falloffRate;
125 	float duration;
126 	int beamLaserTTL;
127 
128 	bool soundTrigger;
129 
130 	bool selfExplode;
131 	bool gravityAffected;
132 	int highTrajectory;         ///< Per-weapon high traj setting, 0=low, 1=high, 2=unit
133 	float myGravity;
134 	bool noExplode;
135 	float startvelocity;
136 	float weaponacceleration;
137 	float turnrate;
138 
139 	float projectilespeed;
140 	float explosionSpeed;
141 
142 	float wobble;             ///< how much the missile will wobble around its course
143 	float dance;              ///< how much the missile will dance
144 	float trajectoryHeight;   ///< how high trajectory missiles will try to fly in
145 
146 	bool largeBeamLaser;             // whether a BeamLaser should spawn LargeBeamLaserProjectile's or regular ones
147 	bool laserHardStop;              // whether the shot should fade out or stop and contract at max-range (applies to LaserCannons only)
148 
149 	bool isShield;                   // if the weapon is a shield rather than a weapon //FIXME REMOVE! (this information is/should be saved in the weapontype)
150 	bool shieldRepulser;             // if the weapon should be repulsed or absorbed
151 	bool smartShield;                // only affect enemy projectiles
152 	bool exteriorShield;             // only affect stuff coming from outside shield radius
153 	bool visibleShield;              // if the shield should be graphically shown
154 	bool visibleShieldRepulse;       // if a small graphic should be shown at each repulse
155 	int  visibleShieldHitFrames;     // number of frames to draw the shield after it has been hit
156 	float shieldEnergyUse;           // energy use per shot or per second depending on projectile
157 	float shieldRadius;              // size of shielded area
158 	float shieldForce;               // shield acceleration on plasma stuff
159 	float shieldMaxSpeed;            // max speed shield can repulse plasma like weapons with
160 	float shieldPower;               // how much damage the shield can reflect (0=infinite)
161 	float shieldPowerRegen;          // how fast the power regenerates per second
162 	float shieldPowerRegenEnergy;    // how much energy is needed to regenerate power per second
163 	float shieldStartingPower;       // how much power the shield has when first created
164 	int   shieldRechargeDelay;       // number of frames to delay recharging by after each hit
165 	float3 shieldGoodColor;          // color when shield at full power
166 	float3 shieldBadColor;           // color when shield is empty
167 	float shieldAlpha;               // shield alpha value
168 	int shieldArmorType;             // armor type for the damage table
169 	std::string shieldArmorTypeName; // name of the armor type
170 
171 	unsigned int shieldInterceptType;      // type of shield (bitfield)
172 	unsigned int interceptedByShieldType;  // weapon can be affected by shields where (shieldInterceptType & interceptedByShieldType) is not zero
173 
174 	bool avoidFriendly;     // if true, try to avoid friendly units while aiming
175 	bool avoidFeature;      // if true, try to avoid features while aiming
176 	bool avoidNeutral;      // if true, try to avoid neutral units while aiming
177 	bool avoidGround;       // if true, try to avoid ground while aiming
178 	/**
179 	 * If nonzero, targetting units will TryTarget at the edge of collision sphere
180 	 * (radius*tag value, [-1;1]) instead of its centre.
181 	 */
182 	float targetBorder;
183 	/**
184 	 * If greater than 0, the range will be checked in a cylinder
185 	 * (height=range*cylinderTargeting) instead of a sphere.
186 	 */
187 	float cylinderTargeting;
188 	/**
189 	 * For beam-lasers only - always hit with some minimum intensity
190 	 * (a damage coefficient normally dependent on distance).
191 	 * Do not confuse this with the intensity tag, it i completely unrelated.
192 	 */
193 	float minIntensity;
194 	/**
195 	 * Controls cannon range height boost.
196 	 *
197 	 * default: -1: automatically calculate a more or less sane value
198 	 */
199 	float heightBoostFactor;
200 	float proximityPriority;     // multiplier for the distance to the target for priority calculations
201 
202 	unsigned int projectileType;
203 	unsigned int collisionFlags;
204 
205 	bool sweepFire;
206 	bool canAttackGround;
207 
208 	float cameraShake;
209 
210 	float dynDamageExp;
211 	float dynDamageMin;
212 	float dynDamageRange;
213 	bool dynDamageInverted;
214 
215 	std::map<std::string, std::string> customParams;
216 
217 	struct Visuals {
VisualsWeaponDef::Visuals218 		Visuals()
219 			: color(ZeroVector)
220 			, color2(ZeroVector)
221 			, model(NULL)
222 			, colorMap(NULL)
223 			, explosionScar(true)
224 			, smokeTrail(false)
225 			, texture1(NULL)
226 			, texture2(NULL)
227 			, texture3(NULL)
228 			, texture4(NULL)
229 			, tilelength(0.0f)
230 			, scrollspeed(0.0f)
231 			, pulseSpeed(0.0f)
232 			, laserflaresize(0.0f)
233 			, thickness(0.0f)
234 			, corethickness(0.0f)
235 			, lodDistance(0)
236 			, beamdecay(0.0f)
237 			, stages(0)
238 			, alphaDecay(0.0f)
239 			, sizeDecay(0.0f)
240 			, separation(0.0f)
241 			, noGap(true)
242 			, alwaysVisible(true)
243 		{}
244 
245 		float3 color;
246 		float3 color2;
247 
248 		S3DModel* model;
249 		std::string modelName;
250 		std::string texNames[4];
251 		std::string ptrailExpGenTag; ///< tag of CEG that projectiles fired by this weapon should use during flight
252 		std::string impactExpGenTag; ///< tag of CEG that projectiles fired by this weapon should use on impact
253 		std::string bounceExpGenTag; ///< tag of CEG that projectiles fired by this weapon should use when bouncing
254 		CColorMap* colorMap;
255 
256 		/// TODO: make the scar-type configurable
257 		bool explosionScar;
258 		bool smokeTrail;
259 
260 		AtlasedTexture* texture1;
261 		AtlasedTexture* texture2;
262 		AtlasedTexture* texture3;
263 		AtlasedTexture* texture4;
264 		float tilelength;
265 		float scrollspeed;
266 		float pulseSpeed;
267 		float laserflaresize;
268 		float thickness;
269 		float corethickness;
270 		int   lodDistance;
271 		float beamdecay;
272 
273 		int stages;
274 		float alphaDecay;
275 		float sizeDecay;
276 		float separation;
277 		bool noGap;
278 		bool alwaysVisible;
279 	};
280 	Visuals visuals;
281 
282 private:
283 	void ParseWeaponSounds(const LuaTable& wdTable);
284 	void LoadSound(const LuaTable& wdTable, const std::string& soundKey, const unsigned int soundIdx, std::vector<GuiSoundSet::Data>& soundData);
285 };
286 
287 #endif // _WEAPON_DEF_H
288