File: objectshield.h

package info (click to toggle)
freespace2 24.0.2%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: trixie
  • size: 43,188 kB
  • sloc: cpp: 583,107; ansic: 21,729; python: 1,174; sh: 464; makefile: 248; xml: 181
file content (141 lines) | stat: -rw-r--r-- 4,159 bytes parent folder | download | duplicates (4)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * Copyright (C) Volition, Inc. 1999.  All rights reserved.
 *
 * All source code herein is the property of Volition, Inc. You may not sell 
 * or otherwise commercially exploit the source or things you created based on the 
 * source.
 *
*/

#ifndef _OBJECTSHIELD_H
#define _OBJECTSHIELD_H

#include "globalincs/globals.h"
#include "globalincs/pstypes.h"
#include "object/object.h"

#define	FRONT_QUAD	1
#define	REAR_QUAD	2
#define	LEFT_QUAD	3
#define	RIGHT_QUAD	0

/**
 * @brief Balances/Equalizes the shield
 *
 * @param[in] balance_rate The rate to balance the shield (0 < x <= 1)
 * @param[in] penalty      Percent of the shield energy to lose during the balance (0 < x <= 1)
 *
 * @author z64555
 *
 * @details Each quadrant is observed to exponentially approach the average shield HP, weaker quadrants quickly fill
 *   up while stronger quadrants fille up slower. We don't have to worry about the shield gaining energy from
 *   somewhere, since the sum of each (shield_hp_avg - shield_quadrant[i]) is 0.
 *   Applying a balance rate is legal since it's equivalent to applying the rate to the entire sum, which is still 0.
 *
 * @TODO Verify operation with model point shields
 */
void shield_balance(object *objp, float rate, float penalty);

/**
 * @brief Transfers energy to the given quadrant from the other quadrants
 *
 * @param[in] quadrant Index of the quadrant to Xfer to
 * @param[in] rate     Percent rate to increase the target quadrant
 *
 * @author z64555, zookeeper
 *
 * @details The transfer sips a percentage of each quadrant, taking more energy from stronger quadrants and less from
 *   weaker ones.
 */
void shield_transfer(object *objp, int quadrant, float rate);

/**
 * @brief Gets the shield strength (in HP) of the given object
 */
float shield_get_strength(object *objp);

/**
 * @brief Sets the shield strength (in HP) of the given object.
 * @note All quadrants are set to an equal strength
 */
void shield_set_strength(object *objp, float strength);

/**
 * @brief Adds the given delta to the given object's shield.
 *
 * @param[in] delta HP to add (or subtract if negative) to the object's shield
 */
void shield_add_strength(object *objp, float delta);

/**
 * @brief Gets the strength (in HP) of a shield quadrant/sector
 *
 * @param[in] quadrant_num Index of the quadrant/sector to check.
 *
 * @author Goober5000
 */
float shield_get_quad(object *objp, int quadrant_num);

/**
 * @brief Sets the strength (in HP) of a shield quadrant/sector
 *
 * @param[in] quadrant_num Index of the quadrant/sector to set.
 * @param[in] strength HP to set
 *
 * @author Goober5000
 */
void shield_set_quad(object *objp, int quadrant_num, float strength);

/**
 * @brief Sets the strength (in HP) of a shield quadrant/sector
 *
 * @param[in] quadrant_num Index of the quadrant/sector to set.
 * @param[in] strength HP to add (or subtract if negative) to the quadrant/sector
 *
 * @author Goober5000
 */
void shield_add_quad(object *objp, int quadrant_num, float strength);

/**
 * @brief Gets the max shield HP of the given object
 *
 * @note $Max Shield Recharge is not intended to affect max strength of individual shield segments
 *
 * @author Goober5000
 */
float shield_get_max_strength(object *objp, bool no_msr = false);

/**
 * @brief Sets the max shield HP of the given object. Use this to init or override a ship's default shield HP
 */
void shield_set_max_strength(object *objp, float newmax);

/**
 * @brief Gets the max shield HP that a quadrant/sector may have
 *
 * @author Goober5000
 */
float shield_get_max_quad(object *objp);

/**
 * @brief Strengthens the weakest quadrant first, then spreads it out
 */
void shield_apply_healing(object* objp, float healing);

/**
 * @brief Applies damage to the given shield quandrant/sector of the given object.
 *
 * @returns Any remaining damage after being absorbed by the shield.
 *
 * @details Basically:
 *   if (Damage > Quadrant HP) {
 *     Quadrant HP = 0;
 *     return Damage - Quadrant HP;
 *   } else {
 *     Quadrant HP -= Damage;
 *     return 0.0f;
 *   }
 */
float shield_apply_damage(object *objp, int quadrant, float damage);

#endif //_OBJECTSHIELD_H