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 |
|
---|
10 | #include "editor/mode/e_ai.hh"
|
---|
11 | #include "editor/e_state.hh"
|
---|
12 | #include "critical_graph.hh"
|
---|
13 | #include "map.hh"
|
---|
14 | #include "map_man.hh"
|
---|
15 | #include "g1_render.hh"
|
---|
16 | #include "editor/contedit.hh"
|
---|
17 | #include "editor/editor.hh"
|
---|
18 | #include "gui/butbox.hh"
|
---|
19 |
|
---|
20 | g1_ai_params g1_e_ai;
|
---|
21 |
|
---|
22 | g1_mode_handler::state g1_ai_mode::current_state()
|
---|
23 | {
|
---|
24 | w8 remap[]={ ROTATE,
|
---|
25 | ZOOM,
|
---|
26 | DRAG_SELECT,
|
---|
27 | DRAG_SELECT,
|
---|
28 | OTHER,
|
---|
29 | OTHER
|
---|
30 | };
|
---|
31 |
|
---|
32 | I4_ASSERT(g1_edit_state.ai.minor_mode<=sizeof(remap), "state too big");
|
---|
33 |
|
---|
34 | return (g1_mode_handler::state)remap[g1_e_ai.get_minor_mode()];
|
---|
35 | }
|
---|
36 |
|
---|
37 |
|
---|
38 | g1_ai_mode::g1_ai_mode(g1_controller_edit_class *c)
|
---|
39 | : g1_mode_handler(c)
|
---|
40 | {
|
---|
41 | sel_color=0xffff00;
|
---|
42 | norm_color=0x7f7f7f;
|
---|
43 | }
|
---|
44 |
|
---|
45 |
|
---|
46 | void g1_ai_mode::post_draw(i4_draw_context_class &context)
|
---|
47 | {
|
---|
48 | g1_map_class *map=g1_get_map();
|
---|
49 | if (map)
|
---|
50 | {
|
---|
51 | g1_critical_graph_class *graph=map->get_critical_graph();
|
---|
52 | if (graph)
|
---|
53 | {
|
---|
54 | for (int i=1; i<graph->criticals; i++)
|
---|
55 | {
|
---|
56 | float x = graph->critical[i].x, y=graph->critical[i].y, z;
|
---|
57 | x = (float)((int)x)+0.5;
|
---|
58 | y = (float)((int)y)+0.5;
|
---|
59 |
|
---|
60 | z=map->terrain_height(x,y)+0.01;
|
---|
61 |
|
---|
62 | r1_vert rv;
|
---|
63 | int w1=2,w2=1;
|
---|
64 | if (g1_render.project_point(i4_3d_point_class(x,y,z),
|
---|
65 | rv, c->g1_context.transform))
|
---|
66 | {
|
---|
67 | w32 color;
|
---|
68 | if (graph->critical[i].selected)
|
---|
69 | color=sel_color;
|
---|
70 | else
|
---|
71 | color=norm_color;
|
---|
72 |
|
---|
73 |
|
---|
74 | r1_clip_clear_area((sw32)rv.px-w1, (sw32)rv.py-w1,
|
---|
75 | (sw32)rv.px+w1, (sw32)rv.py+w1,
|
---|
76 | 0, 0.02, *c->g1_context.context, g1_render.r_api);
|
---|
77 |
|
---|
78 | r1_clip_clear_area((sw32)rv.px-w2, (sw32)rv.py-w2,
|
---|
79 | (sw32)rv.px+w2, (sw32)rv.py+w2,
|
---|
80 | color, 0.01, *c->g1_context.context, g1_render.r_api);
|
---|
81 | }
|
---|
82 | }
|
---|
83 | }
|
---|
84 | }
|
---|
85 |
|
---|
86 | g1_mode_handler::post_draw(context);
|
---|
87 | }
|
---|
88 |
|
---|
89 | g1_critical_graph_class *g1_ai_mode::get_graph()
|
---|
90 | {
|
---|
91 | g1_map_class *map=g1_get_map();
|
---|
92 | if (map)
|
---|
93 | return map->get_critical_graph();
|
---|
94 | return 0;
|
---|
95 | }
|
---|
96 |
|
---|
97 | void g1_ai_mode::mouse_down()
|
---|
98 | {
|
---|
99 | if (g1_e_ai.get_minor_mode()==g1_ai_params::CREATE)
|
---|
100 | {
|
---|
101 | g1_critical_graph_class *graph=get_graph();
|
---|
102 | i4_float gx,gy, dx,dy;
|
---|
103 | if (!c->view_to_game(lx(), ly(), gx,gy, dx,dy))
|
---|
104 | return;
|
---|
105 |
|
---|
106 | g1_map_class *map=g1_get_map();
|
---|
107 | g1_editor_instance.add_undo(G1_MAP_CRITICAL_POINTS);
|
---|
108 | if (map) map->mark_for_recalc(G1_RECALC_CRITICAL_DATA);
|
---|
109 | graph->add_critical_point(gx, gy);
|
---|
110 | }
|
---|
111 | else g1_mode_handler::mouse_down();
|
---|
112 | }
|
---|
113 |
|
---|
114 |
|
---|
115 |
|
---|
116 | i4_bool g1_ai_mode::select_object(sw32 mx, sw32 my,
|
---|
117 | i4_float &ox, i4_float &oy, i4_float &oz,
|
---|
118 | select_modifier mod)
|
---|
119 | {
|
---|
120 | i4_bool change=i4_F;
|
---|
121 |
|
---|
122 |
|
---|
123 | no_more_move_undos=i4_F;
|
---|
124 |
|
---|
125 | g1_critical_graph_class *graph=get_graph();
|
---|
126 | if (!graph) return i4_F;
|
---|
127 | g1_map_class *map=g1_get_map();
|
---|
128 |
|
---|
129 | if (mod!=FOR_CURSOR_HINT)
|
---|
130 | g1_editor_instance.add_undo(G1_MAP_CRITICAL_POINTS);
|
---|
131 |
|
---|
132 | i4_bool ret=i4_F;
|
---|
133 | int t=graph->criticals;
|
---|
134 | for (int i=1; i<t && !ret; i++)
|
---|
135 | {
|
---|
136 | g1_critical_graph_class::critical_point_class *p=graph->critical+i;
|
---|
137 | float x=((int)p->x)+0.5, y=((int)p->y)+0.5, z;
|
---|
138 | z=map->terrain_height(x,y)+0.01;
|
---|
139 |
|
---|
140 | r1_vert rv;
|
---|
141 | if (g1_render.project_point(i4_3d_point_class(x,y,z), rv, c->g1_context.transform))
|
---|
142 | {
|
---|
143 | if (abs((sw32)rv.px-mx)<3 && abs((sw32)rv.py-my)<3)
|
---|
144 | {
|
---|
145 | ox=x; oy=y; oz=z;
|
---|
146 |
|
---|
147 | if (p->selected==0 && mod==CLEAR_OLD_IF_NO_SELECTION)
|
---|
148 | for (int j=1; j<t; j++)
|
---|
149 | graph->critical[j].selected=0;
|
---|
150 |
|
---|
151 | if (mod==CLEAR_OLD_IF_NO_SELECTION || mod==ADD_TO_OLD)
|
---|
152 | {
|
---|
153 | p->selected=1;
|
---|
154 | change=i4_T;
|
---|
155 | }
|
---|
156 | else if (mod==SUB_FROM_OLD)
|
---|
157 | {
|
---|
158 | p->selected=0;
|
---|
159 | change=i4_T;
|
---|
160 | }
|
---|
161 |
|
---|
162 | ret=i4_T;
|
---|
163 | }
|
---|
164 | }
|
---|
165 | }
|
---|
166 |
|
---|
167 | if (change)
|
---|
168 | {
|
---|
169 | c->changed();
|
---|
170 | c->refresh();
|
---|
171 | }
|
---|
172 |
|
---|
173 |
|
---|
174 | return ret;
|
---|
175 | }
|
---|
176 |
|
---|
177 | void g1_ai_mode::select_objects_in_area(sw32 x1, sw32 y1, sw32 x2, sw32 y2,
|
---|
178 | select_modifier mod)
|
---|
179 | {
|
---|
180 | no_more_move_undos=i4_F;
|
---|
181 |
|
---|
182 |
|
---|
183 | g1_critical_graph_class *graph=get_graph();
|
---|
184 | if (!graph) return;
|
---|
185 | g1_map_class *map=g1_get_map();
|
---|
186 |
|
---|
187 | g1_editor_instance.add_undo(G1_MAP_CRITICAL_POINTS);
|
---|
188 |
|
---|
189 | int t=graph->criticals;
|
---|
190 | for (int i=1; i<t; i++)
|
---|
191 | {
|
---|
192 | g1_critical_graph_class::critical_point_class *p=graph->critical+i;
|
---|
193 | float x=p->x, y=p->y, z;
|
---|
194 | z=map->terrain_height(x,y)+0.01;
|
---|
195 |
|
---|
196 | r1_vert rv;
|
---|
197 | if (g1_render.project_point(i4_3d_point_class(x,y,z), rv, c->g1_context.transform))
|
---|
198 | {
|
---|
199 | if (rv.px>=x1 && rv.px<=x2 && rv.py>=y1 && rv.py<=y2)
|
---|
200 | {
|
---|
201 | if (mod==SUB_FROM_OLD)
|
---|
202 | p->selected=0;
|
---|
203 | else
|
---|
204 | p->selected=1;
|
---|
205 | }
|
---|
206 | else if (mod==CLEAR_OLD_IF_NO_SELECTION)
|
---|
207 | p->selected=0;
|
---|
208 | }
|
---|
209 | }
|
---|
210 | }
|
---|
211 |
|
---|
212 | void g1_ai_mode::move_selected(i4_float xc, i4_float yc, i4_float zc,
|
---|
213 | sw32 mouse_x, sw32 mouse_y)
|
---|
214 | {
|
---|
215 | g1_critical_graph_class *graph=get_graph();
|
---|
216 | if (!graph) return;
|
---|
217 | g1_map_class *map=g1_get_map();
|
---|
218 |
|
---|
219 | g1_editor_instance.add_undo(G1_MAP_CRITICAL_POINTS);
|
---|
220 | map->mark_for_recalc(G1_RECALC_CRITICAL_DATA);
|
---|
221 |
|
---|
222 | int t=graph->criticals;
|
---|
223 | for (int i=1; i<t; i++)
|
---|
224 | {
|
---|
225 | g1_critical_graph_class::critical_point_class *p=graph->critical+i;
|
---|
226 | if (p->selected)
|
---|
227 | {
|
---|
228 | p->x+=xc; if (p->x<0) p->x=0; else if (p->x>=map->width()) p->x=map->width()-0.1;
|
---|
229 | p->y+=yc; if (p->y<0) p->y=0; else if (p->y>=map->height()) p->y=map->height()-0.1;
|
---|
230 | }
|
---|
231 | }
|
---|
232 | }
|
---|
233 |
|
---|
234 | void g1_ai_mode::delete_selected()
|
---|
235 | {
|
---|
236 | g1_critical_graph_class *graph=get_graph();
|
---|
237 | if (!graph) return;
|
---|
238 | g1_map_class *map=g1_get_map();
|
---|
239 |
|
---|
240 | g1_editor_instance.add_undo(G1_MAP_CRITICAL_POINTS);
|
---|
241 | map->mark_for_recalc(G1_RECALC_CRITICAL_DATA);
|
---|
242 |
|
---|
243 | for (int i=1; i<graph->criticals; i++)
|
---|
244 | {
|
---|
245 | if (graph->critical[i].selected)
|
---|
246 | {
|
---|
247 | for (int j=i;j<graph->criticals-1; j++)
|
---|
248 | graph->critical[j]=graph->critical[j+1];
|
---|
249 | graph->criticals--;
|
---|
250 | }
|
---|
251 | }
|
---|
252 | }
|
---|
253 |
|
---|
254 |
|
---|
255 |
|
---|
256 |
|
---|
257 | void g1_ai_params::create_buttons(i4_parent_window_class *container)
|
---|
258 | {
|
---|
259 | i4_button_box_class *box=new i4_button_box_class(&g1_edit_state);
|
---|
260 | char *rn[]={"aROTATE", "aZOOM", "aMOVE", "aSELECT", "aCREATE", 0 };
|
---|
261 | w32 i=ROTATE;
|
---|
262 |
|
---|
263 |
|
---|
264 | for (char **a=rn; *a; i++, a++)
|
---|
265 | g1_edit_state.add_but(box, *a, 0, (i4_bool) i==get_minor_mode(),
|
---|
266 | new g1_set_minor_mode_event("AI",i));
|
---|
267 |
|
---|
268 | box->arrange_right_down();
|
---|
269 |
|
---|
270 | i4_button_class *create=g1_edit_state.create_button("aRECALC", RECALC, i4_T);
|
---|
271 |
|
---|
272 | i4_graphical_style_class *s=get_style();
|
---|
273 | i4_color_window_class *cw=new i4_color_window_class(box->width(),
|
---|
274 | box->height()+create->height(),
|
---|
275 | s->color_hint->window.passive.medium,
|
---|
276 | s);
|
---|
277 | container->add_child(0, 0, box);
|
---|
278 | container->add_child(0, box->height(), create);
|
---|
279 |
|
---|
280 | }
|
---|
281 |
|
---|
282 |
|
---|
283 |
|
---|
284 |
|
---|
285 | i4_bool g1_ai_params::set_minor_mode(w8 m)
|
---|
286 | {
|
---|
287 | if (m<=CREATE)
|
---|
288 | minor_mode=(minor_mode_type)m;
|
---|
289 | if (m==RECALC)
|
---|
290 | {
|
---|
291 | g1_map_class *map=g1_get_map();
|
---|
292 | if (map)
|
---|
293 | {
|
---|
294 | map->mark_for_recalc(G1_RECALC_BLOCK_MAPS |
|
---|
295 | G1_RECALC_CRITICAL_DATA);
|
---|
296 | map->recalc_static_stuff();
|
---|
297 | }
|
---|
298 | }
|
---|
299 | return i4_T;
|
---|
300 | }
|
---|
301 |
|
---|
302 |
|
---|