-
Notifications
You must be signed in to change notification settings - Fork 57
/
buffs.c
263 lines (244 loc) · 6.88 KB
/
buffs.c
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/*
* buffs.c
*
* Created on: 14.11.2008
* Author: superfloh
*/
#include "buffs.h"
#include "actors_list.h"
#include "client_serv.h"
#include "eye_candy_wrapper.h"
#include "font.h" // for ALT_INGAME_FONT_X_LEN
#include "gl_init.h"
#include "elconfig.h" // for poor_man
#include "interface.h" // for view_names
#include "platform.h"
#include "spells.h" // for the sigils texture
#include "textures.h"
int view_buffs = 1;
int buff_icon_size = 32;
// Forward declaration
static void update_buff_eye_candy(actor *act);
void update_actor_buffs(int actor_id, Uint32 in_buffs)
{
locked_list_ptr actors_list;
actor *act, *attached;
#ifdef EXTRA_DEBUG
ERR();
#endif
actors_list = lock_and_get_actor_and_attached_from_id(actor_id, &act, &attached);
if (!actors_list)
//if we got here, it means we don't have this actor, so get it from the server...
return;
update_actor_buffs_locked(act, attached, in_buffs);
release_locked_actors_list_and_invalidate2(actors_list, &act, &attached);
}
void update_actor_buffs_locked(actor *act, actor *attached, Uint32 in_buffs)
{
if (in_buffs & BUFF_DOUBLE_SPEED)
act->step_duration = actors_defs[act->actor_type].step_duration / 2;
else
act->step_duration = actors_defs[act->actor_type].step_duration;
if (attached)
{
attached->buffs = in_buffs & BUFF_DOUBLE_SPEED;
attached->step_duration = act->step_duration;
}
act->buffs = in_buffs;
#ifdef BUFF_DEBUG
{
int i, num_buffs = 0;
for (i = 0; i < NUM_BUFFS; i++)
{
if (act->buffs & ((Uint32)pow(2, i))) {
num_buffs++;
}
}
printf("update_actor_buffs: name %s id %i num buffs: %i\n", act->actor_name, act->actor_id, num_buffs);
}
if (in_buffs & BUFF_INVISIBILITY) {
printf(" invisibility ON\n");
}
// else {
// printf(" invisibility off\n");
// }
if (in_buffs & BUFF_MAGIC_IMMUNITY) {
printf(" magic immunity ON\n");
}
// else {
// printf(" magic immunity off\n");
// }
if (in_buffs & BUFF_MAGIC_PROTECTION) {
printf(" magic protection ON\n");
}
// else {
// printf(" magic protection off\n");
// }
if (in_buffs & BUFF_COLD_SHIELD) {
printf(" cold shield ON\n");
}
// else {
// printf(" cold shield off\n");
// }
if (in_buffs & BUFF_HEAT_SHIELD) {
printf(" heat shield ON\n");
}
// else {
// printf(" heat shield off\n");
// }
if (in_buffs & BUFF_RADIATION_SHIELD) {
printf(" radiation shield ON\n");
}
// else {
// printf(" radiation shield off\n");
// }
if (in_buffs & BUFF_SHIELD) {
printf(" shield ON\n");
}
// else {
// printf(" shield off\n");
// }
if (in_buffs & BUFF_TRUE_SIGHT) {
printf(" true sight ON\n");
}
// else {
// printf(" true sight off\n");
// }
if (in_buffs & BUFF_ACCURACY) {
printf(" accuracy ON\n");
}
// else {
// printf(" accuracy off\n");
// }
if (in_buffs & BUFF_EVASION) {
printf(" evasion ON\n");
}
// else {
// printf(" evasion off\n");
// }
if (in_buffs & BUFF_DOUBLE_SPEED) {
printf(" double speed ON\n");
}
// else {
// printf(" double speed off\n");
// }
#endif // BUFF_DEBUG
update_buff_eye_candy(act);
}
static void update_buff_eye_candy(actor *act)
{
Uint32 buff_index;
// turn on eye candy effects
buff_index = (Uint32)(0.5 + log(BUFF_SHIELD)/log(2));
if (act->buffs & BUFF_SHIELD && act->ec_buff_reference[buff_index] == NULL) {
act->ec_buff_reference[buff_index] = ec_create_ongoing_shield2(act, 1.0, 1.0, (poor_man ? 6 : 10), 1.0);
}
buff_index = (Uint32)(0.5 + log(BUFF_MAGIC_PROTECTION)/log(2));
if (act->buffs & BUFF_MAGIC_PROTECTION && act->ec_buff_reference[buff_index] == NULL) {
act->ec_buff_reference[buff_index] = ec_create_ongoing_magic_protection2(act, 1.0, 1.0, (poor_man ? 6 : 10), 1.0);
}
/*
* not yet implemented
if (act->buffs & BUFF_POISONED && act->ec_buff_reference[((Uint32)(log(BUFF_POISONED)/log(2)))] == NULL) {
act->ec_buff_reference[((Uint32)(log(BUFF_POISONED)/log(2)))] = ec_create_ongoing_poison2(act, 1.0, 1.0, (poor_man ? 6 : 10), 1.0);
}
*/
// removed by Roja's request
// if (act->buffs & BUFF_MAGIC_IMMUNITY && act->ec_buff_reference[((Uint32)(log(BUFF_MAGIC_IMMUNITY)/log(2)))] == NULL) {
// act->ec_buff_reference[((Uint32)(log(BUFF_MAGIC_IMMUNITY)/log(2)))] = ec_create_ongoing_magic_immunity2(act, 1.0, 1.0, (poor_man ? 6 : 10), 1.0);
// }
// turn off effects
for (int i = 0; i < NUM_BUFFS; i++) {
if (act->ec_buff_reference[i] != NULL && !(act->buffs & ((Uint32)(0.5 + pow(2, i))))) {
ec_recall_effect(act->ec_buff_reference[i]);
act->ec_buff_reference[i] = NULL;
}
}
}
void draw_buffs(actor *act, float x, float y,float z)
{
int scale_buff_icon_size = (int)(0.5 + buff_icon_size * get_global_scale());
if (act->buffs)
{
// texture coords
float u_start,v_start,u_end,v_end;
// current texture
int cur_tex = 0;
// loop index
int i;
// number of buffs
int num_buffs = 0;
// x offset
int x_off = 0;
// textures
int texture_ids[NUM_BUFFS];
//enable alpha filtering, so we have some alpha key
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER,0.1f);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glColor3f(1.0f,1.0f,1.0f);
bind_texture(sigils_text);
// keep in sync with client_serv.h !!!
if (act->buffs & BUFF_SHIELD) {
texture_ids[num_buffs] = 32;
num_buffs++;
}
if (act->buffs & BUFF_MAGIC_PROTECTION) {
texture_ids[num_buffs] = 33;
num_buffs++;
}
if (act->buffs & BUFF_COLD_SHIELD) {
texture_ids[num_buffs] = 55;
num_buffs++;
}
if (act->buffs & BUFF_HEAT_SHIELD) {
texture_ids[num_buffs] = 56;
num_buffs++;
}
if (act->buffs & BUFF_RADIATION_SHIELD) {
texture_ids[num_buffs] = 57;
num_buffs++;
}
/*
* not yet implemented
if (act->buffs & BUFF_POISONED) {
texture_ids[num_buffs] = 34;
num_buffs++;
}
*/
if (act->buffs & BUFF_MAGIC_IMMUNITY) {
texture_ids[num_buffs] = 35;
num_buffs++;
}
// move icons up by actor name and actor health bar
y = y + 1.0f/ALT_INGAME_FONT_X_LEN*SMALL_INGAME_FONT_Y_LEN*font_scales[NAME_FONT]*12.0*view_names // displayed_font_y_size from font.c
+ ALT_INGAME_FONT_Y_LEN*12.0*font_scales[NAME_FONT]*1.0f/ALT_INGAME_FONT_X_LEN; // healthbar_y_len from actors.c
for (i = 0; i < num_buffs; i++)
{
cur_tex = texture_ids[i];
//now get the texture coordinates, copied from spells.c
u_start = 0.125f * (cur_tex % 8);
u_end = u_start + 0.125f;
v_start = 0.125f * (cur_tex / 8);
v_end = v_start + 0.125f;
x_off = (int)(-1.0 * ((float)num_buffs * scale_buff_icon_size) / 2.0f + (scale_buff_icon_size * i));
// draw the spell icon
glBegin(GL_QUADS);
glTexCoord2f(u_start,v_start);
glVertex3f(x + x_off, y + scale_buff_icon_size, z);
glTexCoord2f(u_start,v_end);
glVertex3f(x + x_off,y,z);
glTexCoord2f(u_end,v_end);
glVertex3f(x + scale_buff_icon_size + x_off, y, z);
glTexCoord2f(u_end,v_start);
glVertex3f(x + scale_buff_icon_size + x_off, y + scale_buff_icon_size, z);
glEnd();
}
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
#ifdef OPENGL_TRACE
CHECK_GL_ERRORS();
#endif //OPENGL_TRACE
}
}