1 /*
2 * buffs.c
3 *
4 * Created on: 14.11.2008
5 * Author: superfloh
6 */
7
8 #include "buffs.h"
9
10 #include "client_serv.h"
11 #include "eye_candy_wrapper.h"
12 #include "font.h" // for ALT_INGAME_FONT_X_LEN
13 #include "gl_init.h"
14 #include "elconfig.h" // for poor_man
15 #include "interface.h" // for view_names
16 #include "platform.h"
17 #include "spells.h" // for the sigils texture
18 #include "textures.h"
19
20 int view_buffs = 1;
21 int buff_icon_size = 32;
22
update_actor_buffs(int actor_id,Uint32 in_buffs)23 void update_actor_buffs(int actor_id, Uint32 in_buffs)
24 {
25 actor *act;
26 #ifdef EXTRA_DEBUG
27 ERR();
28 #endif
29 act = get_actor_ptr_from_id(actor_id);
30
31 if(!act){
32 //if we got here, it means we don't have this actor, so get it from the server...
33 } else {
34 if (in_buffs & BUFF_DOUBLE_SPEED)
35 act->step_duration = actors_defs[act->actor_type].step_duration / 2;
36 else
37 act->step_duration = actors_defs[act->actor_type].step_duration;
38 if (act->attached_actor >= 0)
39 {
40 actors_list[act->attached_actor]->buffs = in_buffs & BUFF_DOUBLE_SPEED;
41 actors_list[act->attached_actor]->step_duration = act->step_duration;
42 }
43 act->buffs = in_buffs;
44 #ifdef BUFF_DEBUG
45 {
46 int i, num_buffs = 0;
47 for (i = 0; i < NUM_BUFFS; i++)
48 {
49 if (act->buffs & ((Uint32)pow(2, i))) {
50 num_buffs++;
51 }
52 }
53 printf("update_actor_buffs: name %s id %i num buffs: %i\n", act->actor_name, act->actor_id, num_buffs);
54 }
55 if (in_buffs & BUFF_INVISIBILITY) {
56 printf(" invisibility ON\n");
57 }
58 // else {
59 // printf(" invisibility off\n");
60 // }
61 if (in_buffs & BUFF_MAGIC_IMMUNITY) {
62 printf(" magic immunity ON\n");
63 }
64 // else {
65 // printf(" magic immunity off\n");
66 // }
67 if (in_buffs & BUFF_MAGIC_PROTECTION) {
68 printf(" magic protection ON\n");
69 }
70 // else {
71 // printf(" magic protection off\n");
72 // }
73 if (in_buffs & BUFF_COLD_SHIELD) {
74 printf(" cold shield ON\n");
75 }
76 // else {
77 // printf(" cold shield off\n");
78 // }
79 if (in_buffs & BUFF_HEAT_SHIELD) {
80 printf(" heat shield ON\n");
81 }
82 // else {
83 // printf(" heat shield off\n");
84 // }
85 if (in_buffs & BUFF_RADIATION_SHIELD) {
86 printf(" radiation shield ON\n");
87 }
88 // else {
89 // printf(" radiation shield off\n");
90 // }
91 if (in_buffs & BUFF_SHIELD) {
92 printf(" shield ON\n");
93 }
94 // else {
95 // printf(" shield off\n");
96 // }
97 if (in_buffs & BUFF_TRUE_SIGHT) {
98 printf(" true sight ON\n");
99 }
100 // else {
101 // printf(" true sight off\n");
102 // }
103 if (in_buffs & BUFF_ACCURACY) {
104 printf(" accuracy ON\n");
105 }
106 // else {
107 // printf(" accuracy off\n");
108 // }
109 if (in_buffs & BUFF_EVASION) {
110 printf(" evasion ON\n");
111 }
112 // else {
113 // printf(" evasion off\n");
114 // }
115 if (in_buffs & BUFF_DOUBLE_SPEED) {
116 printf(" double speed ON\n");
117 }
118 // else {
119 // printf(" double speed off\n");
120 // }
121 #endif // BUFF_DEBUG
122 update_buff_eye_candy(actor_id);
123 }
124 }
125
update_buff_eye_candy(int actor_id)126 void update_buff_eye_candy(int actor_id) {
127 actor *act;
128 act = get_actor_ptr_from_id(actor_id);
129 if (act) {
130 int i = 0; // loop index
131 // turn on eye candy effects
132 Uint32 buff_index = (Uint32)(0.5 + log(BUFF_SHIELD)/log(2));
133 if (act->buffs & BUFF_SHIELD && act->ec_buff_reference[buff_index] == NULL) {
134 act->ec_buff_reference[buff_index] = ec_create_ongoing_shield2(act, 1.0, 1.0, (poor_man ? 6 : 10), 1.0);
135 }
136 buff_index = (Uint32)(0.5 + log(BUFF_MAGIC_PROTECTION)/log(2));
137 if (act->buffs & BUFF_MAGIC_PROTECTION && act->ec_buff_reference[buff_index] == NULL) {
138 act->ec_buff_reference[buff_index] = ec_create_ongoing_magic_protection2(act, 1.0, 1.0, (poor_man ? 6 : 10), 1.0);
139 }
140 /*
141 * not yet implemented
142 if (act->buffs & BUFF_POISONED && act->ec_buff_reference[((Uint32)(log(BUFF_POISONED)/log(2)))] == NULL) {
143 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);
144 }
145 */
146 // removed by Roja's request
147 // if (act->buffs & BUFF_MAGIC_IMMUNITY && act->ec_buff_reference[((Uint32)(log(BUFF_MAGIC_IMMUNITY)/log(2)))] == NULL) {
148 // 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);
149 // }
150 // turn off effects
151 for (i = 0; i < NUM_BUFFS; i++) {
152 if (act->ec_buff_reference[i] != NULL && !(act->buffs & ((Uint32)(0.5 + pow(2, i))))) {
153 ec_recall_effect(act->ec_buff_reference[i]);
154 act->ec_buff_reference[i] = NULL;
155 }
156 }
157 }
158 }
159
draw_buffs(int actor_id,float x,float y,float z)160 void draw_buffs(int actor_id, float x, float y,float z)
161 {
162 int scale_buff_icon_size = (int)(0.5 + buff_icon_size * get_global_scale());
163 actor *act;
164 act = get_actor_ptr_from_id(actor_id);
165 if (act && act->buffs) {
166 // texture coords
167 float u_start,v_start,u_end,v_end;
168 // current texture
169 int cur_tex = 0;
170 // loop index
171 int i;
172 // number of buffs
173 int num_buffs = 0;
174 // x offset
175 int x_off = 0;
176 // textures
177 int texture_ids[NUM_BUFFS];
178 //enable alpha filtering, so we have some alpha key
179 glEnable(GL_ALPHA_TEST);
180 glAlphaFunc(GL_GREATER,0.1f);
181 glEnable(GL_BLEND);
182 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
183 glColor3f(1.0f,1.0f,1.0f);
184 bind_texture(sigils_text);
185 // keep in sync with client_serv.h !!!
186 if (act->buffs & BUFF_SHIELD) {
187 texture_ids[num_buffs] = 32;
188 num_buffs++;
189 }
190 if (act->buffs & BUFF_MAGIC_PROTECTION) {
191 texture_ids[num_buffs] = 33;
192 num_buffs++;
193 }
194 if (act->buffs & BUFF_COLD_SHIELD) {
195 texture_ids[num_buffs] = 55;
196 num_buffs++;
197 }
198 if (act->buffs & BUFF_HEAT_SHIELD) {
199 texture_ids[num_buffs] = 56;
200 num_buffs++;
201 }
202 if (act->buffs & BUFF_RADIATION_SHIELD) {
203 texture_ids[num_buffs] = 57;
204 num_buffs++;
205 }
206 /*
207 * not yet implemented
208 if (act->buffs & BUFF_POISONED) {
209 texture_ids[num_buffs] = 34;
210 num_buffs++;
211 }
212 */
213 if (act->buffs & BUFF_MAGIC_IMMUNITY) {
214 texture_ids[num_buffs] = 35;
215 num_buffs++;
216 }
217 // move icons up by actor name and actor health bar
218 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
219 + ALT_INGAME_FONT_Y_LEN*12.0*font_scales[NAME_FONT]*1.0f/ALT_INGAME_FONT_X_LEN; // healthbar_y_len from actors.c
220 for (i = 0; i < num_buffs; i++)
221 {
222 cur_tex = texture_ids[i];
223 //now get the texture coordinates, copied from spells.c
224 u_start = 0.125f * (cur_tex % 8);
225 u_end = u_start + 0.125f;
226 v_start = 0.125f * (cur_tex / 8);
227 v_end = v_start + 0.125f;
228 x_off = (int)(-1.0 * ((float)num_buffs * scale_buff_icon_size) / 2.0f + (scale_buff_icon_size * i));
229 // draw the spell icon
230 glBegin(GL_QUADS);
231 glTexCoord2f(u_start,v_start);
232 glVertex3f(x + x_off, y + scale_buff_icon_size, z);
233
234 glTexCoord2f(u_start,v_end);
235 glVertex3f(x + x_off,y,z);
236
237 glTexCoord2f(u_end,v_end);
238 glVertex3f(x + scale_buff_icon_size + x_off, y, z);
239
240 glTexCoord2f(u_end,v_start);
241 glVertex3f(x + scale_buff_icon_size + x_off, y + scale_buff_icon_size, z);
242 glEnd();
243 }
244 glDisable(GL_BLEND);
245 glDisable(GL_ALPHA_TEST);
246 #ifdef OPENGL_TRACE
247 CHECK_GL_ERRORS();
248 #endif //OPENGL_TRACE
249 }
250 }
251