1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #include "map_view.hh"
|
---|
10 | #include "window/window.hh"
|
---|
11 | #include "image/image.hh"
|
---|
12 | #include "map.hh"
|
---|
13 | #include "camera.hh"
|
---|
14 | #include "window/win_evt.hh"
|
---|
15 | #include "device/kernel.hh"
|
---|
16 | #include "player.hh"
|
---|
17 | #include "map_cell.hh"
|
---|
18 | #include "tile.hh"
|
---|
19 | #include "g1_render.hh"
|
---|
20 | #include "tmanage.hh"
|
---|
21 | #include "app/app.hh"
|
---|
22 | #include "border_frame.hh"
|
---|
23 | #include "status/status.hh"
|
---|
24 | #include "map_vert.hh"
|
---|
25 | #include "lisp/lisp.hh"
|
---|
26 | #include "map_man.hh"
|
---|
27 | #include "objs/path_object.hh"
|
---|
28 | #include "objs/bases.hh"
|
---|
29 | #include "human.hh"
|
---|
30 | #include "image_man.hh"
|
---|
31 |
|
---|
32 | class g1_radar_view_class;
|
---|
33 | static g1_radar_view_class *list=0;
|
---|
34 |
|
---|
35 |
|
---|
36 | void g1_calc_map_area(int max_width, int max_height, int &x1, int &y1, int &x2, int &y2)
|
---|
37 | {
|
---|
38 | int map_width= g1_get_map()->width(), map_height=g1_get_map()->height();
|
---|
39 | int iw=max_width, ih=map_height*max_width/map_width;
|
---|
40 |
|
---|
41 | if (ih>max_height)
|
---|
42 | {
|
---|
43 | ih=max_height;
|
---|
44 | iw=map_width*max_height/map_height;
|
---|
45 | }
|
---|
46 |
|
---|
47 | if (iw<max_width)
|
---|
48 | x1=max_width/2-iw/2;
|
---|
49 | else
|
---|
50 | x1=0;
|
---|
51 | x2=x1+iw-1;
|
---|
52 |
|
---|
53 | if (ih<max_height)
|
---|
54 | y1=max_height/2-ih/2;
|
---|
55 | else
|
---|
56 | y1=0;
|
---|
57 | y2=y1+ih-1;
|
---|
58 |
|
---|
59 |
|
---|
60 |
|
---|
61 |
|
---|
62 | }
|
---|
63 |
|
---|
64 | struct g1_radar_params_struct
|
---|
65 | {
|
---|
66 | int ix1, iy1, ix2, iy2;
|
---|
67 | float mx1,my1,mx2,my2;
|
---|
68 | float m2gx, m2gy, g2mx, g2my;
|
---|
69 | float map_w, map_h;
|
---|
70 |
|
---|
71 | void init(int image_w, int image_h)
|
---|
72 | {
|
---|
73 | g1_calc_map_area(image_w, image_h, ix1,iy1,ix2,iy2);
|
---|
74 | mx1=ix1; mx2=ix2;
|
---|
75 | my1=iy1; my2=iy2;
|
---|
76 |
|
---|
77 | map_w=(float)g1_get_map()->width();
|
---|
78 | map_h=(float)g1_get_map()->height();
|
---|
79 |
|
---|
80 | m2gx = map_w/(float)(ix2-ix1+1);
|
---|
81 | m2gy = map_h/(float)(iy2-iy1+1);
|
---|
82 |
|
---|
83 | g2mx = 1.0/m2gx;
|
---|
84 | g2my = 1.0/m2gy;
|
---|
85 | }
|
---|
86 |
|
---|
87 | void mouse_2_game(float mx, float my, float &x, float &y)
|
---|
88 | {
|
---|
89 | x=((float)mx-mx1) * m2gx;
|
---|
90 | y=map_h-((float)my-my1) * m2gy-1;
|
---|
91 | }
|
---|
92 |
|
---|
93 | void game_2_mouse(float gx, float gy, float &mx, float &my)
|
---|
94 | {
|
---|
95 | mx=gx * g2mx + mx1;
|
---|
96 | my=(map_h-gy-1) * g2my + my1;
|
---|
97 |
|
---|
98 | }
|
---|
99 | };
|
---|
100 |
|
---|
101 |
|
---|
102 |
|
---|
103 | //////////////////////////////////////////////////////////////////////////////
|
---|
104 | // radar background drawing code
|
---|
105 | //////////////////////////////////////////////////////////////////////////////
|
---|
106 | static float radar_darkness_multiply;
|
---|
107 |
|
---|
108 |
|
---|
109 | inline int get_mat_color(g1_map_cell_class *c)
|
---|
110 | {
|
---|
111 | if (c->flags & g1_map_cell_class::FOGGED)
|
---|
112 | return 0;
|
---|
113 |
|
---|
114 | r1_texture_handle mat=g1_tile_man.get_texture(c->type);
|
---|
115 | if (mat==g1_tile_man.get_pink())
|
---|
116 | return 0;
|
---|
117 |
|
---|
118 | if (mat)
|
---|
119 | {
|
---|
120 | r1_texture_manager_class *tman=g1_render.r_api->get_tmanager();
|
---|
121 | return tman->average_texture_color(mat,0);
|
---|
122 | }
|
---|
123 | else
|
---|
124 | return 0;
|
---|
125 | }
|
---|
126 |
|
---|
127 |
|
---|
128 |
|
---|
129 | static w8 interp_table[32*32*32];
|
---|
130 | static w8 light_table[32*32*32];
|
---|
131 | static w8 tables_calced=0;
|
---|
132 | static int r_shift, g_shift, b_shift;
|
---|
133 |
|
---|
134 | static void calc_tables()
|
---|
135 | {
|
---|
136 | if (tables_calced) return;
|
---|
137 | tables_calced=1;
|
---|
138 |
|
---|
139 | const i4_pal *pal=i4_current_app->get_display()->get_palette();
|
---|
140 | const i4_pixel_format *dst_fmt=&pal->source;
|
---|
141 | I4_ASSERT(dst_fmt->pixel_depth==I4_16BIT,""); // 16bit only code below
|
---|
142 |
|
---|
143 | b_shift=dst_fmt->blue_shift + (dst_fmt->blue_bits-5);
|
---|
144 |
|
---|
145 | g_shift=dst_fmt->green_shift + (dst_fmt->green_bits-5);
|
---|
146 |
|
---|
147 | r_shift=dst_fmt->red_shift + (dst_fmt->red_bits-5);
|
---|
148 |
|
---|
149 |
|
---|
150 | w8 *t=interp_table;
|
---|
151 | for (int c1=0; c1<32; c1++)
|
---|
152 | for (int c2=0; c2<32; c2++)
|
---|
153 | {
|
---|
154 | int d=c2-c1;
|
---|
155 | for (int r=0; r<32; r++)
|
---|
156 | *(t++)=d*r/32 + (int)c1;
|
---|
157 | }
|
---|
158 |
|
---|
159 |
|
---|
160 | t=light_table;
|
---|
161 | for (int c=0; c<32; c++)
|
---|
162 | for (int l=0; l<32; l++)
|
---|
163 | *(t++)=((int)c * l)/32;
|
---|
164 | }
|
---|
165 |
|
---|
166 | inline w8 interpolate_555(w8 c1_0_31, int c2_0_31, int ratio_0_31)
|
---|
167 | {
|
---|
168 | return interp_table[(c1_0_31<<10) | (c2_0_31<<5) | (ratio_0_31 << 0)];
|
---|
169 | }
|
---|
170 |
|
---|
171 |
|
---|
172 | inline w8 light_555(w8 color_0_31, int light_0_31)
|
---|
173 | {
|
---|
174 | return light_table[(color_0_31<<5) | light_0_31];
|
---|
175 | }
|
---|
176 |
|
---|
177 |
|
---|
178 | w8 g1_light_555(w8 color_0_31, int light_0_31)
|
---|
179 | {
|
---|
180 |
|
---|
181 | calc_tables();
|
---|
182 | return light_table[(color_0_31<<5) | light_0_31];
|
---|
183 | }
|
---|
184 |
|
---|
185 | void g1_draw_strategy_border(i4_image_class *im)
|
---|
186 | {
|
---|
187 | int mx1,my1,mx2,my2;
|
---|
188 | g1_calc_map_area(im->width(), im->height(), mx1,my1,mx2,my2);
|
---|
189 | i4_draw_context_class context(0,0,im->width()-1, im->height()-1);
|
---|
190 | context.clip.remove_area(mx1,my1,mx2,my2);
|
---|
191 |
|
---|
192 | int y=my1;
|
---|
193 | while (y>0) y-=2;
|
---|
194 |
|
---|
195 | w32 color;
|
---|
196 |
|
---|
197 | g1_player_piece_class *com=g1_player_man.get_local()->get_commander();
|
---|
198 | if (com)
|
---|
199 | color=g1_get_upgrade_color(com->upgrade_level_when_built);
|
---|
200 | else
|
---|
201 | color=g1_get_upgrade_color(-1);
|
---|
202 |
|
---|
203 | color=g1_light_color(color, 0.2);
|
---|
204 |
|
---|
205 | im->clear(0, context);
|
---|
206 | for (; y<im->height(); y+=2)
|
---|
207 | im->bar(0,y,im->width()-1,y, color, context);
|
---|
208 | }
|
---|
209 |
|
---|
210 |
|
---|
211 |
|
---|
212 | void g1_render_map_area(i4_image_class *im,
|
---|
213 | g1_radar_params_struct *p,
|
---|
214 | int gx1, int gy1, int gx2, int gy2,
|
---|
215 | i4_status_class *status,
|
---|
216 | i4_bool interlaced)
|
---|
217 | {
|
---|
218 | g1_map_class *map=g1_get_map();
|
---|
219 |
|
---|
220 | int map_width=map->width(), map_height=map->height();
|
---|
221 | if (gx1>0)
|
---|
222 | gx1-=1;
|
---|
223 | if (gy1>0)
|
---|
224 | gy1-=1;
|
---|
225 |
|
---|
226 | if (gy2<map_height-1)
|
---|
227 | gy2+=1;
|
---|
228 | if (gx2<map_width-1)
|
---|
229 | gx2+=1;
|
---|
230 |
|
---|
231 | const i4_pal *pal=i4_current_app->get_display()->get_palette();
|
---|
232 | calc_tables();
|
---|
233 |
|
---|
234 | float map_x, map_y, map_x_step, map_y_step;
|
---|
235 |
|
---|
236 |
|
---|
237 | sw32 x,y;
|
---|
238 | float r,g,b;
|
---|
239 | float im_y1, im_x1, im_x2, im_y2;
|
---|
240 | p->game_2_mouse(gx1,gy1, im_x1, im_y1);
|
---|
241 | p->game_2_mouse(gx2,gy2, im_x2, im_y2);
|
---|
242 | int i_im_y1=i4_f_to_i(im_y1), i_im_x1=i4_f_to_i(im_x1);
|
---|
243 | int i_im_y2=i4_f_to_i(im_y2), i_im_x2=i4_f_to_i(im_x2);
|
---|
244 |
|
---|
245 |
|
---|
246 | float map_x_start, map_y_start;
|
---|
247 | p->mouse_2_game(i_im_x1, i_im_y1, map_x_start, map_y_start);
|
---|
248 |
|
---|
249 |
|
---|
250 | map_x_step=p->m2gx;
|
---|
251 | map_y_step=p->m2gy;
|
---|
252 |
|
---|
253 | map_y=map_y_start;
|
---|
254 | if (interlaced)
|
---|
255 | i_im_y1=i_im_y1&(~1);
|
---|
256 |
|
---|
257 |
|
---|
258 | for (y=i_im_y1; y>=i_im_y2;)
|
---|
259 | {
|
---|
260 | if (status)
|
---|
261 | status->update(map_y/(float)g1_get_map()->height());
|
---|
262 |
|
---|
263 | map_x=map_x_start;
|
---|
264 |
|
---|
265 | // assuming 16bit
|
---|
266 | w16 *i1 = (w16 *)(((w8 *)im->data) + im->bpl*y + i_im_x1*2);
|
---|
267 |
|
---|
268 | for (x=i_im_x1; x<=i_im_x2; x++)
|
---|
269 | {
|
---|
270 | int i_map_x=i4_f_to_i(map_x), i_map_y=i4_f_to_i(map_y);
|
---|
271 | g1_map_cell_class *cell1 = map->cell(i_map_x, i_map_y);
|
---|
272 | w32 color;
|
---|
273 |
|
---|
274 | if (i_map_x<map_width-1 && i_map_y<map_height-1)
|
---|
275 | {
|
---|
276 | int ratio=i4_f_to_i((map_x-i_map_x)*32.0);
|
---|
277 |
|
---|
278 | g1_map_vertex_class *v=map->vertex(i_map_x, i_map_y);
|
---|
279 |
|
---|
280 | if (v[0].light_sum & 0x80000000)
|
---|
281 | v[0].recalc_light_sum(i_map_x, i_map_y);
|
---|
282 |
|
---|
283 | if (v[1].light_sum & 0x80000000)
|
---|
284 | v[1].recalc_light_sum(i_map_x+1, i_map_y);
|
---|
285 |
|
---|
286 | int lv1=v[0].light_sum;
|
---|
287 | int lv2=v[1].light_sum;
|
---|
288 |
|
---|
289 |
|
---|
290 | int c1=get_mat_color(cell1);
|
---|
291 | int c2=get_mat_color(cell1+1);
|
---|
292 |
|
---|
293 | // seperate color components
|
---|
294 |
|
---|
295 | c1>>=3;
|
---|
296 | int b1=c1&31; c1>>=8;
|
---|
297 | int g1=c1&31; c1>>=8;
|
---|
298 | int r1=c1&31;
|
---|
299 |
|
---|
300 | c2>>=3;
|
---|
301 | int b2=c2&31; c2>>=8;
|
---|
302 | int g2=c2&31; c2>>=8;
|
---|
303 | int r2=c2&31;
|
---|
304 |
|
---|
305 |
|
---|
306 | lv1>>=3;
|
---|
307 | int lv1r=lv1&31; lv1>>=8;
|
---|
308 | int lv1g=lv1&31; lv1>>=8;
|
---|
309 | int lv1b=lv1&31;
|
---|
310 |
|
---|
311 | lv2>>=3;
|
---|
312 | int lv2r=lv2&31; lv2>>=8;
|
---|
313 | int lv2g=lv2&31; lv2>>=8;
|
---|
314 | int lv2b=lv2&31;
|
---|
315 |
|
---|
316 |
|
---|
317 | // interpolate color
|
---|
318 | int ur=interpolate_555(r1, r2, ratio);
|
---|
319 | int ug=interpolate_555(g1, g2, ratio);
|
---|
320 | int ub=interpolate_555(b1, b2, ratio);
|
---|
321 |
|
---|
322 | // interpolate light value
|
---|
323 | int lvr=interpolate_555(lv1r, lv2r, ratio);
|
---|
324 | int lvg=interpolate_555(lv1g, lv2g, ratio);
|
---|
325 | int lvb=interpolate_555(lv1b, lv2b, ratio);
|
---|
326 |
|
---|
327 | // apply lighting
|
---|
328 | int r = light_555(ur, lvr);
|
---|
329 | int g = light_555(ug, lvg);
|
---|
330 | int b = light_555(ub, lvb);
|
---|
331 |
|
---|
332 |
|
---|
333 | color = (r<<r_shift) | (g<<g_shift) | (b<<b_shift);
|
---|
334 | }
|
---|
335 | else
|
---|
336 | {
|
---|
337 | g1_map_vertex_class *v1=map->vertex(i_map_x, i_map_y);
|
---|
338 | if (v1[0].light_sum & 0x80000000)
|
---|
339 | v1[0].recalc_light_sum(i_map_x, i_map_y);
|
---|
340 |
|
---|
341 | int lv1=v1[0].light_sum;
|
---|
342 | lv1>>=3;
|
---|
343 | int lv1r=lv1&31; lv1>>=8;
|
---|
344 | int lv1g=lv1&31; lv1>>=8;
|
---|
345 | int lv1b=lv1&31;
|
---|
346 |
|
---|
347 | int c1=get_mat_color(cell1);
|
---|
348 |
|
---|
349 | // seperate color components
|
---|
350 | c1>>=3;
|
---|
351 | int b1=c1&31; c1>>=8;
|
---|
352 | int g1=c1&31; c1>>=8;
|
---|
353 | int r1=c1&31;
|
---|
354 |
|
---|
355 |
|
---|
356 | // apply lighting
|
---|
357 | int r = light_555(r1, lv1r);
|
---|
358 | int g = light_555(g1, lv1g);
|
---|
359 | int b = light_555(b1, lv1b);
|
---|
360 | color = (r<<r_shift) | (g<<g_shift) | (b<<b_shift);
|
---|
361 | }
|
---|
362 |
|
---|
363 | *i1=color;
|
---|
364 |
|
---|
365 | map_x+=map_x_step;
|
---|
366 | ++i1;
|
---|
367 | }
|
---|
368 |
|
---|
369 | map_y+=map_y_step;
|
---|
370 | y--;
|
---|
371 | if (interlaced)
|
---|
372 | {
|
---|
373 | y--;
|
---|
374 | map_y+=map_y_step;
|
---|
375 | }
|
---|
376 |
|
---|
377 | }
|
---|
378 |
|
---|
379 |
|
---|
380 |
|
---|
381 | }
|
---|
382 |
|
---|
383 | i4_image_class *g1_create_map_image(int max_width, int max_height,
|
---|
384 | i4_bool interlace)
|
---|
385 | {
|
---|
386 | i4_status_class *status=i4_create_status(i4gets("rendering_map"));
|
---|
387 |
|
---|
388 | const i4_pal *pal=i4_current_app->get_display()->get_palette();
|
---|
389 | i4_image_class *im = i4_create_image(max_width, max_height, pal);
|
---|
390 | i4_draw_context_class context(0,0, max_width-1, max_height-1);
|
---|
391 | im->clear(0, context);
|
---|
392 |
|
---|
393 | radar_darkness_multiply = 1.0/(255.0 * li_get_float(li_get_value("radar_darkness"),0));
|
---|
394 |
|
---|
395 |
|
---|
396 | g1_radar_params_struct p;
|
---|
397 | p.init(max_width, max_height);
|
---|
398 |
|
---|
399 | g1_render_map_area(im, &p, 0,0, g1_get_map()->width()-1,
|
---|
400 | g1_get_map()->height()-1, status, interlace);
|
---|
401 |
|
---|
402 | // g1_draw_takeover_spots(im);
|
---|
403 | // g1_draw_paths(im, 0);
|
---|
404 |
|
---|
405 | g1_draw_strategy_border(im);
|
---|
406 |
|
---|
407 | delete status;
|
---|
408 |
|
---|
409 | return im;
|
---|
410 | }
|
---|
411 |
|
---|
412 |
|
---|
413 |
|
---|
414 | static void quick_add(i4_rect_list_class &list, int x1, int y1, int x2, int y2)
|
---|
415 | {
|
---|
416 | i4_rect_list_class::area_iter i;
|
---|
417 | for (i=list.list.begin(); i!=list.list.end(); ++i)
|
---|
418 | {
|
---|
419 | if (((i->x1<=x2 && i->x1>=x1) ||
|
---|
420 | (i->x2<=x2 && i->x2>=x1)) &&
|
---|
421 | ((i->y1<=y2 && i->y1>=y1) ||
|
---|
422 | (i->y2<=y2 && i->y2>=y1)))
|
---|
423 | {
|
---|
424 | i->x1=i->x1 < x1 ? i->x1 : x1;
|
---|
425 | i->y1=i->y1 < y1 ? i->y1 : y1;
|
---|
426 | i->x2=i->x2 > x2 ? i->x2 : x2;
|
---|
427 | i->y2=i->y2 > y2 ? i->y2 : y2;
|
---|
428 |
|
---|
429 | return ;
|
---|
430 | }
|
---|
431 | }
|
---|
432 |
|
---|
433 | list.list.insert(*(list.new_area(x1,y1,x2,y2)));
|
---|
434 | }
|
---|
435 |
|
---|
436 |
|
---|
437 | //////////////////////////////////////////////////////////////////////////////
|
---|
438 | // radar window management
|
---|
439 | //////////////////////////////////////////////////////////////////////////////
|
---|
440 | class g1_radar_view_class : public i4_parent_window_class
|
---|
441 | {
|
---|
442 | public:
|
---|
443 | g1_radar_view_class *next;
|
---|
444 | i4_image_class *background;
|
---|
445 | i4_bool grabbing;
|
---|
446 | g1_radar_params_struct setup;
|
---|
447 | int flags;
|
---|
448 | i4_bool restore_strategy_on_top;
|
---|
449 | int grab_x, grab_y, grab_x_end, grab_y_end;
|
---|
450 |
|
---|
451 | struct controller_win
|
---|
452 | {
|
---|
453 | int x,y,w,h;
|
---|
454 | };
|
---|
455 |
|
---|
456 | g1_radar_view_class(w16 w, w16 h, int flags)
|
---|
457 |
|
---|
458 | : i4_parent_window_class(w,h),
|
---|
459 | flags(flags)
|
---|
460 | {
|
---|
461 | restore_strategy_on_top=i4_F;
|
---|
462 | next=list;
|
---|
463 | list=this;
|
---|
464 | background=0;
|
---|
465 |
|
---|
466 | grabbing=i4_F;
|
---|
467 |
|
---|
468 | recalc_background();
|
---|
469 | }
|
---|
470 |
|
---|
471 |
|
---|
472 | void recalc_background()
|
---|
473 | {
|
---|
474 | if (background)
|
---|
475 | {
|
---|
476 | delete background;
|
---|
477 | background=0;
|
---|
478 | }
|
---|
479 |
|
---|
480 | if (g1_map_is_loaded())
|
---|
481 | {
|
---|
482 | background=g1_create_map_image(width(), height(), flags & G1_RADAR_INTERLACED);
|
---|
483 | setup.init(background->width(), background->height());
|
---|
484 | }
|
---|
485 | }
|
---|
486 |
|
---|
487 | void push_in(float &gx, float &gy)
|
---|
488 | {
|
---|
489 | enum {B=6};
|
---|
490 | if (gx<B) gx=B;
|
---|
491 | if (gx>g1_get_map()->width()-1-B) gx=g1_get_map()->width()-1-B;
|
---|
492 | if (gy<B) gy=B;
|
---|
493 | if (gy>g1_get_map()->height()-1-B) gy=g1_get_map()->height()-1-B;
|
---|
494 | }
|
---|
495 |
|
---|
496 | void receive_event(i4_event *ev)
|
---|
497 | {
|
---|
498 | switch (ev->type())
|
---|
499 | {
|
---|
500 | case i4_event::MOUSE_BUTTON_DOWN:
|
---|
501 | {
|
---|
502 | CAST_PTR(bev, i4_mouse_button_down_event_class, ev);
|
---|
503 | float gx,gy;
|
---|
504 | setup.mouse_2_game(bev->x, bev->y, gx,gy);
|
---|
505 | push_in(gx,gy);
|
---|
506 |
|
---|
507 |
|
---|
508 | if (bev->left())
|
---|
509 | {
|
---|
510 |
|
---|
511 | if (flags & G1_RADAR_CLICK_SELECTS_PATH)
|
---|
512 | {
|
---|
513 | g1_human->player_clicked(0, gx,gy);
|
---|
514 | request_redraw(i4_F);
|
---|
515 | }
|
---|
516 | else if (g1_current_view_state())
|
---|
517 | {
|
---|
518 | if (!(flags & G1_RADAR_CLICK_HOLDS_VIEW))
|
---|
519 | {
|
---|
520 | g1_current_view_state()->suggest_camera_mode(G1_STRATEGY_MODE);
|
---|
521 | if (g1_border->strategy_on_top)
|
---|
522 | {
|
---|
523 | restore_strategy_on_top=i4_T;
|
---|
524 | li_call("strategy_on_bottom");
|
---|
525 | }
|
---|
526 |
|
---|
527 | }
|
---|
528 |
|
---|
529 | g1_current_view_state()->set_camera_position(gx,gy);
|
---|
530 |
|
---|
531 | grab_x=grab_x_end=bev->x;
|
---|
532 | grab_y=grab_y_end=bev->y;
|
---|
533 |
|
---|
534 | i4_window_request_mouse_grab_class grab(this);
|
---|
535 | i4_kernel.send_event(parent, &grab);
|
---|
536 | grabbing=i4_T;
|
---|
537 |
|
---|
538 | }
|
---|
539 | }
|
---|
540 | else if (bev->right() && g1_border.get() && g1_border->strategy_on_top)
|
---|
541 | g1_current_view_state()->set_camera_position(gx,gy);
|
---|
542 |
|
---|
543 |
|
---|
544 | } break;
|
---|
545 |
|
---|
546 |
|
---|
547 | case i4_event::MOUSE_BUTTON_UP :
|
---|
548 | {
|
---|
549 | CAST_PTR(bev, i4_mouse_button_down_event_class, ev);
|
---|
550 | if (bev->left())
|
---|
551 | {
|
---|
552 | if (grabbing)
|
---|
553 | {
|
---|
554 | if (!(flags & G1_RADAR_CLICK_HOLDS_VIEW))
|
---|
555 | {
|
---|
556 | if (restore_strategy_on_top)
|
---|
557 | {
|
---|
558 | restore_strategy_on_top=i4_F;
|
---|
559 | li_call("strategy_on_top");
|
---|
560 | }
|
---|
561 |
|
---|
562 | g1_current_view_state()->suggest_camera_mode(G1_ACTION_MODE);
|
---|
563 | }
|
---|
564 |
|
---|
565 | i4_window_request_mouse_ungrab_class ungrab(this);
|
---|
566 | i4_kernel.send_event(parent,&ungrab);
|
---|
567 | grabbing=i4_F;
|
---|
568 | }
|
---|
569 | }
|
---|
570 | } break;
|
---|
571 |
|
---|
572 | case i4_event::MOUSE_MOVE :
|
---|
573 | {
|
---|
574 | CAST_PTR(bev, i4_mouse_move_event_class, ev);
|
---|
575 | float gx,gy,mx,my;
|
---|
576 |
|
---|
577 | if (grabbing)
|
---|
578 | {
|
---|
579 | grab_x_end+=bev->x-bev->lx;
|
---|
580 | grab_y_end+=bev->y-bev->ly;
|
---|
581 |
|
---|
582 | float mouse_move_scale=width()/5000.0;
|
---|
583 |
|
---|
584 | mx=((grab_x_end-grab_x) * mouse_move_scale + grab_x);
|
---|
585 | my=((grab_y_end-grab_y) * mouse_move_scale + grab_y);
|
---|
586 | }
|
---|
587 | else
|
---|
588 | {
|
---|
589 | mx=bev->x;
|
---|
590 | my=bev->y;
|
---|
591 | }
|
---|
592 |
|
---|
593 |
|
---|
594 | // if ((flags & G1_RADAR_CLICK_HOLDS_VIEW)==0 || grabbing)
|
---|
595 | // {
|
---|
596 | // setup.mouse_2_game(mx, my, gx,gy);
|
---|
597 | // push_in(gx,gy);
|
---|
598 |
|
---|
599 | // if ((flags & G1_RADAR_CLICK_HOLDS_VIEW)==0)
|
---|
600 | // g1_current_view_state()->suggest_camera_mode(G1_STRATEGY_MODE);
|
---|
601 |
|
---|
602 | // g1_current_view_state()->set_camera_position(gx,gy);
|
---|
603 | // }
|
---|
604 |
|
---|
605 | } break;
|
---|
606 |
|
---|
607 | // case i4_event::WINDOW_MESSAGE:
|
---|
608 | // {
|
---|
609 | // CAST_PTR(wev, i4_window_message_class, ev);
|
---|
610 | // if (wev->sub_type==i4_window_message_class::LOST_MOUSE_FOCUS &&
|
---|
611 | // (flags & G1_RADAR_CLICK_HOLDS_VIEW)==0)
|
---|
612 | // g1_current_view_state()->suggest_camera_mode(G1_ACTION_MODE);
|
---|
613 | // else if (wev->sub_type==i4_window_message_class::GOT_MOUSE_FOCUS &&
|
---|
614 | // (flags & G1_RADAR_CLICK_HOLDS_VIEW)==0)
|
---|
615 | // g1_current_view_state()->suggest_camera_mode(G1_STRATEGY_MODE);
|
---|
616 | // else
|
---|
617 | // i4_parent_window_class::receive_event(ev);
|
---|
618 | // } break;
|
---|
619 |
|
---|
620 | default:
|
---|
621 | i4_parent_window_class::receive_event(ev);
|
---|
622 | }
|
---|
623 |
|
---|
624 | }
|
---|
625 |
|
---|
626 |
|
---|
627 |
|
---|
628 | void draw_all_paths(g1_team_type team,
|
---|
629 | g1_path_object_class *po,
|
---|
630 | w32 color,
|
---|
631 | i4_draw_context_class &context)
|
---|
632 | {
|
---|
633 | if (po)
|
---|
634 | {
|
---|
635 | int ix=i4_f_to_i(po->x), iy=i4_f_to_i(po->y);
|
---|
636 | if ((flags & G1_RADAR_DRAW_ALL_PATHS) ||
|
---|
637 | (g1_cells[ix+iy*g1_map_width].flags & g1_map_cell_class::FOGGED)==0)
|
---|
638 | {
|
---|
639 | int t=po->total_links(team);
|
---|
640 | for (int k=0; k<t; k++)
|
---|
641 | {
|
---|
642 | g1_path_object_class *p2=po->get_link(team,k);
|
---|
643 | if (p2)
|
---|
644 | {
|
---|
645 | float x1,y1,x2,y2;
|
---|
646 | setup.game_2_mouse(po->x, po->y, x1,y1);
|
---|
647 | setup.game_2_mouse(p2->x, p2->y, x2,y2);
|
---|
648 | local_image->line(i4_f_to_i(x1), i4_f_to_i(y1),
|
---|
649 | i4_f_to_i(x2), i4_f_to_i(y2),
|
---|
650 | color, context);
|
---|
651 |
|
---|
652 | draw_all_paths(team, p2, color, context);
|
---|
653 | }
|
---|
654 | }
|
---|
655 | }
|
---|
656 | }
|
---|
657 | }
|
---|
658 |
|
---|
659 |
|
---|
660 |
|
---|
661 |
|
---|
662 | void draw_recent_path(g1_team_type team,
|
---|
663 | g1_path_object_class *po,
|
---|
664 | w32 color,
|
---|
665 | i4_draw_context_class &context)
|
---|
666 | {
|
---|
667 | if (po)
|
---|
668 | {
|
---|
669 | int ix=i4_f_to_i(po->x), iy=i4_f_to_i(po->y);
|
---|
670 | if ((flags & G1_RADAR_DRAW_ALL_PATHS) ||
|
---|
671 | (g1_cells[ix+iy*g1_map_width].flags & g1_map_cell_class::FOGGED)==0)
|
---|
672 | {
|
---|
673 | g1_path_object_class *p2=po->get_recent_link(team, 0);
|
---|
674 | if (p2)
|
---|
675 | {
|
---|
676 | float x1,y1,x2,y2;
|
---|
677 | setup.game_2_mouse(po->x, po->y, x1,y1);
|
---|
678 | setup.game_2_mouse(p2->x, p2->y, x2,y2);
|
---|
679 | local_image->line(i4_f_to_i(x1), i4_f_to_i(y1),
|
---|
680 | i4_f_to_i(x2), i4_f_to_i(y2),
|
---|
681 | color, context);
|
---|
682 |
|
---|
683 | draw_recent_path(team, p2, color, context);
|
---|
684 | }
|
---|
685 | }
|
---|
686 | }
|
---|
687 | }
|
---|
688 |
|
---|
689 |
|
---|
690 |
|
---|
691 |
|
---|
692 |
|
---|
693 | void parent_draw(i4_draw_context_class &context)
|
---|
694 | {
|
---|
695 | if (background)
|
---|
696 | {
|
---|
697 | if (flags & G1_RADAR_USE_DIRTIES)
|
---|
698 | {
|
---|
699 | i4_rect_list_class::area_iter i;
|
---|
700 | for (i=undrawn_area.list.begin(); i!=undrawn_area.list.end(); ++i)
|
---|
701 | {
|
---|
702 | int x=i->x1, y=i->y1;
|
---|
703 | background->put_part(local_image, x,y, i->x1, i->y1, i->x2, i->y2, context);
|
---|
704 | }
|
---|
705 | }
|
---|
706 | else if (background)
|
---|
707 | background->put_image(local_image,0,0, context);
|
---|
708 |
|
---|
709 | int radius[5]={0, (int)(0.5 * setup.g2mx), (int)(1.0 * setup.g2mx),
|
---|
710 | (int)(0.1 * setup.g2mx),
|
---|
711 | (int)(2.0 * setup.g2mx)};
|
---|
712 | float ix,iy;
|
---|
713 |
|
---|
714 | int map_width=g1_get_map()->width();
|
---|
715 |
|
---|
716 |
|
---|
717 | int i;
|
---|
718 | w32 color;
|
---|
719 | for (i=0; i<G1_MAX_PLAYERS; i++)
|
---|
720 | {
|
---|
721 | g1_team_type team=g1_player_man.get(i)->get_team();
|
---|
722 |
|
---|
723 | color=g1_player_man.get(i)->map_player_color;
|
---|
724 |
|
---|
725 | i4_array<w32> &a=g1_player_man.get(i)->owned_objects;
|
---|
726 | int t=a.size();
|
---|
727 | for (int j=0; j<t; j++)
|
---|
728 | {
|
---|
729 | g1_object_class *p=g1_global_id.checked_get(a[j]);
|
---|
730 |
|
---|
731 | if (p && p->radar_type!=G1_RADAR_NONE)
|
---|
732 | {
|
---|
733 | int cx=i4_f_to_i(p->x);
|
---|
734 | int cy=i4_f_to_i(p->y);
|
---|
735 |
|
---|
736 | if ((g1_cells[map_width * cy + cx].flags & g1_map_cell_class::FOGGED)==0)
|
---|
737 | {
|
---|
738 | setup.game_2_mouse(p->x, p->y, ix,iy);
|
---|
739 |
|
---|
740 |
|
---|
741 | if ((flags & G1_RADAR_USE_ICONS)==0 || !p->radar_image)
|
---|
742 | {
|
---|
743 | int r=radius[p->radar_type];
|
---|
744 |
|
---|
745 | int ix1=i4_f_to_i(ix)-r, iy1=i4_f_to_i(iy)-r;
|
---|
746 | int ix2=i4_f_to_i(ix)+r, iy2=i4_f_to_i(iy)+r;
|
---|
747 | local_image->bar(ix1-1,iy1-1,ix2+1,iy2+1, 0, context);
|
---|
748 | local_image->bar(ix1,iy1,ix2,iy2, color, context);
|
---|
749 | }
|
---|
750 | }
|
---|
751 | }
|
---|
752 | }
|
---|
753 | }
|
---|
754 |
|
---|
755 | g1_team_type my_team=g1_player_man.get_local()->get_team();
|
---|
756 |
|
---|
757 | if (flags & G1_RADAR_DRAW_UNHIDDEN_PATHS)
|
---|
758 | {
|
---|
759 | g1_factory_class *f;
|
---|
760 | for (f=g1_factory_list.first(); f; f=f->next)
|
---|
761 | {
|
---|
762 | if (g1_player_man.get(f->player_num)->get_team()==my_team)
|
---|
763 | {
|
---|
764 | g1_path_object_class *start=f->get_start();
|
---|
765 | if (start)
|
---|
766 | {
|
---|
767 | draw_all_paths(my_team, start, f->get_path_color(),
|
---|
768 | context);
|
---|
769 |
|
---|
770 | draw_recent_path(my_team, start, f->get_selected_path_color(),
|
---|
771 | context);
|
---|
772 | }
|
---|
773 | }
|
---|
774 | }
|
---|
775 | }
|
---|
776 |
|
---|
777 | if (flags & G1_RADAR_USE_ICONS)
|
---|
778 | {
|
---|
779 | for (i=0; i<G1_MAX_PLAYERS; i++)
|
---|
780 | {
|
---|
781 | i4_array<w32> &a=g1_player_man.get(i)->owned_objects;
|
---|
782 | int t=a.size();
|
---|
783 |
|
---|
784 | for (int j=0; j<t; j++)
|
---|
785 | {
|
---|
786 | g1_object_class *p=g1_global_id.checked_get(a[j]);
|
---|
787 |
|
---|
788 | if (p && p->radar_image)
|
---|
789 | {
|
---|
790 | int cx=i4_f_to_i(p->x);
|
---|
791 | int cy=i4_f_to_i(p->y);
|
---|
792 |
|
---|
793 | if ((g1_cells[map_width * cy + cx].flags & g1_map_cell_class::FOGGED)==0)
|
---|
794 | {
|
---|
795 | setup.game_2_mouse(p->x, p->y, ix,iy);
|
---|
796 |
|
---|
797 |
|
---|
798 | i4_image_class *i=p->radar_image->tinted_icons[p->player_num];
|
---|
799 | int ix1=i4_f_to_i(ix)-i->width()/2;
|
---|
800 | int iy1=i4_f_to_i(iy)-i->height()/2;
|
---|
801 |
|
---|
802 | i->put_image(local_image, ix1,iy1,context);
|
---|
803 | }
|
---|
804 | }
|
---|
805 | }
|
---|
806 | }
|
---|
807 | }
|
---|
808 |
|
---|
809 |
|
---|
810 | // draw_paths();
|
---|
811 |
|
---|
812 |
|
---|
813 | } else local_image->clear(0, context);
|
---|
814 | }
|
---|
815 |
|
---|
816 |
|
---|
817 | void refresh_area(int gx1, int gy1, int gx2, int gy2)
|
---|
818 | {
|
---|
819 | g1_render_map_area(background,
|
---|
820 | &setup, gx1,gy1,gx2,gy2,
|
---|
821 | 0, (flags & G1_RADAR_INTERLACED) ? i4_T : i4_F);
|
---|
822 |
|
---|
823 |
|
---|
824 |
|
---|
825 | request_redraw(i4_F);
|
---|
826 | }
|
---|
827 |
|
---|
828 |
|
---|
829 | ~g1_radar_view_class()
|
---|
830 | {
|
---|
831 | if (background)
|
---|
832 | {
|
---|
833 | delete background;
|
---|
834 | background=0;
|
---|
835 | }
|
---|
836 |
|
---|
837 | if (this==list)
|
---|
838 | list=list->next;
|
---|
839 | else
|
---|
840 | {
|
---|
841 | g1_radar_view_class *p=list;
|
---|
842 | while (p->next!=this)
|
---|
843 | p=p->next;
|
---|
844 | p->next=next;
|
---|
845 | }
|
---|
846 | }
|
---|
847 |
|
---|
848 | char *name() { return "radar_view"; }
|
---|
849 | };
|
---|
850 |
|
---|
851 |
|
---|
852 |
|
---|
853 |
|
---|
854 |
|
---|
855 | void g1_radar_recalculate_backgrounds()
|
---|
856 | {
|
---|
857 | for (g1_radar_view_class *v=list; v; v=v->next)
|
---|
858 | v->recalc_background();
|
---|
859 | }
|
---|
860 |
|
---|
861 | void g1_radar_looking_at(float x1, float y1, float x2, float y2)
|
---|
862 | {
|
---|
863 | }
|
---|
864 |
|
---|
865 |
|
---|
866 | i4_parent_window_class *g1_create_radar_view(int max_w, int max_h, int flags)
|
---|
867 | {
|
---|
868 | g1_radar_view_class *rv=new g1_radar_view_class(max_w, max_h, flags);
|
---|
869 | return rv;
|
---|
870 | }
|
---|
871 |
|
---|
872 |
|
---|
873 |
|
---|
874 | void g1_radar_refresh(int game_x1, int game_y1, int game_x2, int game_y2)
|
---|
875 | {
|
---|
876 | for (g1_radar_view_class *v=list; v; v=v->next)
|
---|
877 | v->refresh_area(game_x1, game_y1, game_x2, game_y2);
|
---|
878 | }
|
---|
879 |
|
---|
880 | void g1_radar_update()
|
---|
881 | {
|
---|
882 | for (g1_radar_view_class *v=list; v; v=v->next)
|
---|
883 | v->request_redraw(i4_F);
|
---|
884 | }
|
---|
885 |
|
---|
886 |
|
---|
887 | void g1_unfog_radius(const i4_3d_vector &v, float r)
|
---|
888 | {
|
---|
889 | int fog_rect_x1=10000, fog_rect_y1=10000,
|
---|
890 | fog_rect_x2=-1, fog_rect_y2=-1, ix,iy;
|
---|
891 |
|
---|
892 | g1_map_class *map=g1_get_map();
|
---|
893 |
|
---|
894 | int x_left = i4_f_to_i(v.x-r); if (x_left<0) x_left=0;
|
---|
895 | int x_right = i4_f_to_i(v.x+r); if (x_right>=map->width()) x_right=map->width()-1;
|
---|
896 | int y_top = i4_f_to_i(v.y-r); if (y_top<0) y_top=0;
|
---|
897 | int y_bottom = i4_f_to_i(v.y+r); if (y_bottom>=map->height()) y_bottom=map->height()-1;
|
---|
898 |
|
---|
899 | for (iy=y_top; iy<=y_bottom; iy++)
|
---|
900 | {
|
---|
901 | g1_map_cell_class *c=map->cell(x_left,iy);
|
---|
902 | for (ix=x_left; ix<=x_right; ix++)
|
---|
903 | {
|
---|
904 | if (c->flags & g1_map_cell_class::FOGGED)
|
---|
905 | {
|
---|
906 | c->unfog(ix, iy);
|
---|
907 | if (ix<fog_rect_x1) fog_rect_x1=ix;
|
---|
908 | if (ix>fog_rect_x2) fog_rect_x2=ix;
|
---|
909 | if (iy<fog_rect_y1) fog_rect_y1=iy;
|
---|
910 | if (iy>fog_rect_y2) fog_rect_y2=iy;
|
---|
911 | }
|
---|
912 | c++;
|
---|
913 | }
|
---|
914 |
|
---|
915 | }
|
---|
916 |
|
---|
917 | if (fog_rect_x2!=-1)
|
---|
918 | g1_radar_refresh(fog_rect_x1, fog_rect_y1, fog_rect_x2, fog_rect_y2);
|
---|
919 |
|
---|
920 | }
|
---|