Initial Import
[glAntsMech.git] / glants_mech / linux / src / globals.c
bloba71f5a0c08f19724f315f1b364ec8850d82d0164
1 //
2 // globals.cpp
3 //
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <malloc.h>
8 #include <string.h>
9 #include <time.h>
10 #include <stdarg.h>
12 #include <sys/time.h>
13 #include <math.h>
15 #include <GL/gl.h> // Header File For The OpenGL32 Library
16 #include <GL/glu.h> // Header File For The GLu32 Library
19 #include "defaults.h"
20 #include "bot.h"
21 #include "gldrawlib.h"
22 #include "globals.h"
23 #include "camera.h"
24 #include "text.h"
25 #include "menu.h"
26 #include "keys.h"
27 #include "fireants.h"
28 #include "network/include/connect.h"
29 #include "network/include/clients.h"
31 #define CONFIG_FILE_NAME "config.ini"
32 #define ERROR_FILE_NAME "error.log"
33 FILE *f_config = NULL;
34 FILE *f_errorlog = NULL;
35 FILE *f_newfile = NULL;
37 // false = no error
38 bool config_errors[MAX_ERRORS];
40 AntGlobals *ant_globals;
42 char error_str[MAX_ERRORS][40] = {
43 "NULL",
44 "LINE_OF_SIGHT",
45 "ATTACK_RADIUS",
46 "BULLET_DAMAGE",
47 "MIN_BULLET_SPEED",
48 "USE_ANT_ENGINE",
49 "MAX_FIRE_ANTS",
50 "MAX_BOTS",
51 "USE_GARDEN_AREA",
52 "MAX_TRAIL_STACK",
53 "DYING_STATE",
54 "MAX_PHEROMONES",
55 "PHEROMONE_LIFE",
56 "PHEROMONE_DROP",
57 "MAX_BULLETS",
58 "MAX_FIRE_SPEED",
59 "MAX_GARDENS",
60 "BOT_SPEED",
61 "BOT_MAX_SPEED",
62 "MIN_TURN_SPEED",
63 "CHECK_RESPAWN",
64 "GARD_RESPAWN_RATE",
65 "MIN_STRAIGHT_STEPS",
66 "MAX_STRAIGHT_STEPS",
67 "MIN_STRAIGHT_STEPS_2",
68 "MAX_STRAIGHT_STEPS_2",
69 "INITIAL_ANT_FOOD",
70 "INITIAL_GARD_FOOD",
71 "FOOD_WIDTH",
72 "INIT_FOOD_RATE",
73 "MAX_FOOD_RATE",
74 "MOVE_FOOD_RATE",
75 "FOOD_RATE"
80 // Config msgs
82 #define MAX_TXT_MSGS 40
83 char text_msg[MAX_TXT_MSGS][80] =
85 "#\n",
86 "# glAnts - original config.ini\n",
87 "# file, change at your own risk\n",
88 "#\n",
89 "# if you remove this file, the program\n",
90 "# will create another one with the defaults\n",
91 "# so removing this file can be a good thing\n",
92 "#\n",
93 "#\n",
94 "# Also of note, if the system finds an error\n",
95 "# it goes with the default variable\n",
96 "#\n",
97 "# FORMAT has to be [VARIABLE_NAME]=VALUE;\n",
98 "# oh yeah, add the 'f' tag for float\n",
99 "# \n",
100 "# [VARIABLE_NAME]=VALUEf;\n",
101 "# \n",
102 "# COMMENTS are '#'\n",
103 "#\n",
104 "# Remove the comments below are your own risk\n",
105 "# they basically just define the default values\n",
106 "# used, if you remove them then you wont know\n",
107 "# what good values will look like\n",
108 "#\n",
109 "# The only things that really need changing\n",
110 "# are:\n",
111 "#\n",
112 "# USE_ANT_ENGINE: take out the little ants \n",
113 "#\n",
114 "# MAX_FIRE_ANTS: max fighter ants\n",
115 "# \n",
116 "# MAX_BOTS: number of worker ants\n",
117 "#\n",
118 "# INITIAL_ANT_FOOD: the health of the fighter\n",
119 "# ants and the workers\n",
120 "# try 10,000 and they will never die\n",
121 "#\n",
122 "# Also, you may comment one of the variables\n",
123 "# and get the default once the program runs\n",
124 "#\n"
129 // intro_str
131 char intro_str[] = {
132 "glAnts is a mech game.\n" \
133 "It is loosely based on spectreVR.\n" \
134 "glAnts was created with GCCv2.96... \n" \
135 "just kidding, it will be though... \n" \
136 "visit glants.sourceforge.net for updates\n" \
137 "Linux version coming soon..."
138 "\n(berlin ltd.)\n\n\n\n" \
139 "Microsoft has issued\n" \
140 "yet another critical update.\n" \
141 "Software Piracy is \nGood for Microsoft\n\n" \
145 // text used to fill the network window
147 char network_str_[26][80] = {
148 "::Player Name: Player1", // 0
149 "::IP Address: 127.0.0.1", // 1
150 "::Send Bots Only: false", // 2
151 "::Network Bots: 1", // 3
152 "Total Players to Send: ", // 4
153 "IP Address-", // 5
154 "Server-", // 6
155 "Ping-", // 7
156 "Cur/Max-", // 8
157 "Vers-", // 9
158 "OS", // 10
159 "Connect To Server", // 11
160 "Server Settings", // 12
161 "Client Settings", // 13
162 "::Server Name: Server1", // 14
163 "::Current IP: 127.0.0.1", // 15
164 "::Use Bots Only: false", // 16
165 "::Host Bots: 1", // 17
166 "IP Address-", // 18
167 "Client-", // 19
168 "Ping-", // 20
169 "OS-", // 21 --
170 " (Connect to Server)", // 22
171 " (Disconnect from Server)" , // 23
172 " (Start Server)", // 24
173 " (Shutdown Server)" }; // 25
176 #define HORZ_TYPE_ 2
177 #define VERT_TYPE_ 4
178 #define STAT_TYPE_ 6
181 #define N_TITLE_X 200
182 #define N_TITLE_YY1 200
183 #define N_TITLE_YY2 220
185 // strlength is taken into consideration
186 #define TEXT_HORZ_START 60.0f
187 #define TEXT_HORZ_WIDTH 40
188 #define TEXT_VERT_START 60.0f
189 #define TEXT_VERT_STARTY2 240
190 #define TEXT_VERT_HEIGHT 16
191 #define TXT_V_START 160.0f
192 #define TXT_V_STARTYY2 330
194 // x positions
195 #define T_COL_1 160
196 #define T_COL_2 240
197 #define T_COL_3 300
198 #define T_COL_4 370
199 #define T_COL_5 420
201 #define T_COL_6 60
202 #define T_COL_7 240
203 #define T_ROW_1 142
204 #define T_ROW_2 312
205 #define T_ROW_3 414
206 #define T_ROW_4 424
209 static char *_tmp_str = NULL;
210 static clock_t curr_Time;
211 static clock_t next_Time = 0;
213 // WRAPPER FUNCTIONS FOR TEXT--
215 // There are three different text areas
216 // The top, left text contains the score
217 // the top, right text contains the fps and any
218 // other system specific data --
220 // NOTE: use Super_Printf for debug code
221 // - you also have to call drawText to
222 // actually render to screen
225 TextBoxPtr main_text = NULL;
226 TextBoxPtr score_text = NULL;
227 TextBoxPtr help_text = NULL;
228 TextBoxPtr intro_text = NULL;
229 TextBoxPtr network_text = NULL;
232 // Set_TitleScreen
233 // - put the state in title screen mode
234 // - usaully used by the network interface
236 void Mode_TitleScreen(void)
239 ant_globals->paused = 1;
240 ant_globals->menu_mode = MENU_TITLE_MODE;
242 } // end of the function
245 // Set into running mode
246 // play - game
248 void Mode_SetRunning(void)
251 ant_globals->paused = 0;
252 ant_globals->menu_mode = MENU_RUN_MODE;
254 // Not the first time any more
255 ant_globals->_menu_state = FIRST_TIME_FALSE;
257 // NOTE NOTE NOTE NOTE!
258 // reset the bots here
259 // this may take 1a while
260 //Reset_FireAnts();
261 Reset_NetworkBots();
263 } // end of the function
268 // Super_MainText
270 void Super_MainText(void)
272 main_text = InitTextBox(10, 200, 400, 480);
273 SetTextMode(main_text, TEXT_NONE);
274 SetTextColor(main_text, 0, 255, 0);
275 Printf(main_text, "** DEBUG TEXT\n");
278 // Now prepare the score text- upper left
279 score_text = InitTextBox(10, 300, 10, 200);
280 SetTextMode(score_text, TEXT_NONE);
281 SetTextColor(score_text, 0, 255, 0);
283 // Build the help screen text --
284 help_text = InitTextBox(230, 500, 180, 370);
285 SetTextMode(help_text, TEXT_NONE);
286 SetTextColor(help_text, 255, 255, 255);
289 // Build the help text here
291 Printf(help_text, "[ESC] - Main Screen\n\n");
292 Printf(help_text, "[P] - Pause\n\n");
293 Printf(help_text, "[Q] - Quit\n\n");
294 Printf(help_text, "[TAB] - First/Third View Mode\n\n");
295 Printf(help_text, "[ARROW KEYS] - Turn\n\n");
296 Printf(help_text, "[SPACE] - Fire\n\n");
297 Printf(help_text, "[S,F,R MOUSE] - Adjust View\n");
298 Printf(help_text, "[F1] - Full Screen\n\n");
301 // Intro text
303 intro_text = InitTextBox(340, 630, 340, 430);
304 SetTextMode(intro_text, TEXT_NONE);
305 SetTextColor(intro_text, 255, 255, 255);
307 _tmp_str = intro_str;
310 // network_text
312 network_text = InitTextBox(340, 630, 340, 430);
313 SetTextMode(network_text, TEXT_NONE);
314 SetTextColor(network_text, 255, 255, 255);
316 } // end of the function
319 // Draw_TString
320 void Draw_TString(int x, int y, char *str)
322 TextBegin(network_text);
323 DrawString(network_text, x, y, str);
324 TextEnd();
326 } // end of the func
329 // Set_Net_Menu(int
330 // - setup the horizontal or vertical positions
331 // and draw the text --
333 static void Setup_NetMenu(int start_pos, int end_pos, int h_type)
336 int i;
337 float horz_pos;
338 float vert_pos;
341 // set the text changes before the code below
344 switch(h_type)
346 case HORZ_TYPE_:
348 // we only have two diferent cases to handle
349 if (start_pos == C_HORZ_MENU)
352 horz_pos = TEXT_HORZ_START;
353 vert_pos = TXT_V_START;
355 TextBegin(network_text);
356 DrawString(network_text, horz_pos, vert_pos, network_str_[C_HORZ_MENU]);
357 TextEnd();
359 // next col --
360 horz_pos = T_COL_1;
361 vert_pos = TXT_V_START;
363 TextBegin(network_text);
364 DrawString(network_text, horz_pos, vert_pos, network_str_[C_HORZ_MENU+1]);
365 TextEnd();
367 // next col --
368 horz_pos = T_COL_2;
369 vert_pos = TXT_V_START;
371 TextBegin(network_text);
372 DrawString(network_text, horz_pos, vert_pos, network_str_[C_HORZ_MENU+2]);
373 TextEnd();
375 // next col --
376 horz_pos = T_COL_3;
377 vert_pos = TXT_V_START;
379 TextBegin(network_text);
380 DrawString(network_text, horz_pos, vert_pos, network_str_[C_HORZ_MENU+3]);
381 TextEnd();
384 // next col --
385 horz_pos = T_COL_4;
386 vert_pos = TXT_V_START;
388 TextBegin(network_text);
389 DrawString(network_text, horz_pos, vert_pos, network_str_[C_HORZ_MENU+4]);
390 TextEnd();
393 // next col --
394 horz_pos = T_COL_5;
395 vert_pos = TXT_V_START;
397 TextBegin(network_text);
398 DrawString(network_text, horz_pos, vert_pos, network_str_[C_HORZ_MENU+5]);
399 TextEnd();
401 } // end of the
402 else {
404 horz_pos = TEXT_HORZ_START;
405 vert_pos = TXT_V_STARTYY2;
406 TextBegin(network_text);
407 DrawString(network_text, horz_pos, vert_pos, network_str_[S_SERV_HORZ]);
408 TextEnd();
410 // next col
411 horz_pos = T_COL_1;
412 vert_pos = TXT_V_STARTYY2;
414 TextBegin(network_text);
415 DrawString(network_text, horz_pos, vert_pos, network_str_[S_SERV_HORZ+1]);
416 TextEnd();
419 horz_pos = T_COL_2;
420 vert_pos = TXT_V_STARTYY2;
422 TextBegin(network_text);
423 DrawString(network_text, horz_pos, vert_pos, network_str_[S_SERV_HORZ+2]);
424 TextEnd();
426 horz_pos = T_COL_3;
427 vert_pos = TXT_V_STARTYY2;
429 TextBegin(network_text);
430 DrawString(network_text, horz_pos, vert_pos, network_str_[S_SERV_HORZ+3]);
431 TextEnd();
433 } // end of the if-else
437 break;
439 case VERT_TYPE_:
441 if (start_pos == CLIENT_NET_MENU)
442 vert_pos = TEXT_VERT_START;
443 else
444 vert_pos = TEXT_VERT_STARTY2;
446 for (i = start_pos; i <= end_pos; i++)
448 TextBegin(network_text);
449 DrawString(network_text, TEXT_HORZ_START, vert_pos, network_str_[i]);
450 TextEnd();
452 vert_pos = vert_pos + TEXT_VERT_HEIGHT;
454 } // end of the for
456 break;
458 case STAT_TYPE_:
459 break;
462 case SERVER_SETTINGS:
463 TextBegin(network_text);
464 DrawString(network_text, start_pos,
465 end_pos, network_str_[SERVER_SETTINGS]);
466 TextEnd();
468 break;
471 case CLIENT_SETTINGS:
472 TextBegin(network_text);
473 DrawString(network_text, start_pos,
474 end_pos, network_str_[CLIENT_SETTINGS]);
475 TextEnd();
477 break;
482 } // end of the function
485 // Draw_NetworkScreen
487 void Draw_NetworkScreen(void)
489 const float box_x_min = 50.0f;
490 const float box_x_max = 500.0f;
491 const float box_y_min = 50.0f;
492 const float box_y_max = 440.0f;
494 const float msg_y = box_y_max - 32.0f;
496 char buffer[80];
498 glDisable(GL_TEXTURE_2D);
500 // Draw a blue screen
501 // in the background
503 glColor3ub(20, 120, 235);
505 glLineWidth(3.0f);
506 glBegin(GL_QUADS);
507 glVertex3f(box_x_min, box_y_min, 0.0f);
508 glVertex3f(box_x_max, box_y_min, 0.0f);
510 glVertex3f(box_x_max, box_y_max, 0.0f);
511 glVertex3f(box_x_min, box_y_max, 0.0f);
513 glEnd();
516 // draw outline around object
517 glColor3ub(255, 255, 255);
518 glBegin(GL_LINE_LOOP);
519 glVertex3f(box_x_min, box_y_min, 0.0f);
520 glVertex3f(box_x_max, box_y_min, 0.0f);
522 glVertex3f(box_x_max, box_y_max, 0.0f);
523 glVertex3f(box_x_min, box_y_max, 0.0f);
524 glEnd();
526 // The next line
527 // will be used for the message screen
528 glBegin(GL_LINE_LOOP);
529 glVertex3f(box_x_min, msg_y, 0.0f);
530 glVertex3f(box_x_max, msg_y, 0.0f);
531 glEnd();
534 glLineWidth(1.0f);
536 // before drawing the name, save selection
537 Display_NetSel(network_str_);
539 // Print the actual text
540 Setup_NetMenu(CLIENT_NET_MENU, END_CLIENT_NET, VERT_TYPE_);
541 Setup_NetMenu(C_HORZ_MENU, END_CLIENT_NET, HORZ_TYPE_);
543 Setup_NetMenu(N_TITLE_X, N_TITLE_YY2, SERVER_SETTINGS);
544 Setup_NetMenu(SERVER_NET_MENU, END_SERVER_NET, VERT_TYPE_);
545 Setup_NetMenu(S_SERV_HORZ, E_SERV_HORZ, HORZ_TYPE_);
548 // Draw the static text
549 TextBegin(network_text);
550 DrawString(network_text, T_COL_6,
551 T_ROW_1, network_str_[_TEXT_CONNECT_]);
552 TextEnd();
554 TextBegin(network_text);
555 DrawString(network_text, T_COL_7,
556 T_ROW_1, network_str_[_TEXT_DISCONNECT_]);
557 TextEnd();
559 // Server buttons --
560 TextBegin(network_text);
561 DrawString(network_text, T_COL_6,
562 T_ROW_2, network_str_[_TEXT_START_]);
563 TextEnd();
565 TextBegin(network_text);
566 DrawString(network_text, T_COL_7,
567 T_ROW_2, network_str_[_TEXT_SHUTDOWN_]);
568 TextEnd();
570 // And at the bottom
571 // the network and help screens and messages
572 TextBegin(network_text);
574 // get network message
575 Get_NetworkMsg(buffer);
576 DrawString(network_text, TEXT_HORZ_START,
577 T_ROW_3, buffer);
578 TextEnd();
580 // print connections if there are any
581 printConnections();
583 } // end of the functino
587 // Draw_HelpScreen
589 void Draw_IntroScreen(void)
592 glDisable(GL_TEXTURE_2D);
594 // Draw a blue screen
595 // in the background
596 glColor3ub(20, 120, 235);
598 glLineWidth(2.0f);
599 glBegin(GL_QUADS);
600 glVertex3f(320.0f, 320.0f, 0.0f);
601 glVertex3f(635.0f, 320.0f, 0.0f);
603 glVertex3f(635.0f, 440.0f, 0.0f);
604 glVertex3f(320.0f, 440.0f, 0.0f);
606 glEnd();
609 // draw outline around object
610 glColor3ub(255, 255, 255);
611 glBegin(GL_LINE_LOOP);
612 glVertex3f(320.0f, 320.0f, 0.0f);
613 glVertex3f(635.0f, 320.0f, 0.0f);
615 glVertex3f(635.0f, 440.0f, 0.0f);
616 glVertex3f(320.0f, 440.0f, 0.0f);
618 glEnd();
621 glLineWidth(1.0f);
623 //DrawText(intro_text);
624 //curr_Time = GetTickCount();
625 curr_Time = clock();
627 if (curr_Time > next_Time) {
629 Printf(intro_text, "%c", *_tmp_str);
631 next_Time = curr_Time + (800*1.4);
633 // delay a little bit
634 if (*(_tmp_str) == ')')
635 next_Time = curr_Time + (8000*1.4);
638 // update the char
639 if (*(++_tmp_str) == '\0')
640 _tmp_str = intro_str;
642 } // end of the if
644 DrawText(intro_text);
648 } // end of the function
653 // Draw_HelpScreen
655 void Draw_HelpScreen(void)
658 glDisable(GL_TEXTURE_2D);
660 // Draw a blue screen
661 // in the background
663 glColor3ub(20, 120, 235);
665 glLineWidth(2.0f);
666 glBegin(GL_QUADS);
667 glVertex3f(220.0f, 160.0f, 0.0f);
668 glVertex3f(480.0f, 160.0f, 0.0f);
670 glVertex3f(480.0f, 320.0f, 0.0f);
671 glVertex3f(220.0f, 320.0f, 0.0f);
673 glEnd();
676 // draw outline around object
677 glColor3ub(255, 255, 255);
678 glBegin(GL_LINE_LOOP);
679 glVertex3f(220.0f, 160.0f, 0.0f);
680 glVertex3f(480.0f, 160.0f, 0.0f);
682 glVertex3f(480.0f, 320.0f, 0.0f);
683 glVertex3f(220.0f, 320.0f, 0.0f);
685 glEnd();
688 glLineWidth(1.0f);
690 DrawText(help_text);
693 } // end of the function
696 // Super_Printf
697 // - print the debug text screen
699 void Super_Printf(char* fmt, ... )
701 va_list vlist;
702 char buff[MAX_STR];
704 // Get output string
705 va_start(vlist, fmt);
706 vsprintf(buff, fmt, vlist);
708 FormatStrCat(main_text, buff);
710 va_end(vlist);
712 } // end of the function
715 // Score
717 void Score_Printf(char* fmt, ... )
719 va_list vlist;
720 char buff[MAX_STR];
722 // Get output string
723 va_start(vlist, fmt);
724 vsprintf(buff, fmt, vlist);
726 FormatStrCat(score_text, buff);
728 va_end(vlist);
730 } // end of the function
734 // Super_BeginPaused
735 // - once the game is started, begin in paused mode
737 void Super_BeginPaused(void)
739 ant_globals->paused = 1;
741 } // end of the fuction
744 // Print_Score
746 void Print_Score(void)
748 int i = 0;
749 char buffer[80];
750 int x,y;
752 for (i = 0; i < MAX_SCORE_DISPLAY; i++)
754 sprintf(buffer, "BUG\n");
756 sprintf(buffer, "P%d %0.2f %d\n",
757 ant_globals->score_obj[i].name,
758 ant_globals->score_obj[i].score,
759 ant_globals->score_obj[i].kills);
762 TextBegin(score_text);
763 DrawString(score_text, 10, 4+(i*10), buffer);
764 TextEnd();
766 } // end of the for
768 // Also, print frames per second
769 sprintf(buffer, "FPS: %0.2f", framerate);
770 TextBegin(score_text);
771 DrawString(score_text, 500, 4, buffer);
772 TextEnd();
774 // And the score and health
775 sprintf(buffer, "Armor: %0.2f", ant_globals->player_health);
776 TextBegin(score_text);
777 DrawString(score_text, 300, 4, buffer);
778 TextEnd();
780 // Print the current position
781 sprintf(buffer, "%d/%d Bots",
782 ant_globals->alive_bots, (MAX_FIRE_ANTS-1));
783 TextBegin(score_text);
784 DrawString(score_text, 300, 14, buffer);
785 TextEnd();
787 // Print some paused text
788 if (ant_globals->paused)
791 // find the correct x pos
792 x = 12 * 8;
793 x /= 2;
795 x = (SCREEN_WIDTH/2) - x;
796 y = (SCREEN_HEIGHT / 2);
798 // And the score and health
799 sprintf(buffer, "- PAUSED -");
800 TextBegin(score_text);
801 DrawString(score_text, x, y, buffer);
802 TextEnd();
804 sprintf(buffer, "(GLANTS)");
805 TextBegin(score_text);
806 DrawString(score_text, x+8, y+10, buffer);
807 TextEnd();
811 } // end of the if
813 } // end of the function
818 // Draw Text
820 void Super_DrawText(void)
822 DrawText(main_text);
824 Print_NetRun();
826 // Also placing print score
827 // here, for some reason...
828 Print_Score();
830 } // end of the function
833 // Destroy_MainText(void)
835 void Super_KillText(void)
838 DestroyTextBox(main_text);
839 DestroyTextBox(score_text);
840 DestroyTextBox(help_text);
841 DestroyTextBox(intro_text);
843 DestroyTextBox(network_text);
845 } // end of the function
849 // Super
851 void Super_LoadGlobals(void)
853 ant_globals = (AntGlobals *)malloc(sizeof(AntGlobals));
856 ZeroMemory((AntGlobals *)ant_globals,
857 sizeof(AntGlobals));
858 } // end of the function
861 // Super
863 void Super_KillGlobals(void)
865 // free the other allocated
866 // arrays
867 //free(ant_globals->score_obj);
868 //free(ant_globals);
870 RELEASE_OBJECT(ant_globals->score_obj);
872 RELEASE_OBJECT(ant_globals);
874 } // end of the function
877 // Init Globals
879 void InitGlobals(void)
881 ant_globals->alive_ants = MAX_FIRE_ANTS;
882 ant_globals->seconds = 0;
883 ant_globals->time_t = 0;
884 ant_globals->nest_food = 0;
885 ant_globals->garden = 0;
886 ant_globals->player_health = 0;
887 ant_globals->paused = 0;
888 ant_globals->alive_bots = MAX_FIRE_ANTS-1;
890 ant_globals->menu_mode = MENU_TITLE_MODE;
891 ant_globals->_menu_state = FIRST_TIME_TRUE;
893 SET_NET_OFF; // turn network interface off
895 ant_globals->score_obj = (struct tagScoreObj *)malloc(
896 MAX_FIRE_ANTS*sizeof(struct tagScoreObj));
899 // load with zeros
900 ZeroMemory(ant_globals->score_obj,
901 MAX_FIRE_ANTS*sizeof(ScoreObj));
904 } // end of the function
907 // TogglePaused
909 void TogglePaused(void)
912 if (ant_globals->paused) {
914 ant_globals->paused = 0;
915 }else {
917 ant_globals->paused = 1;
918 } // end of if-else
920 } // end of the ufnctio
923 // DestroyGlobals
925 void DestroyGlobals(void)
927 // nada?
928 } // end of the function
931 // Load_Score
933 void Load_Score(float score, float kills, int id, int i)
936 ant_globals->score_obj[i].score = score;
937 ant_globals->score_obj[i].kills = kills;
938 ant_globals->score_obj[i].name = id;
941 } // end of the function
944 // SubtractAnts
946 void SubtractAnts(int ants)
948 if (ant_globals->alive_ants <= 0)
950 ant_globals->alive_ants = 0;
951 return;
952 } // end of if
954 ant_globals->alive_ants -= ants;
956 } // end of the function
959 // AddAnts
961 void AddAnts(int ants)
964 ant_globals->alive_ants += ants;
966 } // end of the function
969 // GetAnts
971 int GetAnts(void){
972 return ant_globals->alive_ants;
973 } // end of the functino
976 // AddSeconds
978 void AddSeconds(float delta)
980 ant_globals->seconds += delta;
981 } // end of the function
984 // Add Time
986 // - time to render each frames
988 void AddTime(float delta)
990 ant_globals->time_t = delta;
991 } // end of the function
994 // Set GardenSize
996 void SetGardenSize(int v)
998 ant_globals->garden += v;
1000 } // end of func
1003 // GetGarden
1005 int GetGardenSize(void)
1007 return ant_globals->garden;
1008 } // end of func
1011 // SetNestfood
1013 void SetNestFood(float d)
1015 ant_globals->nest_food = d;
1017 } // end of function
1020 // SetNestfood
1022 void SetPlayerHealth(float d)
1024 ant_globals->player_health = d;
1026 } // end of function
1031 // AddTick
1032 // - number of ticks in the game
1033 void GameTick(void)
1035 ant_globals->ticks += 1;
1037 } // end of the function
1040 // GetGameTick
1042 DWORD GetGameTick(void)
1044 return ant_globals->ticks;
1045 } // end of the functino
1049 // PrintGlobals
1051 void PrintGlobals(void)
1053 int i = 0;
1055 #if HUD_ANTS
1056 glRasterPos2i(10, 48+14);
1057 PrintText("ANTS: %d", ant_globals->alive_ants);
1058 #endif
1060 #if HUD_SECS
1061 glRasterPos2i(10, 48+28);
1062 PrintText("TIME: %0.1f", ant_globals->seconds);
1063 #endif
1066 #if HUD_TIME_T
1067 glRasterPos2i(10, 48+42);
1068 PrintText("TIME_T: %0.0f", ant_globals->time_t);
1069 #endif
1071 #if HUD_NEST_FOOD
1072 glRasterPos2i(10, 48+56);
1073 PrintText("FOOD: %0.0f", ant_globals->nest_food);
1074 //PrintText("FOOD: %ld", ant_globals.ticks);
1075 #endif
1078 #if HUD_GARDEN
1079 glRasterPos2i(10, 48+70);
1080 PrintText("GARD: %d", ant_globals->garden);
1081 //PrintText("FOOD: %ld", ant_globals.ticks);
1082 #endif
1085 #if HUD_POS
1086 // note: hud_NEST_FOOD must be turned off
1087 glRasterPos2i(10, 48+56);
1088 PrintText("x: %0.2f y: %0.2f", GetBotX(), GetBotY());
1089 #endif
1091 #if HUD_HEALTH
1092 glRasterPos2i(10, 48+70);
1093 PrintText("LIFE: %0.2f", ant_globals->player_health);
1094 //PrintText("FOOD: %ld", ant_globals.ticks);
1095 #endif
1097 #if HUD_SCORE
1099 for (i = 0; i < MAX_SCORE_DISPLAY; i++)
1101 #if 0
1102 glRasterPos2i(10, (SCREEN_HEIGHT-14)-(i*14));
1103 PrintText("P%d %0.2f %d",
1104 ant_globals->score_obj[i].name,
1105 ant_globals->score_obj[i].score,
1106 ant_globals->score_obj[i].kills);
1107 #endif
1108 } // end of the for
1110 #endif
1112 } // end of the function
1115 // CONFIG LOADING FUNCTIONS
1119 // SetErrorLog
1120 // - call before Load configfile
1121 // or place it in load configfile, whatever
1123 // hopefully, run-time errors will not occur
1125 void Set_ErrorLog(void)
1127 int i;
1129 // false means no error
1131 // we will assume that there were errors
1132 // except for the file open
1133 for (i = 0; i < MAX_ERRORS; i++)
1134 config_errors[i] = true;
1136 config_errors[ID_FILE_NOT_FOUND] = false;
1138 f_errorlog =fopen(ERROR_FILE_NAME, "w");
1140 fprintf(f_errorlog, "-- FILE_LOADED\n\n");
1142 fclose(f_errorlog);
1144 } // end of the function
1147 // Add_ErrorLog
1148 // - add an entry to the error log
1150 void Add_ErrorStr(char *str)
1152 f_errorlog = NULL;
1154 f_errorlog = fopen(ERROR_FILE_NAME, "a");
1156 fprintf(f_errorlog, "%s\n", str);
1158 fclose(f_errorlog);
1160 } // end of the functino
1163 // Add_ErrorLog
1164 // - add an entry to the error log
1166 void Add_ErrorLog(const int error_id)
1168 f_errorlog = NULL;
1170 f_errorlog = fopen(ERROR_FILE_NAME, "a");
1172 config_errors[error_id] = true;
1174 switch(error_id)
1176 case ID_FILE_NOT_FOUND:
1177 fprintf(f_errorlog, "error: config FILE_NOT_FOUND\n");
1178 break;
1180 case ID_LINE_OF_SIGHT:
1181 fprintf(f_errorlog, "error: LINE_OF_SIGHT\n");
1182 break;
1184 case ID_ATTACK_RADIUS:
1185 fprintf(f_errorlog, "error: ATTACK_RADIUS\n");
1186 break;
1188 case ID_BULLET_DAMAGE:
1189 fprintf(f_errorlog, "error: BULLET_DAMAGE\n");
1190 break;
1192 case ID_MIN_BULLET_SPEED:
1193 fprintf(f_errorlog, "error: MIN_BULLET_SPEED\n");
1194 break;
1196 case ID_USE_ANT_ENGINE:
1197 fprintf(f_errorlog, "error: USE_ANT_ENGINE:\n");
1198 break;
1200 case ID_MAX_FIRE_ANTS:
1201 fprintf(f_errorlog, "error: MAX_FIRE_ANTS\n");
1202 break;
1204 case ID_MAX_BOTS:
1205 fprintf(f_errorlog, "error: MAX_BOTS\n");
1206 break;
1208 case ID_USE_GARDEN_AREA:
1209 fprintf(f_errorlog, "error: USE_GARDEN_AREA\n");
1210 break;
1212 case ID_MAX_TRAIL_STACK:
1213 fprintf(f_errorlog, "error: MAX_TRAIL_STACK\n");
1214 break;
1216 case ID_DYING_STATE:
1217 fprintf(f_errorlog, "error: DYING_STATE\n");
1218 break;
1220 case ID_MAX_PHEROMONES:
1221 fprintf(f_errorlog, "error: MAX_PHEROMONES\n");
1222 break;
1224 case ID_PHEROMONE_LIFE:
1225 fprintf(f_errorlog, "error: PHEROMONE_LIFE\n");
1226 break;
1228 case ID_PHEROMONE_DROP:
1229 fprintf(f_errorlog, "error: PHEROMONE_DROP\n");
1230 break;
1232 case ID_MAX_BULLETS:
1233 fprintf(f_errorlog, "error: MAX_BULLETS\n");
1234 break;
1236 case ID_MAX_FIRE_SPEED:
1237 fprintf(f_errorlog, "error: MAX_FIRE_SPEED\n");
1238 break;
1240 case ID_MAX_GARDENS:
1241 fprintf(f_errorlog, "error: MAX_GARDENS\n");
1242 break;
1244 case ID_BOT_SPEED:
1245 fprintf(f_errorlog, "error: BOT_SPEED\n");
1246 break;
1248 case ID_BOT_MAX_SPEED:
1249 fprintf(f_errorlog, "error: BOT_MAX_SPEED\n");
1250 break;
1252 case ID_MIN_TURN_SPEED:
1253 fprintf(f_errorlog, "error: MIN_TURN_SPEED\n");
1254 break;
1256 case ID_CHECK_RESPAWN:
1257 fprintf(f_errorlog, "error: CHECK_RESPAWN\n");
1258 break;
1260 case ID_GARD_RESPAWN_RATE:
1261 fprintf(f_errorlog, "error: GARD_RESPAWN_RATE\n");
1262 break;
1264 case ID_MIN_STRAIGHT_STEPS:
1265 fprintf(f_errorlog, "error: MIN_STRAIGHT_STEPS\n");
1266 break;
1268 case ID_MAX_STRAIGHT_STEPS:
1269 fprintf(f_errorlog, "error: MAX_STRAIGHT_STEPS\n");
1270 break;
1272 case ID_MIN_STRAIGHT_STEPS_2:
1273 fprintf(f_errorlog, "error: MIN_STRAIGHT_STEPS_2:\n");
1274 break;
1276 case ID_MAX_STRAIGHT_STEPS_2:
1277 fprintf(f_errorlog, "error: MAX_STRAIGHT_STEPS_2\n");
1278 break;
1280 case ID_INITIAL_ANT_FOOD:
1281 fprintf(f_errorlog, "error: INITIAL_ANT_FOOD\n");
1282 break;
1284 case ID_INITIAL_GARD_FOOD:
1285 fprintf(f_errorlog, "error: INITIAL_GARD_FOOD\n");
1286 break;
1288 case ID_FOOD_WIDTH:
1289 fprintf(f_errorlog, "error: FOOD_WIDTH\n");
1290 break;
1292 case ID_INIT_FOOD_RATE:
1293 fprintf(f_errorlog, "error: INIT_FOOD_RATE\n");
1294 break;
1296 case ID_MAX_FOOD_RATE:
1297 fprintf(f_errorlog, "error: MAX_FOOD_RATE\n");
1298 break;
1300 case ID_MOVE_FOOD_RATE:
1301 fprintf(f_errorlog, "error: MOVE_FOOD_RATE\n");
1302 break;
1304 case ID_FOOD_RATE:
1305 fprintf(f_errorlog, "error: FOOD_RATE\n");
1306 break;
1308 default:
1309 fprintf(f_errorlog, "error: INVALID_ERROR_CODE\n");
1310 break;
1314 fclose(f_errorlog);
1316 } // end of the function
1319 // Set_Variable
1320 // - set one of the variables
1321 // based on the incoming buffer
1323 void Set_Variable(int id, char *val, int f_flag)
1325 float f_val=0;
1326 int i_val=0;
1328 if (id < 0)
1329 return; // no negatives
1332 // also go ahead and set the error
1333 // should probably set below
1334 // but that would take more effort
1335 config_errors[id] = false;
1337 if (f_flag)
1338 f_val = atof(val);
1339 else
1340 i_val = atoi(val);
1342 switch(id)
1344 case ID_LINE_OF_SIGHT:
1346 if (f_flag)
1347 LINE_OF_SIGHT = f_val;
1348 else
1349 LINE_OF_SIGHT = i_val;
1350 break;
1352 case ID_ATTACK_RADIUS:
1353 if (f_flag)
1354 ATTACK_RADIUS = f_val;
1355 else
1356 ATTACK_RADIUS = i_val;
1357 break;
1359 case ID_BULLET_DAMAGE:
1360 if (f_flag)
1361 BULLET_DAMAGE = f_val;
1362 else
1363 BULLET_DAMAGE = i_val;
1364 break;
1366 case ID_MIN_BULLET_SPEED:
1367 if (f_flag)
1368 MIN_BULLET_SPEED = f_val;
1369 else
1370 MIN_BULLET_SPEED = i_val;
1371 break;
1373 case ID_USE_ANT_ENGINE:
1374 if (f_flag)
1375 USE_ANT_ENGINE = f_val;
1376 else
1377 USE_ANT_ENGINE = i_val;
1378 break;
1380 case ID_MAX_FIRE_ANTS:
1381 if (f_flag)
1382 MAX_FIRE_ANTS= f_val;
1383 else
1384 MAX_FIRE_ANTS = i_val;
1386 break;
1388 case ID_MAX_BOTS:
1389 if (f_flag)
1390 MAX_BOTS = f_val;
1391 else
1392 MAX_BOTS = i_val;
1393 break;
1395 case ID_USE_GARDEN_AREA:
1396 if (f_flag)
1397 USE_GARDEN_AREA = f_val;
1398 else
1399 USE_GARDEN_AREA = i_val;
1400 break;
1402 case ID_MAX_TRAIL_STACK:
1403 if (f_flag)
1404 MAX_TRAIL_STACK = f_val;
1405 else
1406 MAX_TRAIL_STACK = i_val;
1407 break;
1409 case ID_DYING_STATE:
1410 if (f_flag)
1411 DYING_STATE = f_val;
1412 else
1413 DYING_STATE = i_val;
1414 break;
1416 case ID_MAX_PHEROMONES:
1417 if (f_flag)
1418 MAX_PHEROMONES = f_val;
1419 else
1420 MAX_PHEROMONES = i_val;
1421 break;
1423 case ID_PHEROMONE_LIFE:
1424 if (f_flag)
1425 PHEROMONE_LIFE = f_val;
1426 else
1427 PHEROMONE_LIFE = i_val;
1428 break;
1430 case ID_PHEROMONE_DROP:
1431 if (f_flag)
1432 PHEROMONE_DROP = f_val;
1433 else
1434 PHEROMONE_DROP = i_val;
1435 break;
1437 case ID_MAX_BULLETS:
1438 if (f_flag)
1439 MAX_BULLETS = f_val;
1440 else
1441 MAX_BULLETS = i_val;
1442 break;
1444 case ID_MAX_FIRE_SPEED:
1445 if (f_flag)
1446 MAX_FIRE_SPEED = f_val;
1447 else
1448 MAX_FIRE_SPEED = i_val;
1449 break;
1451 case ID_MAX_GARDENS:
1452 if (f_flag)
1453 MAX_GARDENS = f_val;
1454 else
1455 MAX_GARDENS = i_val;
1456 break;
1458 case ID_BOT_SPEED:
1459 if (f_flag)
1460 BOT_SPEED = f_val;
1461 else
1462 BOT_SPEED = i_val;
1463 break;
1465 case ID_BOT_MAX_SPEED:
1466 if (f_flag)
1467 BOT_MAX_SPEED = f_val;
1468 else
1469 BOT_MAX_SPEED = i_val;
1470 break;
1472 case ID_MIN_TURN_SPEED:
1473 if (f_flag)
1474 MIN_TURN_SPEED= f_val;
1475 else
1476 MIN_TURN_SPEED = i_val;
1477 break;
1479 case ID_CHECK_RESPAWN:
1480 if (f_flag)
1481 CHECK_RESPAWN = f_val;
1482 else
1483 CHECK_RESPAWN = i_val;
1484 break;
1486 case ID_GARD_RESPAWN_RATE:
1488 if (f_flag)
1489 GARD_RESPAWN_RATE = f_val;
1490 else
1491 GARD_RESPAWN_RATE = i_val;
1492 break;
1494 case ID_MIN_STRAIGHT_STEPS:
1495 if (f_flag)
1496 MIN_STRAIGHT_STEPS = f_val;
1497 else
1498 MIN_STRAIGHT_STEPS = i_val;
1499 break;
1501 case ID_MAX_STRAIGHT_STEPS:
1502 if (f_flag)
1503 MAX_STRAIGHT_STEPS = f_val;
1504 else
1505 MAX_STRAIGHT_STEPS = i_val;
1506 break;
1508 case ID_MIN_STRAIGHT_STEPS_2:
1509 if (f_flag)
1510 MIN_STRAIGHT_STEPS_2 = f_val;
1511 else
1512 MIN_STRAIGHT_STEPS_2 = i_val;
1513 break;
1515 case ID_MAX_STRAIGHT_STEPS_2:
1516 if (f_flag)
1517 MAX_STRAIGHT_STEPS_2 = f_val;
1518 else
1519 MAX_STRAIGHT_STEPS_2 = i_val;
1520 break;
1522 case ID_INITIAL_ANT_FOOD:
1523 if (f_flag)
1524 INITIAL_ANT_FOOD = f_val;
1525 else
1526 INITIAL_ANT_FOOD = i_val;
1527 break;
1529 case ID_INITIAL_GARD_FOOD:
1530 if (f_flag)
1531 INITIAL_GARD_FOOD = f_val;
1532 else
1533 INITIAL_GARD_FOOD = i_val;
1534 break;
1536 case ID_FOOD_WIDTH:
1537 if (f_flag)
1538 FOOD_WIDTH = f_val;
1539 else
1540 FOOD_WIDTH = i_val;
1541 break;
1543 case ID_INIT_FOOD_RATE:
1544 if (f_flag)
1545 INIT_FOOD_RATE = f_val;
1546 else
1547 INIT_FOOD_RATE = i_val;
1548 break;
1550 case ID_MAX_FOOD_RATE:
1551 if (f_flag)
1552 MAX_FOOD_RATE = f_val;
1553 else
1554 MAX_FOOD_RATE = i_val;
1555 break;
1557 case ID_MOVE_FOOD_RATE:
1558 if (f_flag)
1559 MOVE_FOOD_RATE = f_val;
1560 else
1561 MOVE_FOOD_RATE = i_val;
1562 break;
1564 case ID_FOOD_RATE:
1565 if (f_flag)
1566 FOOD_RATE = f_val;
1567 else
1568 FOOD_RATE = i_val;
1569 break;
1571 default:
1572 break;
1577 } // end of the function
1581 #define V_TRUE *f_flag=1
1584 // Get ConfValue
1585 // Note: this file allocates memory
1587 void *Get_ConfValue(int id, int *f_flag)
1589 float *f_val = NULL;
1590 int *i_val = NULL;
1592 if (id < 0)
1593 return NULL; // no negatives
1596 switch(id)
1598 case ID_LINE_OF_SIGHT:
1599 f_val = (float *)malloc(sizeof(float));
1600 *f_val = D_LINE_OF_SIGHT;
1602 V_TRUE;
1603 return f_val;
1604 break;
1606 case ID_ATTACK_RADIUS:
1607 f_val = (float *)malloc(sizeof(float));
1608 *f_val = D_ATTACK_RADIUS;
1610 V_TRUE;
1611 return f_val;
1612 break;
1614 case ID_BULLET_DAMAGE:
1615 f_val = (float *)malloc(sizeof(float));
1616 *f_val = D_BULLET_DAMAGE;
1618 V_TRUE;
1619 return f_val;
1620 break;
1622 case ID_MIN_BULLET_SPEED:
1623 f_val = (float *)malloc(sizeof(float));
1624 *f_val = D_MIN_BULLET_SPEED;
1626 V_TRUE;
1627 return f_val;
1628 break;
1630 case ID_USE_ANT_ENGINE:
1631 i_val = (int *)malloc(sizeof(int));
1632 *i_val = D_USE_ANT_ENGINE;
1633 return i_val;
1634 break;
1636 case ID_MAX_FIRE_ANTS:
1637 i_val = (int *)malloc(sizeof(int));
1639 *i_val = D_MAX_FIRE_ANTS;
1641 return i_val;
1642 break;
1644 case ID_MAX_BOTS:
1645 i_val = (int *)malloc(sizeof(int));
1646 *i_val = D_MAX_BOTS;
1648 return i_val;
1649 break;
1651 case ID_USE_GARDEN_AREA:
1652 i_val = (int *)malloc(sizeof(int));
1653 *i_val = D_USE_GARDEN_AREA;
1654 return i_val;
1655 break;
1657 case ID_MAX_TRAIL_STACK:
1659 i_val = (int *)malloc(sizeof(int));
1660 *i_val = D_MAX_TRAIL_STACK;
1662 return i_val;
1664 break;
1666 case ID_DYING_STATE:
1668 i_val = (int *)malloc(sizeof(int));
1669 *i_val = D_DYING_STATE;
1670 return i_val;
1671 break;
1673 case ID_MAX_PHEROMONES:
1674 i_val = (int *)malloc(sizeof(int));
1675 *i_val = D_MAX_PHEROMONES;
1677 return i_val;
1678 break;
1680 case ID_PHEROMONE_LIFE:
1682 i_val = (int *)malloc(sizeof(int));
1683 *i_val = D_PHEROMONE_LIFE;
1685 return i_val;
1686 break;
1688 case ID_PHEROMONE_DROP:
1689 i_val = (int *)malloc(sizeof(int));
1690 *i_val = D_PHEROMONE_DROP;
1692 return i_val;
1693 break;
1695 case ID_MAX_BULLETS:
1696 i_val = (int *)malloc(sizeof(int));
1697 *i_val = D_MAX_BULLETS;
1699 return i_val;
1700 break;
1702 case ID_MAX_FIRE_SPEED:
1703 i_val = (int *)malloc(sizeof(int));
1704 *i_val = D_MAX_FIRE_SPEED;
1706 return i_val;
1708 break;
1710 case ID_MAX_GARDENS:
1712 i_val = (int *)malloc(sizeof(int));
1713 *i_val = D_MAX_GARDENS;
1715 return i_val;
1717 break;
1719 case ID_BOT_SPEED:
1720 f_val = (float *)malloc(sizeof(float));
1721 *f_val = D_BOT_SPEED;
1723 V_TRUE;
1724 return f_val;
1725 break;
1727 case ID_BOT_MAX_SPEED:
1729 f_val = (float *)malloc(sizeof(float));
1730 *f_val = D_BOT_MAX_SPEED;
1732 V_TRUE;
1734 return f_val;
1736 break;
1738 case ID_MIN_TURN_SPEED:
1740 f_val = (float *)malloc(sizeof(float));
1741 *f_val = D_MIN_TURN_SPEED;
1743 V_TRUE;
1745 return f_val;
1746 break;
1748 case ID_CHECK_RESPAWN:
1749 i_val = (int *)malloc(sizeof(int));
1750 *i_val = D_CHECK_RESPAWN;
1752 return i_val;
1753 break;
1755 case ID_GARD_RESPAWN_RATE:
1757 i_val = (int *)malloc(sizeof(int));
1758 *i_val = D_GARD_RESPAWN_RATE;
1760 return i_val;
1762 break;
1764 case ID_MIN_STRAIGHT_STEPS:
1766 i_val = (int *)malloc(sizeof(int));
1767 *i_val = D_MIN_STRAIGHT_STEPS;
1769 return i_val;
1771 break;
1773 case ID_MAX_STRAIGHT_STEPS:
1775 i_val = (int *)malloc(sizeof(int));
1776 *i_val = D_MAX_STRAIGHT_STEPS;
1778 return i_val;
1779 break;
1782 case ID_MIN_STRAIGHT_STEPS_2:
1783 i_val = (int *)malloc(sizeof(int));
1784 *i_val = D_MIN_STRAIGHT_STEPS_2;
1787 return i_val;
1789 break;
1791 case ID_MAX_STRAIGHT_STEPS_2:
1793 i_val = (int *)malloc(sizeof(int));
1794 *i_val = D_MAX_STRAIGHT_STEPS_2;
1796 return i_val;
1797 break;
1799 case ID_INITIAL_ANT_FOOD:
1801 i_val = (int *)malloc(sizeof(int));
1802 *i_val = D_INITIAL_ANT_FOOD;
1804 return i_val;
1805 break;
1807 case ID_INITIAL_GARD_FOOD:
1809 i_val = (int *)malloc(sizeof(int));
1810 *i_val = D_INITIAL_GARD_FOOD;
1812 return i_val;
1813 break;
1815 case ID_FOOD_WIDTH:
1816 f_val = (float *)malloc(sizeof(float));
1817 *f_val = D_FOOD_WIDTH;
1819 V_TRUE;
1821 return f_val;
1822 break;
1824 case ID_INIT_FOOD_RATE:
1825 i_val = (int *)malloc(sizeof(int));
1826 *i_val = D_INIT_FOOD_RATE;
1827 return i_val;
1828 break;
1830 case ID_MAX_FOOD_RATE:
1832 i_val = (int *)malloc(sizeof(int));
1833 *i_val = D_MAX_FOOD_RATE;
1834 return i_val;
1835 break;
1837 case ID_MOVE_FOOD_RATE:
1838 f_val = (float *)malloc(sizeof(float));
1839 *f_val = D_MOVE_FOOD_RATE;
1841 V_TRUE;
1843 return f_val;
1844 break;
1846 case ID_FOOD_RATE:
1848 f_val = (float *)malloc(sizeof(float));
1850 *f_val = D_FOOD_RATE;
1852 V_TRUE;
1854 return f_val;
1855 break;
1857 default:
1858 break;
1862 return NULL;
1864 } // end of the function
1873 // RESET_VALUE
1874 // - if the config file is messed up
1875 // set the appropriate variable
1877 void Reset_Value(int id)
1879 if (id < 0)
1880 return; // no negatives
1882 switch(id)
1884 case ID_LINE_OF_SIGHT:
1886 LINE_OF_SIGHT = D_LINE_OF_SIGHT;
1887 break;
1889 case ID_ATTACK_RADIUS:
1890 ATTACK_RADIUS = D_ATTACK_RADIUS;
1891 break;
1893 case ID_BULLET_DAMAGE:
1894 BULLET_DAMAGE = D_BULLET_DAMAGE;
1895 break;
1897 case ID_MIN_BULLET_SPEED:
1898 MIN_BULLET_SPEED = D_MIN_BULLET_SPEED;
1899 break;
1901 case ID_USE_ANT_ENGINE:
1902 USE_ANT_ENGINE = D_USE_ANT_ENGINE;
1903 break;
1905 case ID_MAX_FIRE_ANTS:
1907 MAX_FIRE_ANTS = D_MAX_FIRE_ANTS;
1908 break;
1910 case ID_MAX_BOTS:
1912 MAX_BOTS = D_MAX_BOTS;
1914 break;
1916 case ID_USE_GARDEN_AREA:
1918 USE_GARDEN_AREA = D_USE_GARDEN_AREA;
1919 break;
1921 case ID_MAX_TRAIL_STACK:
1922 MAX_TRAIL_STACK = D_MAX_TRAIL_STACK;
1924 break;
1926 case ID_DYING_STATE:
1928 DYING_STATE = D_DYING_STATE;
1929 break;
1931 case ID_MAX_PHEROMONES:
1933 MAX_PHEROMONES = D_MAX_PHEROMONES;
1934 break;
1936 case ID_PHEROMONE_LIFE:
1938 PHEROMONE_LIFE = D_PHEROMONE_LIFE;
1940 break;
1942 case ID_PHEROMONE_DROP:
1944 PHEROMONE_DROP = D_PHEROMONE_DROP;
1945 break;
1947 case ID_MAX_BULLETS:
1948 MAX_BULLETS = D_MAX_BULLETS;
1949 break;
1951 case ID_MAX_FIRE_SPEED:
1952 MAX_FIRE_SPEED = D_MAX_FIRE_SPEED;
1954 break;
1956 case ID_MAX_GARDENS:
1958 MAX_GARDENS = D_MAX_GARDENS;
1960 break;
1962 case ID_BOT_SPEED:
1964 BOT_SPEED = D_BOT_SPEED;
1965 break;
1967 case ID_BOT_MAX_SPEED:
1969 BOT_MAX_SPEED = D_BOT_MAX_SPEED;
1971 break;
1973 case ID_MIN_TURN_SPEED:
1975 MIN_TURN_SPEED = D_MIN_TURN_SPEED;
1977 break;
1979 case ID_CHECK_RESPAWN:
1981 CHECK_RESPAWN = D_CHECK_RESPAWN;
1982 break;
1984 case ID_GARD_RESPAWN_RATE:
1986 GARD_RESPAWN_RATE = D_GARD_RESPAWN_RATE;
1988 break;
1990 case ID_MIN_STRAIGHT_STEPS:
1992 MIN_STRAIGHT_STEPS = D_MIN_STRAIGHT_STEPS;
1994 break;
1996 case ID_MAX_STRAIGHT_STEPS:
1998 MAX_STRAIGHT_STEPS = D_MAX_STRAIGHT_STEPS;
1999 break;
2001 case ID_MIN_STRAIGHT_STEPS_2:
2003 break;
2005 case ID_MAX_STRAIGHT_STEPS_2:
2007 MAX_STRAIGHT_STEPS_2 = D_MAX_STRAIGHT_STEPS_2;
2008 break;
2010 case ID_INITIAL_ANT_FOOD:
2012 INITIAL_ANT_FOOD = D_INITIAL_ANT_FOOD;
2013 break;
2015 case ID_INITIAL_GARD_FOOD:
2017 INITIAL_GARD_FOOD = D_INITIAL_GARD_FOOD;
2019 break;
2021 case ID_FOOD_WIDTH:
2022 FOOD_WIDTH = D_FOOD_WIDTH;
2023 break;
2025 case ID_INIT_FOOD_RATE:
2027 INIT_FOOD_RATE = D_INIT_FOOD_RATE;
2028 break;
2030 case ID_MAX_FOOD_RATE:
2032 MAX_FOOD_RATE = D_MAX_FOOD_RATE;
2033 break;
2035 case ID_MOVE_FOOD_RATE:
2036 MOVE_FOOD_RATE = D_MOVE_FOOD_RATE;
2037 break;
2039 case ID_FOOD_RATE:
2041 FOOD_RATE = D_FOOD_RATE;
2043 break;
2045 default:
2046 break;
2051 } // end of the function
2057 // Process_ConfigFile
2059 int Process_ConfigFile(char *buffer)
2061 int i;
2062 int res;
2064 // not case sensitive
2066 for (i = 0; i < MAX_ERRORS; i++)
2068 res = strcasecmp(buffer, error_str[i]);
2070 if (res == 0)
2072 return i;
2073 } // end of the if
2075 } // end of the for
2077 return -1;
2079 } // end of the function
2082 // void Read_ConfigFile
2083 // -
2085 // if the error tally comes up
2086 // with any errors it will have
2087 // to create a default variable, sorry
2089 void Read_ConfigFile(FILE *f)
2091 char c;
2093 char buffer[256];
2094 int c_index = 0;
2095 int res=0;
2096 char var[80];
2097 int float_flag = 0;
2099 int lines_read = 0;
2101 while (!feof(f))
2104 c = fgetc(f);
2106 switch(c)
2109 case '#':
2111 while(1) {
2112 c = fgetc(f);
2114 if (c == '\n')
2115 break;
2117 } // end of the while
2119 break;
2122 case '[':
2124 c_index = 0;
2126 while(1)
2128 c = fgetc(f);
2130 if (c == ']')
2131 break;
2133 buffer[c_index] = c;
2134 c_index++;
2136 if (c == '\n') {
2137 lines_read++;
2138 break;
2139 } // end of if
2141 } // end of the while
2143 // null terminate the command
2144 buffer[c_index]='\0';
2147 res = Process_ConfigFile(buffer);
2149 // now add the variable with the value
2151 c = fgetc(f);
2153 // get the equals
2154 c_index = 0;
2155 float_flag = 0;
2157 while(1)
2159 c = fgetc(f);
2161 // we found a float
2162 if (c == 'f') {
2163 float_flag = 1;
2164 break;
2165 } // end of the if
2167 // break on a ';'
2168 if (c == ';')
2169 break;
2171 var[c_index] = c;
2172 c_index++;
2174 if (c == '\n')
2175 break;
2177 } // end of the while
2179 var[c_index] = '\0';
2182 // the final step, send in a
2183 // variable
2184 Set_Variable(res,var,float_flag);
2186 break;
2188 default:break;
2190 }; // end switch
2192 } // end of the while
2194 } // end of the function
2198 // Rewrite File
2200 // if the file doesnt exist
2202 void Rewrite_File(void)
2204 int i =0;
2205 int f_flag = 0;
2207 // who needs types
2208 void *tmp = NULL;
2209 float *tmp_f = NULL;
2210 int *tmp_i = NULL;
2212 f_newfile = fopen(CONFIG_FILE_NAME, "w");
2215 for (i = 0; i < MAX_TXT_MSGS; i++)
2217 fprintf(f_newfile, "%s", text_msg[i]);
2218 } // end of the for
2222 for (i = 0; i < MAX_ERRORS; i++)
2224 if (i == 0)
2225 continue;
2227 fprintf(f_newfile, "[");
2228 fprintf(f_newfile, "%s", error_str[i]);
2229 fprintf(f_newfile, "]=");
2231 f_flag = 0;
2233 tmp = Get_ConfValue(i, &f_flag);
2235 if (f_flag) {
2236 tmp_f = (float *)tmp;
2237 fprintf(f_newfile,"%0.2ff;\n", *tmp_f);
2238 } else{
2239 tmp_i = (int *)tmp;
2240 fprintf(f_newfile,"%d;\n",*tmp_i);
2241 } // end of if-else
2245 //free(tmp);
2246 RELEASE_OBJECT(tmp);
2247 tmp = NULL;
2249 } // end of the for
2251 fprintf(f_newfile, "\n\n");
2253 fclose(f_newfile);
2255 } // end of the function
2259 // Check_Errors
2260 // - the config file is messed up somehow
2261 // we need to make sure we have value
2262 // stored for that variable
2264 void Check_Errors(void)
2266 int index = 0;
2268 for (index = 0; index < MAX_ERRORS; index++)
2270 if (index == ID_FILE_NOT_FOUND)
2271 continue;
2273 if (config_errors[index])
2275 // write the file --
2276 Add_ErrorLog(index);
2278 // now get the variable
2279 Reset_Value(index);
2281 } // end of the if
2283 } // end of the for
2285 } // end of the function
2288 // load
2290 void Load_ConfigFile(void)
2293 Set_ErrorLog(); // set up the error log
2295 f_config = fopen(CONFIG_FILE_NAME, "r");
2297 if (f_config == NULL)
2299 Add_ErrorLog(ID_FILE_NOT_FOUND);
2301 // create a new file config.ini
2302 Rewrite_File();
2304 //Read_ConfigFile(f_newfile);
2306 // Note: I left the comment above
2307 // because you may need it later
2308 // right now, the code writes a file
2309 // based on the default values
2310 // then closes the new file
2312 // Another approach might be to write
2313 // the new file and then reread the new
2314 // file and check the variables
2315 // it is really a matter of
2316 // "if there are bugs then check here"
2319 Check_Errors();
2322 return;
2324 } // end of the function
2327 Read_ConfigFile(f_config);
2329 fclose(f_config);
2331 Check_Errors();
2333 } // end of the function