1 /* Copyright (C) 1995-2002 FSGames. Ported by Sean Ford and Yan Shosh
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17 #include "scen.h"
18 #include "input.h"
19 #include "util.h"
20
21 /* Changelog
22 * 8/8/02: Zardus: added scrolling-by-minimap
23 * Zardus: added scrolling-by-keyboard
24 */
25
26 #include <string>
27 using namespace std;
28 #include <stdlib.h>
29 #define MINIMUM_TIME 0
30
31 // From picker // just emulate these so other files are happy
32 // Difficulty settings .. in percent, so 100 == normal
33 long current_difficulty = 1; // setting 'normal'
34 long difficulty_level[DIFFICULTY_SETTINGS] =
35 {
36 50,
37 100,
38 200,
39 }; // end of difficulty settings
40
41 FILE * open_misc_file(char *, char *, char *);
42
43 long do_load(screen *ascreen); // load a scenario or grid
44 long do_save(screen *ascreen); // save a scenario or grid
45 long score_panel(screen *myscreen);
46 long save_scenario(char * filename, screen * master, char *gridname);
47 void info_box(walker *target, screen * myscreen);
48 void set_facing(walker *target, screen *myscreen);
49 void set_name(walker *target, screen * myscreen);
50 void scenario_options(screen * myscreen);
51 long quit(long);
52
53 screen *myscreen; // global for scen?
54
55 // Zardus: our prefs object from view.cpp
56 extern options * theprefs;
57
58 // To appease the linker, we'll fake these from picker.cpp
59 long statcosts[NUM_FAMILIES][6];
60 long costlist[NUM_FAMILIES];
61
calculate_level(unsigned long howmuch)62 long calculate_level(unsigned long howmuch)
63 {
64 return (long) (howmuch/10);
65 }
66
67 long *mymouse;
68 char *mykeyboard;
69 //scenario *myscen = new scenario;
70 long currentmode = OBJECT_MODE;
71 unsigned long currentlevel = 1;
72 char scen_name[10] = "test";
73 char grid_name[10] = "test";
74
75 unsigned char *mypixdata[PIX_MAX+1];
76 char scenpalette[768];
77 long backcount=0, forecount = 0;
78 long myorder = ORDER_LIVING;
79 char currentteam = 0;
80 long event = 1; // need to redraw?
81 long levelchanged = 0; // has level changed?
82 long cyclemode = 0; // for color cycling
83 long grid_aligned = 1; // aligned by grid, default is on
84 //buffers: PORT: changed start_time to start_time_s to avoid conflict with
85 //input.cpp
86 long start_time_s; // for timer ops
87
88 smoother *mysmoother = NULL;
89
90 long backgrounds[] = {
91 PIX_GRASS1, PIX_GRASS2, PIX_GRASS_DARK_1, PIX_GRASS_DARK_2,
92 //PIX_GRASS_DARK_B1, PIX_GRASS_DARK_BR, PIX_GRASS_DARK_R1, PIX_GRASS_DARK_R2,
93 PIX_BOULDER_1, PIX_GRASS_DARK_LL, PIX_GRASS_DARK_UR, PIX_GRASS_RUBBLE,
94
95 PIX_GRASS_LIGHT_LEFT_TOP, PIX_GRASS_LIGHT_1,
96 PIX_GRASS_LIGHT_RIGHT_TOP, PIX_WATER1,
97
98 PIX_WATERGRASS_U, PIX_WATERGRASS_D,
99 PIX_WATERGRASS_L, PIX_WATERGRASS_R,
100
101 PIX_DIRTGRASS_UR1, PIX_DIRT_1, PIX_DIRT_1, PIX_DIRTGRASS_LL1,
102 PIX_DIRTGRASS_LR1, PIX_DIRT_DARK_1, PIX_DIRT_DARK_1, PIX_DIRTGRASS_UL1,
103
104 PIX_DIRTGRASS_DARK_UR1, PIX_DIRTGRASS_DARK_LL1,
105 PIX_DIRTGRASS_DARK_LR1, PIX_DIRTGRASS_DARK_UL1,
106
107 PIX_JAGGED_GROUND_1, PIX_JAGGED_GROUND_2,
108 PIX_JAGGED_GROUND_3, PIX_JAGGED_GROUND_4,
109
110 PIX_PATH_1, PIX_PATH_2, PIX_PATH_3, PIX_PATH_4,
111 PIX_COBBLE_1, PIX_COBBLE_2, PIX_COBBLE_3, PIX_COBBLE_4,
112
113 //PIX_WALL2, PIX_WALL3, PIX_WALL4, PIX_WALL5,
114
115 PIX_WALL4, PIX_WALL_ARROW_GRASS,
116 PIX_WALL_ARROW_FLOOR, PIX_WALL_ARROW_GRASS_DARK,
117
118 PIX_WALL2, PIX_WALL3, PIX_H_WALL1, PIX_WALL_LL,
119
120 PIX_WALLSIDE_L, PIX_WALLSIDE_C, PIX_WALLSIDE_R, PIX_WALLSIDE1,
121
122 PIX_WALLSIDE_CRACK_C1, PIX_WALLSIDE_CRACK_C1,
123 PIX_TORCH1, PIX_VOID1,
124
125 //PIX_VOID1, PIX_FLOOR1, PIX_VOID1, PIX_VOID1,
126
127 PIX_CARPET_SMALL_TINY, PIX_CARPET_M2, PIX_PAVEMENT1, PIX_FLOOR1,
128
129 //PIX_PAVEMENT1, PIX_PAVEMENT2, PIX_PAVEMENT3, PIX_PAVEMENT3,
130 PIX_FLOOR_PAVEL, PIX_FLOOR_PAVEU, PIX_FLOOR_PAVED, PIX_FLOOR_PAVED,
131
132 PIX_WALL_LL,
133 PIX_WALLTOP_H,
134 PIX_PAVESTEPS1,
135 PIX_BRAZIER1,
136
137 PIX_PAVESTEPS2L, PIX_PAVESTEPS2, PIX_PAVESTEPS2R, PIX_PAVESTEPS1,
138 //PIX_TORCH1, PIX_TORCH2, PIX_TORCH3, PIX_TORCH3,
139
140 PIX_COLUMN1, PIX_COLUMN2, PIX_COLUMN2, PIX_COLUMN2,
141
142 PIX_TREE_T1, PIX_TREE_T1, PIX_TREE_T1, PIX_TREE_T1,
143 PIX_TREE_ML, PIX_TREE_M1, PIX_TREE_MT, PIX_TREE_MR,
144 PIX_TREE_B1, PIX_TREE_B1, PIX_TREE_B1, PIX_TREE_B1,
145
146 PIX_CLIFF_BACK_L, PIX_CLIFF_BACK_1, PIX_CLIFF_BACK_2, PIX_CLIFF_BACK_R,
147 PIX_CLIFF_LEFT, PIX_CLIFF_BOTTOM, PIX_CLIFF_TOP, PIX_CLIFF_RIGHT,
148 PIX_CLIFF_LEFT, PIX_CLIFF_TOP_L, PIX_CLIFF_TOP_R, PIX_CLIFF_RIGHT,
149 };
150
151 long rowsdown = 0;
152 long maxrows = ((sizeof(backgrounds)/4) / 4);
153 text *scentext;
154
main(int argc,char ** argv)155 int main(int argc, char **argv)
156 {
157 cfg.commandline(argc, argv);
158 long i,j;
159 long extra;
160 // unsigned char input;
161 // char soundpath[80];
162 long windowx, windowy;
163 walker *newob;
164 long mx, my;
165 char mystring[80]; //, someletter;
166 // long pos;
167 short count;
168 // char buffer[80];
169 char * filepath;
170
171 //Zardus: add: init the input
172 init_input();
173
174 // Zardus: create dirs
175 create_dataopenglad();
176
177 filepath = get_file_path("openglad.cfg");
178 cfg.parse(filepath);
179 delete filepath;
180
181 // Zardus: load prefs
182 theprefs = new options;
183
184 // For informational purposes..
185 if (argc > 1 && !strcmp(argv[1], "/?") )
186 {
187 printf("\nScenario Editor version %s\n", GLAD_VER);
188
189 // Free memory ..
190 meminfo Memory;
191 //buffers: PORT: union REGS regs;
192 //buffers: PORT: struct SREGS sregs;
193 long bytes;
194
195 //buffers: PORT: regs.x.eax = 0x00000500;
196 //buffers: PORT: memset( &sregs, 0, sizeof(sregs) );
197 //buffers: PORT: sregs.es = FP_SEG( &Memory );
198 //buffers: regs.x.edi = FP_OFF( &Memory );
199
200 //buffers: int386x( DPMI_INT, ®s, ®s, &sregs );
201 bytes = Memory.FreeLinAddrSpace * 4096;
202 printf("\nMemory available: %ld bytes.\n", bytes);
203
204 exit (0);
205 }
206
207 myscreen = new screen(1);
208
209 scentext = new text(myscreen);
210 // Set the un-set text to empty ..
211 for (i=0; i < 60; i ++)
212 myscreen->scentext[i][0] = 0;
213
214 // Install our masking timer interrupt
215 grab_timer();
216
217 // Now install the keyboard interrupt
218 grab_keyboard();
219 // Clear the keyboard state
220 clear_keyboard();
221
222 // Now do the mouse ..
223 grab_mouse();
224
225 // Get our pixie data ..
226 load_map_data(mypixdata);
227 load_and_set_palette("our.pal", scenpalette);
228
229 // Set our default par value ..
230 myscreen->par_value = 1;
231 load_scenario("test", myscreen);
232
233 myscreen->clearfontbuffer();
234 myscreen->redraw();
235 myscreen->refresh();
236
237 //******************************
238 // Keyboard loop
239 //******************************
240
241 grab_mouse();
242 mykeyboard = query_keyboard();
243
244 //
245 // This is the main program loop
246 //
247 while(1)
248 {
249 // Reset the timer count to zero ...
250 reset_timer();
251
252 if (myscreen->end)
253 break;
254
255 //buffers: get keys and stuff
256 get_input_events(POLL);
257
258 // Zardus: COMMENT: I went through and replaced dumbcounts with get_input_events.
259
260 // Delete all with ^D
261 if (mykeyboard[SDLK_d] && mykeyboard[SDLK_LCTRL])
262 {
263 remove_all_objects(myscreen);
264 event = 1;
265 }
266
267 // Change teams ..
268 if (mykeyboard[SDLK_0])
269 {
270 currentteam = 0;
271 event = 1;
272 }
273 if (mykeyboard[SDLK_1])
274 {
275 currentteam = 1;
276 event = 1;
277 }
278 if (mykeyboard[SDLK_2])
279 {
280 currentteam = 2;
281 event = 1;
282 }
283 if (mykeyboard[SDLK_3])
284 {
285 currentteam = 3;
286 event = 1;
287 }
288 if (mykeyboard[SDLK_4])
289 {
290 currentteam = 4;
291 event = 1;
292 }
293 if (mykeyboard[SDLK_5])
294 {
295 currentteam = 5;
296 event = 1;
297 }
298 if (mykeyboard[SDLK_6])
299 {
300 currentteam = 6;
301 event = 1;
302 }
303 if (mykeyboard[SDLK_7])
304 {
305 currentteam = 7;
306 event = 1;
307 }
308
309 // Toggle grid alignment
310 if (mykeyboard[SDLK_g])
311 {
312 grid_aligned = (grid_aligned+1)%3;
313 event = 1;
314 while (mykeyboard[SDLK_g])
315 //buffers: dumbcount++;
316 get_input_events(WAIT);
317 }
318
319 // Show help
320 if (mykeyboard[SDLK_h])
321 {
322 release_mouse();
323 do_help(myscreen);
324 myscreen->clearfontbuffer();
325 grab_mouse();
326 event = 1;
327 }
328
329 if (mykeyboard[SDLK_KP_MULTIPLY]) // options menu
330 {
331 release_mouse();
332 scenario_options(myscreen);
333 grab_mouse();
334 event = 1; // redraw screen
335 }
336
337 // Load scenario, etc. ..
338 if (mykeyboard[SDLK_l])
339 {
340 if (levelchanged)
341 {
342 myscreen->draw_button(30, 15, 220, 25, 1, 1);
343 scentext->write_xy(32, 17, "Save level first? [Y/N]", DARK_BLUE, 1);
344 myscreen->buffer_to_screen(0, 0, 320, 200);
345 while ( !mykeyboard[SDLK_y] && !mykeyboard[SDLK_n])
346 get_input_events(WAIT);
347 if (mykeyboard[SDLK_y]) // save first
348 do_save(myscreen);
349 }
350 myscreen->draw_button(30, 15, 220, 25, 1, 1);
351 scentext->write_xy(32, 17, "Loading Level...", DARK_BLUE, 1);
352 do_load(myscreen);
353 myscreen->clearfontbuffer();
354 }
355
356 // Save scenario or grid..
357 if (mykeyboard[SDLK_s])
358 {
359 do_save(myscreen);
360 } // end of saving routines
361
362
363 // Switch modes ..
364 if (mykeyboard[SDLK_m]) // switch to map or guys ..
365 {
366 event = 1;
367 currentmode = (currentmode+1) %2;
368 while (mykeyboard[SDLK_m])
369 get_input_events(WAIT);
370 }
371
372 // New names
373 if (mykeyboard[SDLK_n])
374 {
375 event = 1;
376 //gotoxy(1, 23);
377 myscreen->draw_button(50, 30, 200, 40, 1, 1);
378 scentext->write_xy(52, 32, "New name [G/S] : ", DARK_BLUE, 1);
379 myscreen->buffer_to_screen(0, 0, 320, 200);
380 while ( !mykeyboard[SDLK_g] && !mykeyboard[SDLK_s] )
381 get_input_events(WAIT);
382 if (mykeyboard[SDLK_s])
383 {
384 myscreen->draw_button(50, 30, 200, 40, 1, 1);
385 myscreen->buffer_to_screen(0, 0, 320, 200);
386 new_scenario_name();
387 while (mykeyboard[SDLK_s])
388 get_input_events(WAIT);
389 } // end new scenario name
390 else if (mykeyboard[SDLK_g])
391 {
392 myscreen->draw_button(50, 30, 200, 40, 1, 1);
393 myscreen->buffer_to_screen(0, 0, 320, 200);
394 new_grid_name();
395 while (mykeyboard[SDLK_g])
396 get_input_events(WAIT);
397 } // end new grid name
398 myscreen->clearfontbuffer(50,30,150,10);
399 }
400
401 // Enter scenario text ..
402 if (mykeyboard[SDLK_t])
403 {
404 #define TEXT_DOWN(x) (14+((x)*7))
405 #define TL 4
406 //gotoxy(1, 1);
407 myscreen->draw_button(0, 10, 200, 200, 2, 1);
408 myscreen->buffer_to_screen(0, 0, 320, 200);
409 scentext->write_xy(TL, TEXT_DOWN(0), "Enter new scenario text;", DARK_BLUE, 1);
410 scentext->write_xy(TL, TEXT_DOWN(1), " PERIOD (.) alone to end.", DARK_BLUE, 1);
411 scentext->write_xy(TL, TEXT_DOWN(2), "*--------*---------*---------*", DARK_BLUE, 1);
412 myscreen->buffer_to_screen(0, 0, 320, 200);
413 myscreen->scentextlines = 0;
414 count = 2;
415 for (i=0; i < 23; i++)
416 if (strlen(myscreen->scentext[i]))
417 scentext->write_xy(TL, TEXT_DOWN(i+3), myscreen->scentext[i], DARK_BLUE, 1);
418 myscreen->buffer_to_screen(0, 0, 320, 200);
419 extra = 1;
420 for (i=0; i < 60; i++)
421 {
422 count++;
423 mystring[0] = 0;
424 if (! (count%26) )
425 {
426 myscreen->draw_box(TL, TEXT_DOWN(3), 196, 196, 27, 1, 1);
427 myscreen->buffer_to_screen(0, 0, 320, 200);
428 for (j=0; j < 23; j++)
429 {
430 count = j+(23*extra);
431 if (count < 60)
432 if (strlen(myscreen->scentext[count]))
433 scentext->write_xy(TL, TEXT_DOWN(j+3), myscreen->scentext[count], DARK_BLUE, 1);
434 }
435 count = 3;
436 extra++;
437 myscreen->buffer_to_screen(0, 0, 320, 200);
438 }
439 strcpy(mystring, scentext->input_string(TL, TEXT_DOWN(count), 30, myscreen->scentext[i]) );
440 strcpy(myscreen->scentext[i], mystring);
441 if (!strcmp(".", mystring)) // says end ..
442 {
443 i = 70;
444 myscreen->draw_box(0, 10, 200, 200, 0, 1, 1);
445 myscreen->buffer_to_screen(0, 0, 320, 200);
446 myscreen->scentext[i][0] = 0;
447 event = 1;
448 }
449 else
450 myscreen->scentextlines++;
451 }
452 myscreen->draw_box(0, 10, 200, 200, 0, 1, 1);
453 myscreen->buffer_to_screen(0, 0, 320, 200);
454 event = 1;
455 }
456
457 // Display the scenario help..
458 if (mykeyboard[SDLK_SLASH] && (mykeyboard[SDLK_RSHIFT] || mykeyboard[SDLK_LSHIFT]))
459 {
460 read_scenario(myscreen);
461 myscreen->clearfontbuffer();
462 event = 1;
463 }
464
465 // Change level of current guy being placed ..
466 if (mykeyboard[SDLK_RIGHTBRACKET])
467 {
468 currentlevel++;
469 //while (mykeyboard[SDLK_RIGHTBRACKET])
470 // dumbcount++;
471 event = 1;
472 }
473 if (mykeyboard[SDLK_LEFTBRACKET] && currentlevel > 1)
474 {
475 currentlevel--;
476 //while (mykeyboard[SDLK_LEFTBRACKET])
477 // dumbcount++;
478 event = 1;
479 }
480
481 // Change between generator and living orders
482 if (mykeyboard[SDLK_o]) // this is letter o
483 {
484 if (myorder == ORDER_LIVING)
485 {
486 myorder = ORDER_GENERATOR;
487 forecount = FAMILY_TENT;
488 }
489 else if (myorder == ORDER_GENERATOR)
490 myorder = ORDER_SPECIAL; // for placing team guys ..
491 else if (myorder == ORDER_SPECIAL)
492 {
493 myorder = ORDER_TREASURE;
494 forecount = FAMILY_DRUMSTICK;
495 }
496 else if (myorder == ORDER_TREASURE)
497 myorder = ORDER_WEAPON;
498 else if (myorder == ORDER_WEAPON)
499 myorder = ORDER_LIVING;
500 currentmode = OBJECT_MODE;
501 event = 1; // change score panel
502 while (mykeyboard[SDLK_o])
503 get_input_events(WAIT);
504 }
505
506 // Slide tile selector down ..
507 if (mykeyboard[SDLK_DOWN])
508 {
509 rowsdown++;
510 event = 1;
511 if (rowsdown >= maxrows)
512 rowsdown -= maxrows;
513 score_panel(myscreen);
514 while (mykeyboard[SDLK_DOWN])
515 get_input_events(WAIT);
516 }
517
518 // Slide tile selector up ..
519 if (mykeyboard[SDLK_UP])
520 {
521 rowsdown--;
522 event = 1;
523 if (rowsdown < 0)
524 rowsdown += maxrows;
525 if (rowsdown <0 || rowsdown >= maxrows) // bad case
526 rowsdown = 0;
527 score_panel(myscreen);
528 while (mykeyboard[SDLK_UP])
529 get_input_events(WAIT);
530 }
531
532 // Smooth current map, F5
533 if (mykeyboard[SDLK_F5])
534 {
535 if (mysmoother)
536 delete mysmoother;
537 mysmoother = new smoother();
538 mysmoother->set_target(myscreen);
539 mysmoother->smooth();
540 while (mykeyboard[SDLK_F5])
541 get_input_events(WAIT);
542 event = 1;
543 levelchanged = 1;
544 }
545
546 // Change to new palette ..
547 if (mykeyboard[SDLK_F9])
548 {
549 load_and_set_palette("our.pal", scenpalette);
550 while (mykeyboard[SDLK_F9])
551 get_input_events(WAIT);
552 }
553
554 // Toggle color cycling
555 if (mykeyboard[SDLK_F10])
556 {
557 cyclemode++;
558 cyclemode %= 2;
559 while (mykeyboard[SDLK_F10])
560 get_input_events(WAIT);
561 }
562 // Now perform color cycling if selected
563 if (cyclemode)
564 {
565 cycle_palette(scenpalette, WATER_START, WATER_END, 1);
566 cycle_palette(scenpalette, ORANGE_START, ORANGE_END, 1);
567 }
568
569 // Mouse stuff ..
570 mymouse = query_mouse();
571
572 // Scroll the screen ..
573 // Zardus: ADD: added scrolling by keyboard
574 // Zardus: PORT: disabled mouse scrolling
575 if ((mykeyboard[SDLK_KP8] || mykeyboard[SDLK_KP7] || mykeyboard[SDLK_KP9]) // || mymouse[MOUSE_Y]< 2)
576 && myscreen->topy >= 0) // top of the screen
577 set_screen_pos(myscreen, myscreen->topx,
578 myscreen->topy-SCROLLSIZE);
579 if ((mykeyboard[SDLK_KP2] || mykeyboard[SDLK_KP1] || mykeyboard[SDLK_KP3]) // || mymouse[MOUSE_Y]> 198)
580 && myscreen->topy <= (GRID_SIZE*myscreen->maxy)-18) // scroll down
581 set_screen_pos(myscreen, myscreen->topx,
582 myscreen->topy+SCROLLSIZE);
583 if ((mykeyboard[SDLK_KP4] || mykeyboard[SDLK_KP7] || mykeyboard[SDLK_KP1]) // || mymouse[MOUSE_X]< 2)
584 && myscreen->topx >= 0) // scroll left
585 set_screen_pos(myscreen, myscreen->topx-SCROLLSIZE,
586 myscreen->topy);
587 if ((mykeyboard[SDLK_KP6] || mykeyboard[SDLK_KP3] || mykeyboard[SDLK_KP9]) // || mymouse[MOUSE_X] > 318)
588 && myscreen->topx <= (GRID_SIZE*myscreen->maxx)-18) // scroll right
589 set_screen_pos(myscreen, myscreen->topx+SCROLLSIZE,
590 myscreen->topy);
591
592 if (mymouse[MOUSE_LEFT]) // put or remove the current guy
593 {
594 event = 1;
595 mx = mymouse[MOUSE_X];
596 my = mymouse[MOUSE_Y];
597
598 // Zardus: ADD: can move map by clicking on minimap
599 if (mx > myscreen->viewob[0]->endx - myscreen->viewob[0]->myradar->xview - 4
600 && my > myscreen->viewob[0]->endy - myscreen->viewob[0]->myradar->yview - 4
601 && mx < myscreen->viewob[0]->endx - 4 && my < myscreen->viewob[0]->endy - 4)
602 {
603 mx -= myscreen->viewob[0]->endx - myscreen->viewob[0]->myradar->xview - 4;
604 my -= myscreen->viewob[0]->endy - myscreen->viewob[0]->myradar->yview - 4;
605
606 // Zardus: above set_screen_pos doesn't take into account that minimap scrolls too. This one does.
607 set_screen_pos (myscreen, myscreen->viewob[0]->myradar->radarx * GRID_SIZE + mx * GRID_SIZE - 160,
608 myscreen->viewob[0]->myradar->radary * GRID_SIZE + my * GRID_SIZE - 100);
609 }
610 else if ( (mx >= S_LEFT) && (mx <= S_RIGHT) &&
611 (my >= S_UP) && (my <= S_DOWN) ) // in the main window
612 {
613 windowx = mymouse[MOUSE_X] + myscreen->topx - myscreen->viewob[0]->xloc; // - S_LEFT
614 if (grid_aligned==1)
615 windowx -= (windowx%GRID_SIZE);
616 windowy = mymouse[MOUSE_Y] + myscreen->topy - myscreen->viewob[0]->yloc; // - S_UP
617 if (grid_aligned==1)
618 windowy -= (windowy%GRID_SIZE);
619 if (mykeyboard[SDLK_i]) // get info on current object
620 {
621 newob = myscreen->add_ob(ORDER_LIVING, FAMILY_ELF);
622 newob->setxy(windowx, windowy);
623 if (some_hit(windowx, windowy, newob, myscreen))
624 info_box(newob->collide_ob,myscreen);
625 myscreen->remove_ob(newob,0);
626 continue;
627 } // end of info mode
628 if (mykeyboard[SDLK_f]) // set facing of current object
629 {
630 newob = myscreen->add_ob(ORDER_LIVING, FAMILY_ELF);
631 newob->setxy(windowx, windowy);
632 if (some_hit(windowx, windowy, newob, myscreen))
633 set_facing(newob->collide_ob,myscreen);
634 myscreen->remove_ob(newob,0);
635 continue;
636 } // end of set facing
637
638 if (mykeyboard[SDLK_r]) // (re)name the current object
639 {
640 newob = myscreen->add_ob(ORDER_LIVING, FAMILY_ELF);
641 newob->setxy(windowx, windowy);
642 if (some_hit(windowx, windowy, newob, myscreen))
643 {
644 set_name(newob->collide_ob,myscreen);
645 levelchanged = 1;
646 }
647 myscreen->remove_ob(newob,0);
648 } // end of info mode
649 else if (currentmode == OBJECT_MODE)
650 {
651 newob = myscreen->add_ob(myorder, forecount);
652 newob->setxy(windowx, windowy);
653 newob->team_num = currentteam;
654 newob->stats->level = currentlevel;
655 newob->dead = 0; // just in case
656 newob->collide_ob = 0;
657 if ( (grid_aligned==1) && some_hit(windowx, windowy, newob, myscreen))
658 {
659 if (mykeyboard[SDLK_LCTRL] && // are we holding the erase?
660 newob->collide_ob ) // and hit a guy?
661 {
662 myscreen->remove_ob(newob->collide_ob,0);
663 while (mymouse[MOUSE_LEFT])
664 {
665 mymouse = query_mouse();
666 }
667 levelchanged = 1;
668 } // end of deleting guy
669 if (newob)
670 {
671 myscreen->remove_ob(newob,0);
672 newob = NULL;
673 }
674 } // end of failure to put guy
675 else if (grid_aligned == 2)
676 {
677 newob->draw(myscreen->viewob[0]);
678 myscreen->buffer_to_screen(0, 0, 320, 200);
679 start_time_s = query_timer();
680 while ( mymouse[MOUSE_LEFT] && (query_timer()-start_time_s) < 36 )
681 {
682 mymouse = query_mouse();
683 }
684 levelchanged = 1;
685 }
686 if (mykeyboard[SDLK_LCTRL] && newob)
687 {
688 myscreen->remove_ob(newob,0);
689 newob = NULL;
690 }
691 // while (mymouse[MOUSE_LEFT])
692 // mymouse = query_mouse();
693 } // end of putting a guy
694 if (currentmode == MAP_MODE)
695 {
696 windowx /= GRID_SIZE; // get the map position ..
697 windowy /= GRID_SIZE;
698 // Set to our current selection
699 myscreen->grid[windowy*(myscreen->maxx)+windowx] = some_pix(backcount);
700 levelchanged = 1;
701 if (!mykeyboard[SDLK_LCTRL]) // smooth a few squares, if not control
702 {
703 if (mysmoother)
704 {
705 delete mysmoother;
706 mysmoother = new smoother();
707 mysmoother->set_target(myscreen);
708 }
709 for (i=windowx-1; i <= windowx+1; i++)
710 for (j=windowy-1; j <=windowy+1; j++)
711 if (i >= 0 && i < myscreen->maxx &&
712 j >= 0 && j < myscreen->maxy)
713 mysmoother->smooth(i, j);
714 }
715 else if (mysmoother) // update smoother anyway
716 {
717 delete mysmoother;
718 mysmoother = new smoother();
719 mysmoother->set_target(myscreen);
720 }
721 myscreen->viewob[0]->myradar->update();
722 } // end of setting grid square
723 } // end of main window
724 // if ( (mx >= PIX_LEFT) && (mx <= PIX_RIGHT) &&
725 // (my >= PIX_TOP) && (my <= PIX_BOTTOM) ) // grid menu
726 if (mx >= S_RIGHT && my >= PIX_TOP && my <= PIX_BOTTOM)
727 {
728 //windowx = (mx - PIX_LEFT) / GRID_SIZE;
729 windowx = (mx-S_RIGHT) / GRID_SIZE;
730 windowy = (my - PIX_TOP) / GRID_SIZE;
731 backcount = backgrounds[ (windowx + ((windowy+rowsdown) * PIX_OVER))
732 % (sizeof(backgrounds)/4)];
733 backcount %= NUM_BACKGROUNDS;
734 currentmode = MAP_MODE;
735 } // end of background grid window
736
737 } // end of left mouse button
738
739 if (mymouse[MOUSE_RIGHT]) // cycle through things ...
740 {
741 event = 1;
742 if (currentmode == OBJECT_MODE)
743 {
744 if (myorder == ORDER_LIVING)
745 forecount = (forecount+1) % NUM_FAMILIES;
746 else if (myorder == ORDER_TREASURE)
747 forecount = (forecount+1) % (MAX_TREASURE+1);
748 else if (myorder == ORDER_GENERATOR)
749 forecount = (forecount+1) % 4;
750 else if (myorder == ORDER_WEAPON)
751 forecount = (forecount+1) % (FAMILY_DOOR+1); // use largest weapon
752 else
753 forecount = 0;
754 } // end of if object mode
755 if (currentmode == MAP_MODE)
756 {
757 windowx = mymouse[MOUSE_X] + myscreen->topx - myscreen->viewob[0]->xloc; // - S_LEFT
758 windowx -= (windowx%GRID_SIZE);
759 windowy = mymouse[MOUSE_Y] + myscreen->topy - myscreen->viewob[0]->yloc; // - S_UP
760 windowy -= (windowy%GRID_SIZE);
761 windowx /= GRID_SIZE;
762 windowy /= GRID_SIZE;
763 backcount = myscreen->grid[windowy*(myscreen->maxx)+windowx];
764 }
765 while (mymouse[MOUSE_RIGHT])
766 {
767 mymouse = query_mouse();
768 }
769 }
770
771 if (event)
772 {
773 release_mouse();
774 myscreen->redraw();
775 score_panel(myscreen);
776 myscreen->refresh();
777 // score_panel(myscreen);
778 grab_mouse();
779 }
780 event = 0;
781
782 if (mykeyboard[SDLK_ESCAPE])
783 quit(1);
784
785 }
786
787 return 0;
788 }
789
quit(long num)790 long quit(long num)
791 {
792 int i;
793
794 for (i = 0; i < PIX_MAX+1; i++)
795 if (mypixdata[i]) delete mypixdata[i];
796
797 // Release the mouse ..
798 release_mouse();
799
800 // Release the keyboard interrupt
801 release_keyboard();
802
803 // And release the timer ..
804 release_timer();
805
806 // And stop input
807 stop_input();
808
809 // Get rid of the prefs
810 delete theprefs;
811
812 // And delete myscreen
813 delete myscreen;
814
815 // Delete scentext
816 delete scentext;
817
818 SDL_Quit();
819
820 exit(num);
821 return num;
822 }
823
score_panel(screen * myscreen)824 long score_panel(screen *myscreen)
825 {
826 char message[50];
827 long i, j; // for loops
828 // static long family=-1, hitpoints=-1, score=-1, act=-1;
829 static long numobs = myscreen->numobs;
830 static long lm = 245;
831 long curline = 0;
832 long whichback;
833 static char treasures[20][NUM_FAMILIES] =
834 { "BLOOD", "DRUMSTICK", "GOLD", "SILVER",
835 "MAGIC", "INVIS", "INVULN", "FLIGHT",
836 "EXIT", "TELEPORTER", "LIFE GEM", "KEY", "SPEED", "CC",
837 };
838 static char weapons[20][NUM_FAMILIES] =
839 { "KNIFE", "ROCK", "ARROW", "FIREBALL",
840 "TREE", "METEOR", "SPRINKLE", "BONE",
841 "BLOOD", "BLOB", "FIRE ARROW", "LIGHTNING",
842 "GLOW", "WAVE 1", "WAVE 2", "WAVE 3",
843 "PROTECTION", "HAMMER", "DOOR",
844 };
845
846 static char livings[NUM_FAMILIES][20] =
847 { "SOLDIER", "ELF", "ARCHER", "MAGE",
848 "SKELETON", "CLERIC", "ELEMENTAL",
849 "FAERIE", "L SLIME", "S SLIME", "M SLIME",
850 "THIEF", "GHOST", "DRUID", "ORC",
851 "ORC CAPTAIN", "BARBARIAN", "ARCHMAGE",
852 "GOLEM", "G SKELETON", "TOWER1",
853 };
854
855 // Hide the mouse ..
856 release_mouse();
857
858 // Draw the bounding box
859 //myscreen->draw_dialog(lm-4, L_D(-1), 310, L_D(8), "Info");
860 myscreen->draw_button(lm-4, L_D(-1)+4, 315, L_D(7)-2, 1, 1);
861
862 // Show scenario and grid info
863 strcpy(message, scen_name);
864 uppercase(message);
865
866 //myscreen->fastbox(lm, S_UP, 70, 8*5, 27, 1);
867 scentext->write_xy(lm,L_D(curline++),message, DARK_BLUE, 1);
868
869 strcpy(message, grid_name);
870 uppercase(message);
871 scentext->write_xy(lm,L_D(curline++),message, DARK_BLUE, 1);
872
873 if (currentmode==MAP_MODE)
874 scentext->write_xy(lm,L_D(curline++), "MODE: MAP", DARK_BLUE, 1);
875 else if (currentmode==OBJECT_MODE)
876 scentext->write_xy(lm,L_D(curline++), "MODE: OBS", DARK_BLUE, 1);
877
878 // Get team number ..
879 sprintf(message, "%d:", currentteam);
880 if (myorder == ORDER_LIVING)
881 strcat(message, livings[forecount]);
882 else if (myorder == ORDER_GENERATOR)
883 switch (forecount) // who are we?
884 {
885 case FAMILY_TENT:
886 strcat(message, "TENT");
887 break;
888 case FAMILY_TOWER:
889 strcat(message, "TOWER");
890 break;
891 case FAMILY_BONES:
892 strcat(message, "BONEPILE");
893 break;
894 case FAMILY_TREEHOUSE:
895 strcat(message, "TREEHOUSE");
896 break;
897 default:
898 strcat(message, "GENERATOR");
899 break;
900 }
901 else if (myorder == ORDER_SPECIAL)
902 strcat(message, "PLAYER");
903 else if (myorder == ORDER_TREASURE)
904 strcat(message, treasures[forecount]);
905 else if (myorder == ORDER_WEAPON)
906 strcat(message, weapons[forecount]);
907 else
908 strcat(message, "UNKNOWN");
909 scentext->write_xy(lm, L_D(curline++), message, DARK_BLUE, 1);
910
911 // Level display
912 sprintf(message, "LVL: %ld", currentlevel);
913 //myscreen->fastbox(lm,L_D(curline),55,7,27, 1);
914 scentext->write_xy(lm, L_D(curline++), message, DARK_BLUE, 1);
915
916 // Is grid alignment on?
917 //myscreen->fastbox(lm, L_D(curline),65, 7, 27, 1);
918 if (grid_aligned==1)
919 scentext->write_xy(lm, L_D(curline++), "ALIGN: ON", DARK_BLUE, 1);
920 else if (grid_aligned==2)
921 scentext->write_xy(lm, L_D(curline++), "ALIGN: STACK", DARK_BLUE, 1);
922 else
923 scentext->write_xy(lm, L_D(curline++), "ALIGN: OFF", DARK_BLUE, 1);
924
925 numobs = myscreen->numobs;
926 //myscreen->fastbox(lm,L_D(curline),55,7,27, 1);
927 sprintf(message, "OB: %ld", numobs);
928 scentext->write_xy(lm,L_D(curline++),message, DARK_BLUE, 1);
929
930 // Show the background grid ..
931 myscreen->putbuffer(lm+40, PIX_TOP-16, GRID_SIZE, GRID_SIZE,
932 0, 0, 320, 200, mypixdata[backcount]+3);
933
934 // rowsdown = (NUM_BACKGROUNDS / 4) + 1;
935 // rowsdown = 0; // hack for now
936 for (i=0; i < PIX_OVER; i++)
937 {
938 for (j=0; j < 4; j++)
939 {
940 //myscreen->back[i]->draw( S_RIGHT+(i*8), S_UP+100);
941 //myscreen->back[0]->draw(64, 64);
942 whichback = (i+(j+rowsdown)*4) % (sizeof(backgrounds)/4);
943 myscreen->putbuffer(S_RIGHT+i*GRID_SIZE, PIX_TOP+j*GRID_SIZE,
944 GRID_SIZE, GRID_SIZE,
945 0, 0, 320, 200,
946 mypixdata[ backgrounds[whichback] ]+3);
947 }
948 }
949 myscreen->draw_box(S_RIGHT, PIX_TOP,
950 S_RIGHT+4*GRID_SIZE, PIX_TOP+4*GRID_SIZE, 0, 0, 1);
951 myscreen->buffer_to_screen(0, 0, 320, 200);
952 // Restore the mouse
953 grab_mouse();
954
955 return 1;
956 }
957
958
set_screen_pos(screen * myscreen,long x,long y)959 void set_screen_pos(screen *myscreen, long x, long y)
960 {
961 myscreen->topx = x;
962 myscreen->topy = y;
963 event = 1;
964 }
965
remove_all_objects(screen * master)966 void remove_all_objects(screen *master)
967 {
968 oblink *fx = master->fxlist;
969
970 while (fx)
971 {
972 if (fx->ob)
973 {
974 delete fx->ob;
975 fx->ob = NULL;
976 }
977 else
978 fx = fx->next;
979 }
980 if (fx && fx->ob)
981 delete fx->ob;
982
983 fx = master->oblist;
984 while (fx)
985 {
986 if (fx->ob)
987 {
988 delete fx->ob;
989 fx->ob = NULL;
990 }
991 else
992 fx = fx->next;
993 }
994 if (fx && fx->ob)
995 delete fx->ob;
996
997 fx = master->weaplist;
998 while (fx)
999 {
1000 if (fx->ob)
1001 {
1002 delete fx->ob;
1003 fx->ob = NULL;
1004 }
1005 else
1006 fx = fx->next;
1007 }
1008 if (fx && fx->ob)
1009 delete fx->ob;
1010
1011 master->numobs = 0;
1012 } // end remove_all_objects
1013
remove_first_ob(screen * master)1014 void remove_first_ob(screen *master)
1015 {
1016 oblink *here;
1017
1018 here = master->oblist;
1019
1020 while (here)
1021 {
1022 if (here->ob)
1023 {
1024 delete here->ob;
1025 return;
1026 }
1027 else
1028 here = here->next;
1029 }
1030 }
1031
save_map_file(char * filename,screen * master)1032 long save_map_file(char * filename, screen *master)
1033 {
1034 // File data in form:
1035 // <# of frames> 1 byte
1036 // <x size> 1 byte
1037 // <y size> 1 byte
1038 // <pixie data> <x*y*frames> bytes
1039
1040 char numframes, x, y;
1041 // char *newpic;
1042 string fullpath(filename);
1043 FILE *outfile;
1044
1045 // Create the full pathname for the pixie file
1046 fullpath += ".pix";
1047
1048 lowercase (fullpath);
1049
1050 if ( (outfile = open_misc_file((char *)fullpath.c_str(), "pix/", "wb")) == NULL )
1051 {
1052 master->draw_button(30, 30, 220, 60, 1, 1);
1053 scentext->write_xy(32, 32, "Error in saving map file", DARK_BLUE, 1);
1054 scentext->write_xy(32, 42, fullpath.c_str(), DARK_BLUE, 1);
1055 scentext->write_xy(32, 52, "Press SPACE to continue", DARK_BLUE, 1);
1056 master->buffer_to_screen(0, 0, 320, 200);
1057 while (!mykeyboard[SDLK_SPACE])
1058 get_input_events(WAIT);
1059 return 0;
1060 }
1061
1062 x = master->maxx;
1063 y = master->maxy;
1064 numframes = 1;
1065 fwrite(&numframes, 1, 1, outfile);
1066 fwrite(&x, 1, 1, outfile);
1067 fwrite(&y, 1, 1, outfile);
1068
1069 fwrite(master->grid, 1, (x*y), outfile);
1070
1071 fclose(outfile); // Close the data file
1072 return 1;
1073
1074 } // End of map-saving routine
1075
load_new_grid(screen * master)1076 long load_new_grid(screen *master)
1077 {
1078 string tempstring;
1079 //char tempstring[80];
1080
1081 scentext->write_xy(52, 32, "Grid name: ", DARK_BLUE, 1);
1082 tempstring = scentext->input_string(115, 32, 8, grid_name);
1083 //NORMAL_KEYBOARD(SDLKf("%s", tempstring);)
1084 if (tempstring.empty())
1085 {
1086 //buffers: our grid files are all lowercase...
1087 lowercase(tempstring);
1088
1089 tempstring += grid_name;
1090 }
1091
1092 //printf("DB: loading %s\n", grid_name);
1093
1094 //buffers: PORT: changed .PIX to .pix
1095 tempstring += ".pix";
1096 master->grid = read_pixie_file(tempstring.c_str());
1097 master->maxx = master->grid[1];
1098 master->maxy = master->grid[2];
1099 master->grid = master->grid + 3;
1100 //printf("DB: loaded data to grid\n");
1101 //master->viewob[0]->myradar = new radar(master->viewob[0],
1102 // master, 0);
1103
1104 master->viewob[0]->myradar->start();
1105 master->viewob[0]->myradar->update();
1106
1107 //printf("DB: made new radar\n");
1108 return 1;
1109 }
1110
new_scenario_name()1111 long new_scenario_name()
1112 {
1113 char tempstring[80];
1114
1115 scentext->write_xy(52, 32, "Scenario name: ", DARK_BLUE, 1);
1116 strcpy(tempstring, scentext->input_string(135, 32, 8, scen_name));
1117 //NORMAL_KEYBOARD(SDLKf("%s", tempstring);)
1118 if (strlen(tempstring))
1119 {
1120 strcpy(scen_name, tempstring);
1121 //buffers: all our files are lowercase....
1122 lowercase(scen_name);
1123 }
1124
1125 return 1;
1126 }
1127
new_grid_name()1128 long new_grid_name()
1129 {
1130 char tempstring[80];
1131
1132 scentext->write_xy(52, 32, "Grid name: ", DARK_BLUE, 1);
1133 strcpy(tempstring, scentext->input_string(117, 32, 8, grid_name));
1134 //NORMAL_KEYBOARD(SDLKf("%s", tempstring);)
1135 if (strlen(tempstring))
1136 strcpy(grid_name, tempstring);
1137
1138 return 1;
1139 }
1140
do_help(screen * myscreen)1141 void do_help(screen * myscreen)
1142 {
1143 text *helptext = new text(myscreen);
1144 long lm = S_LEFT+4+43, tm=S_UP+15; // left and top margins
1145 long lines = 0;
1146
1147 // Zardus: new margins
1148 //myscreen->draw_button(S_LEFT+32,S_UP,S_RIGHT-1+16,S_DOWN-1,2, 1);
1149 myscreen->draw_button(S_LEFT+43,S_UP + 11,S_RIGHT-1+16,S_DOWN-1,2, 1);
1150
1151 helptext->write_xy(lm + L_W(10), tm, "**HELP**", DARK_BLUE, 1);
1152
1153 helptext->write_xy(lm, tm+L_H(++lines), "G : TOGGLE GRID ALIGNMENT", DARK_BLUE, 1);
1154 helptext->write_xy(lm, tm+L_H(++lines), "H : HELP", DARK_BLUE, 1);
1155 helptext->write_xy(lm, tm+L_H(++lines), "I : INFO ON CLICKED OBJECT", DARK_BLUE, 1);
1156 helptext->write_xy(lm, tm+L_H(++lines), "L : LOAD NEW SCEN OR GRID", DARK_BLUE, 1);
1157 helptext->write_xy(lm, tm+L_H(++lines), "M : TOGGLE OBJECT OR MAP MODE", DARK_BLUE, 1);
1158 helptext->write_xy(lm, tm+L_H(++lines), "N : NEW SCEN OR GRID NAME", DARK_BLUE,1);
1159 helptext->write_xy(lm, tm+L_H(++lines), "O : TOGGLE LIVING/TENT/ETC", DARK_BLUE,1);
1160 helptext->write_xy(lm, tm+L_H(++lines), "R : RENAME OBJECT", DARK_BLUE,1);
1161 helptext->write_xy(lm, tm+L_H(++lines), "S : SAVE SCEN OR GRID", DARK_BLUE,1);
1162 helptext->write_xy(lm, tm+L_H(++lines), "T : ENTER SCEN TEXT", DARK_BLUE,1);
1163 helptext->write_xy(lm, tm+L_H(++lines), "* : TOGGLE SCENARIO OPTIONS", DARK_BLUE, 1);
1164
1165 //lines +=1;
1166 helptext->write_xy(lm, tm+L_H(++lines), "ESC : QUIT", DARK_BLUE,1);
1167 helptext->write_xy(lm, tm+L_H(++lines), "LEFT CLICK : PUT OB OR BACKGD", DARK_BLUE,1);
1168 helptext->write_xy(lm, tm+L_H(++lines), "CTRL + LEFT : Remove Object", DARK_BLUE,1);
1169 helptext->write_xy(lm, tm+L_H(++lines), "CTRL + D : Remove all Obs", DARK_BLUE,1);
1170
1171 helptext->write_xy(lm, tm+L_H(++lines), "RIGHT CLICK : CYCLE THRU OBS", DARK_BLUE,1);
1172 helptext->write_xy(lm, tm+L_H(++lines), "KEYS 0-7 : CYCLE TEAM NUMBER", DARK_BLUE,1);
1173 helptext->write_xy(lm, tm+L_H(++lines), "F5 : SMOOTH MAP TILES", DARK_BLUE,1);
1174 helptext->write_xy(lm, tm+L_H(++lines), "[,] : LOWER/RAISE OB LEVEL", DARK_BLUE,1);
1175 helptext->write_xy(lm, tm+L_H(++lines), "? : DISPLAY SCEN TEXT", DARK_BLUE,1);
1176
1177 myscreen->buffer_to_screen(0, 0, 320, 200);
1178
1179 wait_for_key(SDLK_SPACE);
1180
1181 delete helptext;
1182 }
1183
some_pix(long whatback)1184 char some_pix(long whatback)
1185 {
1186 long i;
1187
1188 i = random(4); // max # of types of any particular ..
1189
1190 switch (whatback)
1191 {
1192 case PIX_GRASS1:
1193 switch (i)
1194 {
1195 case 0:
1196 return PIX_GRASS1;
1197 case 1:
1198 return PIX_GRASS2;
1199 case 2:
1200 return PIX_GRASS3;
1201 case 3:
1202 return PIX_GRASS4;
1203 default:
1204 return PIX_GRASS1;
1205 }
1206 //break;
1207 case PIX_GRASS_DARK_1:
1208 switch (i)
1209 {
1210 case 0:
1211 return PIX_GRASS_DARK_1;
1212 case 1:
1213 return PIX_GRASS_DARK_2;
1214 case 2:
1215 return PIX_GRASS_DARK_3;
1216 case 3:
1217 return PIX_GRASS_DARK_4;
1218 default:
1219 return PIX_GRASS_DARK_1;
1220 }
1221 //break;
1222 case PIX_GRASS_DARK_B1:
1223 case PIX_GRASS_DARK_B2:
1224 switch (i)
1225 {
1226 case 0:
1227 case 1:
1228 return PIX_GRASS_DARK_B1;
1229 case 2:
1230 case 3:
1231 default:
1232 return PIX_GRASS_DARK_B2;
1233 }
1234 //break;
1235 case PIX_GRASS_DARK_R1:
1236 case PIX_GRASS_DARK_R2:
1237 switch (i)
1238 {
1239 case 0:
1240 case 1:
1241 return PIX_GRASS_DARK_R1;
1242 case 2:
1243 case 3:
1244 default:
1245 return PIX_GRASS_DARK_R2;
1246 }
1247 //break;
1248 case PIX_WATER1:
1249 switch (i)
1250 {
1251 case 0:
1252 return PIX_WATER1;
1253 case 1:
1254 return PIX_WATER2;
1255 case 2:
1256 return PIX_WATER3;
1257 default:
1258 return PIX_WATER1;
1259 }
1260 //break;
1261 case PIX_PAVEMENT1:
1262 switch (random(12))
1263 {
1264 case 0:
1265 return PIX_PAVEMENT1;
1266 case 1:
1267 return PIX_PAVEMENT2;
1268 case 2:
1269 return PIX_PAVEMENT3;
1270 default:
1271 return PIX_PAVEMENT1;
1272 }
1273 //break;
1274 case PIX_COBBLE_1:
1275 switch (random(i))
1276 {
1277 case 0:
1278 return PIX_COBBLE_1;
1279 case 1:
1280 return PIX_COBBLE_2;
1281 case 2:
1282 return PIX_COBBLE_3;
1283 case 3:
1284 return PIX_COBBLE_4;
1285 default:
1286 return PIX_COBBLE_1;
1287 }
1288 //break;
1289 case PIX_BOULDER_1:
1290 switch (random(i))
1291 {
1292 case 0:
1293 return PIX_BOULDER_1;
1294 case 1:
1295 return PIX_BOULDER_2;
1296 case 2:
1297 return PIX_BOULDER_3;
1298 case 3:
1299 return PIX_BOULDER_4;
1300 default:
1301 return PIX_BOULDER_1;
1302 }
1303 //break;
1304 case PIX_JAGGED_GROUND_1:
1305 switch (i)
1306 {
1307 case 0:
1308 return PIX_JAGGED_GROUND_1;
1309 case 1:
1310 return PIX_JAGGED_GROUND_2;
1311 case 2:
1312 return PIX_JAGGED_GROUND_3;
1313 case 3:
1314 return PIX_JAGGED_GROUND_4;
1315 default:
1316 return PIX_JAGGED_GROUND_1;
1317 }
1318 default:
1319 return whatback;
1320 }
1321 }
1322
save_scenario(char * filename,screen * master,char * gridname)1323 long save_scenario(char * filename, screen * master, char *gridname)
1324 {
1325 long currentx, currenty;
1326 char temporder, tempfamily;
1327 char tempteam, tempfacing, tempcommand;
1328 short shortlevel;
1329 char filler[20] = "MSTRMSTRMSTRMSTR"; // for RESERVED
1330 FILE *outfile;
1331 char temptext[10] = "FSS";
1332 char temp_grid[20] = "grid"; // default grid
1333 char temp_scen_type = master->scenario_type;
1334 oblink * head = master->oblist;
1335 long listsize;
1336 long i;
1337 char temp_version = VERSION_NUM;
1338 char temp_filename[80];
1339 char numlines, tempwidth;
1340 char oneline[80];
1341 char tempname[12];
1342 char buffer[200];
1343 char scentitle[30];
1344 short temp_par;
1345
1346 // Format of a scenario object list file is: (ver. 8)
1347 // 3-byte header: 'FSS'
1348 // 1-byte version number (from graph.h)
1349 // 8-byte grid file name
1350 // 30-byte scenario title
1351 // 1-byte scenario_type
1352 // 2-bytes par-value for level
1353 // 2-bytes (long) = total objects to follow
1354 // List of n objects, each of 20-bytes of form:
1355 // 1-byte ORDER
1356 // 1-byte FAMILY
1357 // 2-byte long xpos
1358 // 2-byte long ypos
1359 // 1-byte TEAM
1360 // 1-byte current facing
1361 // 1-byte current command
1362 // 1-byte level // this is 2 bytes in version 7+
1363 // 12-bytes name
1364 // ---
1365 // 10 bytes RESERVED
1366 // 1-byte # of lines of text to load
1367 // List of n lines of text, each of form:
1368 // 1-byte character width of line
1369 // m bytes == characters on this line
1370
1371 // Zardus: PORT: no longer need to put in scen/ in this part
1372 //strcpy(temp_filename, scen_directory);
1373 strcpy(temp_filename, filename);
1374 //buffers: PORT: changed .FSS to .fss
1375 strcat(temp_filename, ".fss");
1376
1377 if ( (outfile = open_misc_file(temp_filename, "scen/", "wb")) == NULL ) // open for write
1378 {
1379 //gotoxy(1, 22);
1380 printf("Error in writing file %s\n", filename);
1381
1382 master->draw_button(30, 30, 220, 60, 1, 1);
1383 sprintf(buffer, "Error in saving scenario file");
1384 scentext->write_xy(32, 32, buffer, DARK_BLUE, 1);
1385 sprintf(buffer, "%s", temp_filename);
1386 scentext->write_xy(32, 42, buffer, DARK_BLUE, 1);
1387 sprintf(buffer, "Press SPACE to continue");
1388 scentext->write_xy(32, 52, buffer, DARK_BLUE, 1);
1389 master->buffer_to_screen(0, 0, 320, 200);
1390 while (!mykeyboard[SDLK_SPACE])
1391 get_input_events(WAIT);
1392
1393 return 0;
1394 }
1395
1396 // Write id header
1397 fwrite(temptext, 3, 1, outfile);
1398
1399 // Write version number
1400 fwrite(&temp_version, 1, 1, outfile);
1401
1402 // Write name of current grid...
1403 strcpy(temp_grid, gridname); // Do NOT include extension
1404
1405 // Set any chars under 8 not used to 0 ..
1406 for (i=strlen(temp_grid); i < 8; i++)
1407 temp_grid[i] = 0;
1408 fwrite(temp_grid, 8, 1, outfile);
1409
1410 // Write the scenario title, if it exists
1411 for (i=0; i < strlen(scentitle); i++)
1412 scentitle[i] = 0;
1413 strcpy(scentitle, master->scenario_title);
1414 fwrite(scentitle, 30, 1, outfile);
1415
1416 // Write the scenario type info
1417 fwrite(&temp_scen_type, 1, 1, outfile);
1418
1419 // Write our par value (version 8+)
1420 temp_par = master->par_value;
1421 fwrite(&temp_par, 2, 1, outfile);
1422
1423 // Determine size of object list ...
1424 listsize = 0;
1425 while (head)
1426 {
1427 if (head->ob)
1428 listsize++;
1429 head = head->next;
1430 } // end of oblist-size check
1431
1432 // Also check the fx list ..
1433 head = master->fxlist;
1434 while (head)
1435 {
1436 if (head->ob)
1437 listsize++;
1438 head = head->next;
1439 } // end of fxlist-size check
1440
1441 // And the weapon list ..
1442 head = master->weaplist;
1443 while (head)
1444 {
1445 if (head->ob)
1446 listsize++;
1447 head = head->next;
1448 } // end of weaplist-size check
1449
1450 fwrite(&listsize, 2, 1, outfile);
1451
1452 // Okay, we've written header .. now dump the data ..
1453 head = master->oblist; // back to head of list
1454 while (head)
1455 {
1456 if (head->ob)
1457 {
1458 if (!head)
1459 return 0; // Something wrong! Too few objects..
1460 temporder = head->ob->query_order();
1461 tempfacing= head->ob->curdir;
1462 tempfamily= head->ob->query_family();
1463 tempteam = head->ob->team_num;
1464 tempcommand=head->ob->query_act_type();
1465 currentx = head->ob->xpos;
1466 currenty = head->ob->ypos;
1467 //templevel = head->ob->stats->level;
1468 shortlevel = head->ob->stats->level;
1469 strcpy(tempname, head->ob->stats->name);
1470 fwrite(&temporder, 1, 1, outfile);
1471 fwrite(&tempfamily, 1, 1, outfile);
1472 fwrite(¤tx, 2, 1, outfile);
1473 fwrite(¤ty, 2, 1, outfile);
1474 fwrite(&tempteam, 1, 1, outfile);
1475 fwrite(&tempfacing, 1, 1, outfile);
1476 fwrite(&tempcommand, 1, 1, outfile);
1477 fwrite(&shortlevel, 2, 1, outfile);
1478 fwrite(tempname, 12, 1, outfile);
1479 fwrite(filler, 10, 1, outfile);
1480 }
1481 // Advance to next object ..
1482 head = head->next;
1483 }
1484
1485 // Now dump the fxlist data ..
1486 head = master->fxlist; // back to head of list
1487 while (head)
1488 {
1489 if (head->ob)
1490 {
1491 if (!head)
1492 return 0; // Something wrong! Too few objects..
1493 temporder = head->ob->query_order();
1494 tempfacing= head->ob->curdir;
1495 tempfamily= head->ob->query_family();
1496 tempteam = head->ob->team_num;
1497 tempcommand=head->ob->query_act_type();
1498 currentx = head->ob->xpos;
1499 currenty = head->ob->ypos;
1500 //templevel = head->ob->stats->level;
1501 shortlevel = head->ob->stats->level;
1502 strcpy(tempname, head->ob->stats->name);
1503 fwrite(&temporder, 1, 1, outfile);
1504 fwrite(&tempfamily, 1, 1, outfile);
1505 fwrite(¤tx, 2, 1, outfile);
1506 fwrite(¤ty, 2, 1, outfile);
1507 fwrite(&tempteam, 1, 1, outfile);
1508 fwrite(&tempfacing, 1, 1, outfile);
1509 fwrite(&tempcommand, 1, 1, outfile);
1510 fwrite(&shortlevel, 2, 1, outfile);
1511 fwrite(tempname, 12, 1, outfile);
1512 fwrite(filler, 10, 1, outfile);
1513 }
1514 // Advance to next object ..
1515 head = head->next;
1516 }
1517
1518 // Now dump the weaplist data ..
1519 head = master->weaplist; // back to head of list
1520 while (head)
1521 {
1522 if (head->ob)
1523 {
1524 if (!head)
1525 return 0; // Something wrong! Too few objects..
1526 temporder = head->ob->query_order();
1527 tempfacing= head->ob->curdir;
1528 tempfamily= head->ob->query_family();
1529 tempteam = head->ob->team_num;
1530 tempcommand=head->ob->query_act_type();
1531 currentx = head->ob->xpos;
1532 currenty = head->ob->ypos;
1533 shortlevel = head->ob->stats->level;
1534 strcpy(tempname, head->ob->stats->name);
1535 fwrite(&temporder, 1, 1, outfile);
1536 fwrite(&tempfamily, 1, 1, outfile);
1537 fwrite(¤tx, 2, 1, outfile);
1538 fwrite(¤ty, 2, 1, outfile);
1539 fwrite(&tempteam, 1, 1, outfile);
1540 fwrite(&tempfacing, 1, 1, outfile);
1541 fwrite(&tempcommand, 1, 1, outfile);
1542 fwrite(&shortlevel, 2, 1, outfile);
1543 fwrite(tempname, 12, 1, outfile);
1544 fwrite(filler, 10, 1, outfile);
1545 }
1546 // Advance to next object ..
1547 head = head->next;
1548 }
1549
1550 numlines = master->scentextlines;
1551 //printf("saving %d lines\n", numlines);
1552
1553 fwrite(&numlines, 1, 1, outfile);
1554 for (i=0; i < numlines; i++)
1555 {
1556 strcpy(oneline, master->scentext[i]);
1557 tempwidth = strlen(oneline);
1558 fwrite(&tempwidth, 1, 1, outfile);
1559 fwrite(oneline, tempwidth, 1, outfile);
1560 }
1561
1562 fclose(outfile);
1563
1564 return 1;
1565 }
1566
1567 // Copy of collide from obmap; used manually .. :(
check_collide(long x,long y,long xsize,long ysize,long x2,long y2,long xsize2,long ysize2)1568 long check_collide(long x, long y, long xsize, long ysize,
1569 long x2, long y2, long xsize2, long ysize2)
1570 {
1571 if (x < x2)
1572 {
1573 if (y < y2)
1574 {
1575 if (x2 - x < xsize &&
1576 y2 - y < ysize)
1577 return 1;
1578 }
1579 else // y >= y2
1580 {
1581 if (x2 - x < xsize &&
1582 y - y2 < ysize2)
1583 return 1;
1584 }
1585 }
1586 else // x >= x2
1587 {
1588 if (y < y2)
1589 {
1590 if (x - x2 < xsize2 &&
1591 y2 - y < ysize)
1592 return 1;
1593 }
1594 else // y >= y2
1595 {
1596 if (x - x2 < xsize2 &&
1597 y - y2 < ysize2)
1598 return 1;
1599 }
1600 }
1601 return 0;
1602 }
1603
1604 // The old-fashioned hit check ..
some_hit(long x,long y,walker * ob,screen * screenp)1605 walker * some_hit(long x, long y, walker *ob, screen *screenp)
1606 {
1607 oblink *here;
1608
1609 here = screenp->oblist;
1610
1611 while (here)
1612 {
1613 if (here->ob && here->ob != ob)
1614 if (check_collide(x, y, ob->sizex, ob->sizey,
1615 here->ob->xpos, here->ob->ypos,
1616 here->ob->sizex, here->ob->sizey) )
1617 {
1618 ob->collide_ob = here->ob;
1619 return here->ob;
1620 }
1621 here = here->next;
1622 }
1623
1624 // Also check the fx list ..
1625 here = screenp->fxlist;
1626 while (here)
1627 {
1628 if (here->ob && here->ob != ob)
1629 if (check_collide(x, y, ob->sizex, ob->sizey,
1630 here->ob->xpos, here->ob->ypos,
1631 here->ob->sizex, here->ob->sizey) )
1632 {
1633 ob->collide_ob = here->ob;
1634 return here->ob;
1635 }
1636 here = here->next;
1637 }
1638
1639 // Also check the weapons list ..
1640 here = screenp->weaplist;
1641 while (here)
1642 {
1643 if (here->ob && !here->ob->dead && here->ob != ob)
1644 if (check_collide(x, y, ob->sizex, ob->sizey,
1645 here->ob->xpos, here->ob->ypos,
1646 here->ob->sizex, here->ob->sizey) )
1647 {
1648 ob->collide_ob = here->ob;
1649 return here->ob;
1650 }
1651 here = here->next;
1652 }
1653
1654 ob->collide_ob = NULL;
1655 return NULL;
1656 }
1657
1658 // Display info about the target object ..
1659 #define INFO_DOWN(x) (25+7*x)
info_box(walker * target,screen * myscreen)1660 void info_box(walker *target,screen * myscreen)
1661 {
1662 text *infotext = new text(myscreen);
1663 long linesdown = 0;
1664 long lm = 25+32;
1665 char message[80];
1666 treasure *teleporter, *temp;
1667
1668 static char *orders[] =
1669 { "LIVING", "WEAPON", "TREASURE", "GENERATOR", "FX", "SPECIAL", };
1670 static char *livings[] =
1671 { "SOLDIER", "ELF", "ARCHER", "MAGE",
1672 "SKELETON", "CLERIC", "ELEMENTAL",
1673 "FAERIE", "L-SLIME", "S-SLIME",
1674 "M-SLIME", "THIEF", "GHOST",
1675 "DRUID",
1676 };
1677 static char *treasures[] =
1678 { "BLOODSTAIN", "DRUMSTICK: FOOD",
1679 "GOLD BAR", "SILVER BAR",
1680 "MAGIC POTION", "INVISIBILITY POTION",
1681 "INVULNERABILITY POTION",
1682 "FLIGHT POTION", "EXIT", "TELEPORTER",
1683 "LIFE GEM", "KEY", "SPEED", "CC",
1684 };
1685
1686 release_mouse();
1687 myscreen->draw_button(20+32, 20, 220+32, 170, 1, 1);
1688
1689 infotext->write_xy(lm, INFO_DOWN(linesdown++), "INFO TEXT", DARK_BLUE,1);
1690 linesdown++;
1691
1692 if (strlen(target->stats->name)) // it has a name
1693 {
1694 sprintf(message, "Name : %s", target->stats->name);
1695 infotext->write_xy(lm, INFO_DOWN(linesdown++), message, DARK_BLUE,1);
1696 }
1697
1698 sprintf(message, "Order : %s", orders[target->query_order()] );
1699 infotext->write_xy(lm, INFO_DOWN(linesdown++), message, DARK_BLUE,1);
1700
1701 if (target->query_order() == ORDER_LIVING)
1702 sprintf(message, "Family : %s",
1703 livings[target->query_family()] );
1704 else if (target->query_order() == ORDER_TREASURE)
1705 sprintf(message, "Family : %s",
1706 treasures[target->query_family()] );
1707 else
1708 sprintf(message, "Family : %d", target->query_family());
1709 infotext->write_xy(lm, INFO_DOWN(linesdown++), message, DARK_BLUE,1);
1710
1711 sprintf(message, "Team Num: %d", target->team_num);
1712 infotext->write_xy(lm, INFO_DOWN(linesdown++), message, DARK_BLUE, 1);
1713
1714 sprintf(message, "Position: %dx%d (%dx%d)", target->xpos, target->ypos,
1715 (target->xpos/GRID_SIZE), (target->ypos/GRID_SIZE) );
1716 infotext->write_xy(lm, INFO_DOWN(linesdown++), message, DARK_BLUE,1);
1717
1718 if (target->query_order() == ORDER_TREASURE &&
1719 target->query_family()== FAMILY_EXIT)
1720 sprintf(message, "Exits to: Level %d", target->stats->level);
1721 else if (target->query_order() == ORDER_TREASURE &&
1722 target->query_family() == FAMILY_TELEPORTER)
1723 {
1724 sprintf(message, "Group # : %d", target->stats->level);
1725 infotext->write_xy(lm, INFO_DOWN(linesdown++), message, DARK_BLUE,1);
1726 temp = (treasure *) target;
1727 teleporter = (treasure *) temp->find_teleport_target();
1728 if (!teleporter || teleporter == target)
1729 infotext->write_xy(lm, INFO_DOWN(linesdown++), "Goes to : Itself!", DARK_BLUE,1);
1730 else
1731 {
1732 sprintf(message, "Goes to : %dx%d (%dx%d)", teleporter->xpos,
1733 teleporter->ypos, teleporter->xpos/GRID_SIZE, teleporter->ypos/GRID_SIZE);
1734 }
1735 }
1736 else
1737 sprintf(message, "Level : %d", target->stats->level);
1738 infotext->write_xy(lm, INFO_DOWN(linesdown++), message, DARK_BLUE,1);
1739
1740 linesdown++;
1741 infotext->write_xy(lm, INFO_DOWN(linesdown++),
1742 "PRESS ESC TO EXIT", DARK_BLUE,1);
1743
1744 myscreen->buffer_to_screen(0, 0, 320, 200);
1745 grab_mouse();
1746
1747 // Wait for press and release of ESC
1748 while (!mykeyboard[SDLK_ESCAPE])
1749 get_input_events(WAIT);
1750 while (mykeyboard[SDLK_ESCAPE])
1751 get_input_events(WAIT);
1752 }
1753
1754 // Set the stats->name value of a walker ..
set_name(walker * target,screen * master)1755 void set_name(walker *target, screen * master)
1756 {
1757 char newname[10];
1758 char oldname[20];
1759 char buffer[200];
1760
1761 //gotoxy(1,20);
1762 master->draw_button(30, 30, 220, 70, 1, 1);
1763 sprintf(buffer, "Renaming object");
1764 scentext->write_xy(32, 32, buffer, DARK_BLUE, 1);
1765 sprintf(buffer, "Enter '.' to not change.");
1766 scentext->write_xy(32, 42, buffer, DARK_BLUE, 1);
1767
1768 if (strlen(target->stats->name))
1769 {
1770 sprintf(buffer, "Current name: %s", target->stats->name);
1771 strcpy(oldname, target->stats->name);
1772 }
1773 else
1774 {
1775 sprintf(buffer, "Current name: NOT SET");
1776 strcpy(oldname, "NOT SET");
1777 }
1778 scentext->write_xy(32, 52, buffer, DARK_BLUE, 1);
1779 scentext->write_xy(32, 62, " New name:", DARK_BLUE, 1);
1780
1781 master->buffer_to_screen(0, 0, 320, 200);
1782
1783 // wait for key release
1784 while (mykeyboard[SDLK_r])
1785 get_input_events(WAIT);
1786
1787 strcpy(newname, scentext->input_string(115, 62, 9, oldname) );
1788 newname[10] = 0;
1789
1790 if (strcmp(newname, ".")) // didn't type '.'
1791 strcpy(target->stats->name, newname);
1792
1793 info_box(target,master);
1794
1795 }
1796
scenario_options(screen * myscreen)1797 void scenario_options(screen *myscreen)
1798 {
1799 static text opt_text(myscreen);
1800 char *opt_keys = query_keyboard();
1801 short lm, tm;
1802 char message[80];
1803
1804 lm = 55;
1805 tm = 45;
1806
1807 #define OPT_LD(x) (short) (tm + (x*8) )
1808 while (!opt_keys[SDLK_ESCAPE])
1809 {
1810
1811
1812 myscreen->draw_button(lm-5, tm-5, 260, 160, 2, 1);
1813
1814 opt_text.write_xy(lm, OPT_LD(0), "SCENARIO OPTIONS", DARK_BLUE, 1);
1815
1816 if (myscreen->scenario_type & SCEN_TYPE_CAN_EXIT)
1817 opt_text.write_xy(lm, OPT_LD(2), "Can Always Exit (E) : Yes", DARK_BLUE, 1);
1818 else
1819 opt_text.write_xy(lm, OPT_LD(2), "Can Always Exit (E) : No ", DARK_BLUE, 1);
1820
1821 if (myscreen->scenario_type & SCEN_TYPE_GEN_EXIT)
1822 opt_text.write_xy(lm, OPT_LD(3), " Kill Generators to Exit (G): Yes", DARK_BLUE, 1);
1823 else
1824 opt_text.write_xy(lm, OPT_LD(3), " Kill Generators to Exit (G): No ", DARK_BLUE, 1);
1825
1826 if (myscreen->scenario_type & SCEN_TYPE_SAVE_ALL)
1827 opt_text.write_xy(lm, OPT_LD(4), " Must Save Named NPC's (N) : Yes", DARK_BLUE, 1);
1828 else
1829 opt_text.write_xy(lm, OPT_LD(4), " Must Save Named NPC's (N) : No ", DARK_BLUE, 1);
1830
1831 sprintf(message, " Level Par Value (+,-) : %d ", myscreen->par_value);
1832 opt_text.write_xy(lm, OPT_LD(5), message, DARK_BLUE, 1);
1833
1834
1835 myscreen->buffer_to_screen(0, 0, 320, 200);
1836
1837 get_input_events(WAIT);
1838 if (opt_keys[SDLK_e]) // toggle exit mode
1839 {
1840 if (myscreen->scenario_type & SCEN_TYPE_CAN_EXIT) // already set
1841 myscreen->scenario_type -= SCEN_TYPE_CAN_EXIT;
1842 else
1843 myscreen->scenario_type += SCEN_TYPE_CAN_EXIT;
1844 }
1845 if (opt_keys[SDLK_g]) // toggle exit mode -- generators
1846 {
1847 if (myscreen->scenario_type & SCEN_TYPE_GEN_EXIT) // already set
1848 myscreen->scenario_type -= SCEN_TYPE_GEN_EXIT;
1849 else
1850 myscreen->scenario_type += SCEN_TYPE_GEN_EXIT;
1851 }
1852 if (opt_keys[SDLK_n]) // toggle fail mode -- named guys
1853 {
1854 if (myscreen->scenario_type & SCEN_TYPE_SAVE_ALL) // already set
1855 myscreen->scenario_type -= SCEN_TYPE_SAVE_ALL;
1856 else
1857 myscreen->scenario_type += SCEN_TYPE_SAVE_ALL;
1858 }
1859 if (opt_keys[SDLK_KP_MINUS]) // lower the par value
1860 {
1861 if (myscreen->par_value > 1)
1862 myscreen->par_value--;
1863 }
1864 if (opt_keys[SDLK_KP_PLUS]) // raise the par value
1865 {
1866 myscreen->par_value++;
1867 }
1868 }
1869
1870 while (opt_keys[SDLK_ESCAPE])
1871 get_input_events(WAIT); // wait for key release
1872
1873 myscreen->clearfontbuffer(lm-5, tm-5, 260-(lm-5), 160-(tm-5));
1874 }
1875
1876 // Set an object's facing ..
set_facing(walker * target,screen * myscreen)1877 void set_facing(walker *target, screen *myscreen)
1878 {
1879 char *setkeys = query_keyboard();
1880
1881 if (target)
1882 target = target; // dummy code
1883
1884 myscreen->draw_dialog(100, 50, 220, 170, "Set Facing");
1885 myscreen->buffer_to_screen(0, 0, 320, 200);
1886
1887 while (setkeys[SDLK_f])
1888 get_input_events(WAIT);
1889
1890 }
1891
1892
1893 // Load a grid or scenario ..
do_load(screen * ascreen)1894 long do_load(screen *ascreen)
1895 {
1896 long i;
1897 text *loadtext = new text(ascreen);
1898 char buffer[200],temp[200];
1899
1900 event = 1;
1901 ascreen->draw_button(50, 30, 200, 40, 1, 1);
1902 loadtext->write_xy(52, 32, "Load [G/S] : ", DARK_BLUE, 1);
1903 ascreen->buffer_to_screen(0, 0, 320, 200);
1904 while ( !mykeyboard[SDLK_g] && !mykeyboard[SDLK_s] )
1905 get_input_events(WAIT);
1906 if (mykeyboard[SDLK_s])
1907 {
1908 ascreen->draw_button(50, 30, 200, 40, 1, 1);
1909 ascreen->buffer_to_screen(0, 0, 320, 200);
1910 new_scenario_name();
1911 ascreen->clearfontbuffer(50, 30, 150, 10);
1912 loadtext->write_xy(52, 32, "Loading scenario..", DARK_BLUE, 1);
1913 ascreen->buffer_to_screen(0, 0, 320, 200);
1914 remove_all_objects(ascreen); // kill current obs
1915 for (i=0; i < 60; i ++)
1916 ascreen->scentext[i][0] = 0;
1917 load_scenario(scen_name, ascreen);
1918 ascreen->viewob[0]->myradar->start();
1919 ascreen->viewob[0]->myradar->update();
1920 strcpy(grid_name, query_my_map_name());
1921 while (mykeyboard[SDLK_s])
1922 //buffers: dumbcount++;
1923 get_input_events(WAIT);
1924 //buffers: PORT: stricmp isn't compiling... need to find replacement func
1925 //buffers: workaround: copy scenario_title to new buffer and make it all
1926 //buffers: lowercase and then compare it to lowercase 'none'
1927 strcpy(temp,ascreen->scenario_title);
1928 lowercase(temp);
1929 if (strlen(ascreen->scenario_title) &&
1930 strcmp(temp, "none") )
1931 {
1932 ascreen->draw_button(10, 30, 238, 51, 1, 1);
1933 ascreen->clearfontbuffer(10, 30, 228, 21);
1934 sprintf(buffer, "Loaded: %s", ascreen->scenario_title);
1935 loadtext->write_xy(12, 33, buffer, DARK_BLUE, 1);
1936 loadtext->write_xy(12, 43, "Press space to continue", RED, 1);
1937 ascreen->buffer_to_screen(0, 0, 320, 200);
1938 while (!mykeyboard[SDLK_SPACE])
1939 get_input_events(WAIT);
1940 }
1941 } // end load scenario
1942 else if (mykeyboard[SDLK_g])
1943 {
1944 ascreen->draw_button(50, 30, 200, 40, 1, 1);
1945 ascreen->buffer_to_screen(0, 0, 320, 200);
1946 load_new_grid(ascreen);
1947 while (mykeyboard[SDLK_g])
1948 //dumbcount++;
1949 get_input_events(WAIT);
1950 } // end load new grid
1951
1952 delete loadtext;
1953 levelchanged = 0;
1954 return 1;
1955 }
1956
do_save(screen * ascreen)1957 long do_save(screen *ascreen) // save a scenario or grid
1958 {
1959 text *savetext = new text(ascreen);
1960 long result = 1;
1961
1962 event = 1;
1963 while (mykeyboard[SDLK_s])
1964 get_input_events(WAIT);
1965 ascreen->draw_button(50, 30, 200, 40, 1, 1);
1966 savetext->write_xy(52, 32, "Save [G/S] ", DARK_BLUE, 1);
1967 ascreen->buffer_to_screen(0, 0, 320, 200);
1968 while ( !mykeyboard[SDLK_s] && !mykeyboard[SDLK_g] )
1969 get_input_events(WAIT);
1970 if (mykeyboard[SDLK_s]) // save scenario
1971 {
1972 while (mykeyboard[SDLK_s])
1973 get_input_events(WAIT);
1974
1975 // Allow us to set the title, if desired
1976 ascreen->draw_button(20, 30, 235, 41, 1, 1);
1977 savetext->write_xy(22, 33, "Title:", DARK_BLUE, 1);
1978 ascreen->buffer_to_screen(0, 0, 320, 200);
1979 strcpy(ascreen->scenario_title,
1980 savetext->input_string(58, 33, 29, ascreen->scenario_title) );
1981
1982 ascreen->clearfontbuffer(20, 30, 215, 15);
1983 savetext->write_xy(52, 33, "Saving scenario..");
1984 ascreen->buffer_to_screen(0, 0, 320, 200);
1985 // Save the map file ..
1986 if (!save_map_file(grid_name, ascreen) )
1987 //printf("\nError saving map.\n");
1988 result = 0;
1989 else
1990 save_scenario(scen_name, ascreen, grid_name);
1991
1992 ascreen->clearfontbuffer();
1993 clear_keyboard();
1994 } // end of save scenario
1995 else if (mykeyboard[SDLK_g]) // save current grid
1996 {
1997 ascreen->clearfontbuffer(50, 30, 150, 10);
1998 savetext->write_xy(52, 32, "Saving grid..");
1999 ascreen->buffer_to_screen(0, 0, 320, 200);
2000 if (!save_map_file(grid_name, ascreen) )
2001 //printf("\nError saving map!\n");
2002 result = 0;
2003
2004 ascreen->clearfontbuffer();
2005 clear_keyboard();
2006 } // end of save grid
2007
2008 delete savetext;
2009
2010 if (result)
2011 levelchanged = 0;
2012 return result;
2013 }
2014