15 #include <GL/gl.h> // Header File For The OpenGL32 Library
16 #include <GL/glu.h> // Header File For The GLu32 Library
21 #include "gldrawlib.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
;
38 bool config_errors
[MAX_ERRORS
];
40 AntGlobals
*ant_globals
;
42 char error_str
[MAX_ERRORS
][40] = {
67 "MIN_STRAIGHT_STEPS_2",
68 "MAX_STRAIGHT_STEPS_2",
82 #define MAX_TXT_MSGS 40
83 char text_msg
[MAX_TXT_MSGS
][80] =
86 "# glAnts - original config.ini\n",
87 "# file, change at your own risk\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",
94 "# Also of note, if the system finds an error\n",
95 "# it goes with the default variable\n",
97 "# FORMAT has to be [VARIABLE_NAME]=VALUE;\n",
98 "# oh yeah, add the 'f' tag for float\n",
100 "# [VARIABLE_NAME]=VALUEf;\n",
102 "# COMMENTS are '#'\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",
109 "# The only things that really need changing\n",
112 "# USE_ANT_ENGINE: take out the little ants \n",
114 "# MAX_FIRE_ANTS: max fighter ants\n",
116 "# MAX_BOTS: number of worker ants\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",
122 "# Also, you may comment one of the variables\n",
123 "# and get the default once the program runs\n",
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
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
170 " (Connect to Server)", // 22
171 " (Disconnect from Server)" , // 23
172 " (Start Server)", // 24
173 " (Shutdown Server)" }; // 25
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
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
;
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
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
263 } // end of the function
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");
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
;
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
320 void Draw_TString(int x
, int y
, char *str
)
322 TextBegin(network_text
);
323 DrawString(network_text
, x
, y
, str
);
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
)
341 // set the text changes before the code below
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
]);
361 vert_pos
= TXT_V_START
;
363 TextBegin(network_text
);
364 DrawString(network_text
, horz_pos
, vert_pos
, network_str_
[C_HORZ_MENU
+1]);
369 vert_pos
= TXT_V_START
;
371 TextBegin(network_text
);
372 DrawString(network_text
, horz_pos
, vert_pos
, network_str_
[C_HORZ_MENU
+2]);
377 vert_pos
= TXT_V_START
;
379 TextBegin(network_text
);
380 DrawString(network_text
, horz_pos
, vert_pos
, network_str_
[C_HORZ_MENU
+3]);
386 vert_pos
= TXT_V_START
;
388 TextBegin(network_text
);
389 DrawString(network_text
, horz_pos
, vert_pos
, network_str_
[C_HORZ_MENU
+4]);
395 vert_pos
= TXT_V_START
;
397 TextBegin(network_text
);
398 DrawString(network_text
, horz_pos
, vert_pos
, network_str_
[C_HORZ_MENU
+5]);
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
]);
412 vert_pos
= TXT_V_STARTYY2
;
414 TextBegin(network_text
);
415 DrawString(network_text
, horz_pos
, vert_pos
, network_str_
[S_SERV_HORZ
+1]);
420 vert_pos
= TXT_V_STARTYY2
;
422 TextBegin(network_text
);
423 DrawString(network_text
, horz_pos
, vert_pos
, network_str_
[S_SERV_HORZ
+2]);
427 vert_pos
= TXT_V_STARTYY2
;
429 TextBegin(network_text
);
430 DrawString(network_text
, horz_pos
, vert_pos
, network_str_
[S_SERV_HORZ
+3]);
433 } // end of the if-else
441 if (start_pos
== CLIENT_NET_MENU
)
442 vert_pos
= TEXT_VERT_START
;
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
]);
452 vert_pos
= vert_pos
+ TEXT_VERT_HEIGHT
;
462 case SERVER_SETTINGS
:
463 TextBegin(network_text
);
464 DrawString(network_text
, start_pos
,
465 end_pos
, network_str_
[SERVER_SETTINGS
]);
471 case CLIENT_SETTINGS
:
472 TextBegin(network_text
);
473 DrawString(network_text
, start_pos
,
474 end_pos
, network_str_
[CLIENT_SETTINGS
]);
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
;
498 glDisable(GL_TEXTURE_2D
);
500 // Draw a blue screen
503 glColor3ub(20, 120, 235);
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
);
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
);
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
);
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_
]);
554 TextBegin(network_text
);
555 DrawString(network_text
, T_COL_7
,
556 T_ROW_1
, network_str_
[_TEXT_DISCONNECT_
]);
560 TextBegin(network_text
);
561 DrawString(network_text
, T_COL_6
,
562 T_ROW_2
, network_str_
[_TEXT_START_
]);
565 TextBegin(network_text
);
566 DrawString(network_text
, T_COL_7
,
567 T_ROW_2
, network_str_
[_TEXT_SHUTDOWN_
]);
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
,
580 // print connections if there are any
583 } // end of the functino
589 void Draw_IntroScreen(void)
592 glDisable(GL_TEXTURE_2D
);
594 // Draw a blue screen
596 glColor3ub(20, 120, 235);
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
);
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
);
623 //DrawText(intro_text);
624 //curr_Time = GetTickCount();
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);
639 if (*(++_tmp_str
) == '\0')
640 _tmp_str
= intro_str
;
644 DrawText(intro_text
);
648 } // end of the function
655 void Draw_HelpScreen(void)
658 glDisable(GL_TEXTURE_2D
);
660 // Draw a blue screen
663 glColor3ub(20, 120, 235);
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
);
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
);
693 } // end of the function
697 // - print the debug text screen
699 void Super_Printf(char* fmt
, ... )
705 va_start(vlist
, fmt
);
706 vsprintf(buff
, fmt
, vlist
);
708 FormatStrCat(main_text
, buff
);
712 } // end of the function
717 void Score_Printf(char* fmt
, ... )
723 va_start(vlist
, fmt
);
724 vsprintf(buff
, fmt
, vlist
);
726 FormatStrCat(score_text
, buff
);
730 } // end of the function
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
746 void Print_Score(void)
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
);
768 // Also, print frames per second
769 sprintf(buffer
, "FPS: %0.2f", framerate
);
770 TextBegin(score_text
);
771 DrawString(score_text
, 500, 4, buffer
);
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
);
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
);
787 // Print some paused text
788 if (ant_globals
->paused
)
791 // find the correct x pos
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
);
804 sprintf(buffer
, "(GLANTS)");
805 TextBegin(score_text
);
806 DrawString(score_text
, x
+8, y
+10, buffer
);
813 } // end of the function
820 void Super_DrawText(void)
826 // Also placing print score
827 // here, for some reason...
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
851 void Super_LoadGlobals(void)
853 ant_globals
= (AntGlobals
*)malloc(sizeof(AntGlobals
));
856 ZeroMemory((AntGlobals
*)ant_globals
,
858 } // end of the function
863 void Super_KillGlobals(void)
865 // free the other allocated
867 //free(ant_globals->score_obj);
870 RELEASE_OBJECT(ant_globals
->score_obj
);
872 RELEASE_OBJECT(ant_globals
);
874 } // end of the function
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
));
900 ZeroMemory(ant_globals
->score_obj
,
901 MAX_FIRE_ANTS
*sizeof(ScoreObj
));
904 } // end of the function
909 void TogglePaused(void)
912 if (ant_globals
->paused
) {
914 ant_globals
->paused
= 0;
917 ant_globals
->paused
= 1;
920 } // end of the ufnctio
925 void DestroyGlobals(void)
928 } // end of the function
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
946 void SubtractAnts(int ants
)
948 if (ant_globals
->alive_ants
<= 0)
950 ant_globals
->alive_ants
= 0;
954 ant_globals
->alive_ants
-= ants
;
956 } // end of the function
961 void AddAnts(int ants
)
964 ant_globals
->alive_ants
+= ants
;
966 } // end of the function
972 return ant_globals
->alive_ants
;
973 } // end of the functino
978 void AddSeconds(float delta
)
980 ant_globals
->seconds
+= delta
;
981 } // end of the function
986 // - time to render each frames
988 void AddTime(float delta
)
990 ant_globals
->time_t = delta
;
991 } // end of the function
996 void SetGardenSize(int v
)
998 ant_globals
->garden
+= v
;
1005 int GetGardenSize(void)
1007 return ant_globals
->garden
;
1013 void SetNestFood(float d
)
1015 ant_globals
->nest_food
= d
;
1017 } // end of function
1022 void SetPlayerHealth(float d
)
1024 ant_globals
->player_health
= d
;
1026 } // end of function
1032 // - number of ticks in the game
1035 ant_globals
->ticks
+= 1;
1037 } // end of the function
1042 DWORD
GetGameTick(void)
1044 return ant_globals
->ticks
;
1045 } // end of the functino
1051 void PrintGlobals(void)
1056 glRasterPos2i(10, 48+14);
1057 PrintText("ANTS: %d", ant_globals
->alive_ants
);
1061 glRasterPos2i(10, 48+28);
1062 PrintText("TIME: %0.1f", ant_globals
->seconds
);
1067 glRasterPos2i(10, 48+42);
1068 PrintText("TIME_T: %0.0f", ant_globals
->time_t);
1072 glRasterPos2i(10, 48+56);
1073 PrintText("FOOD: %0.0f", ant_globals
->nest_food
);
1074 //PrintText("FOOD: %ld", ant_globals.ticks);
1079 glRasterPos2i(10, 48+70);
1080 PrintText("GARD: %d", ant_globals
->garden
);
1081 //PrintText("FOOD: %ld", ant_globals.ticks);
1086 // note: hud_NEST_FOOD must be turned off
1087 glRasterPos2i(10, 48+56);
1088 PrintText("x: %0.2f y: %0.2f", GetBotX(), GetBotY());
1092 glRasterPos2i(10, 48+70);
1093 PrintText("LIFE: %0.2f", ant_globals
->player_health
);
1094 //PrintText("FOOD: %ld", ant_globals.ticks);
1099 for (i
= 0; i
< MAX_SCORE_DISPLAY
; i
++)
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
);
1112 } // end of the function
1115 // CONFIG LOADING FUNCTIONS
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)
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");
1144 } // end of the function
1148 // - add an entry to the error log
1150 void Add_ErrorStr(char *str
)
1154 f_errorlog
= fopen(ERROR_FILE_NAME
, "a");
1156 fprintf(f_errorlog
, "%s\n", str
);
1160 } // end of the functino
1164 // - add an entry to the error log
1166 void Add_ErrorLog(const int error_id
)
1170 f_errorlog
= fopen(ERROR_FILE_NAME
, "a");
1172 config_errors
[error_id
] = true;
1176 case ID_FILE_NOT_FOUND
:
1177 fprintf(f_errorlog
, "error: config FILE_NOT_FOUND\n");
1180 case ID_LINE_OF_SIGHT
:
1181 fprintf(f_errorlog
, "error: LINE_OF_SIGHT\n");
1184 case ID_ATTACK_RADIUS
:
1185 fprintf(f_errorlog
, "error: ATTACK_RADIUS\n");
1188 case ID_BULLET_DAMAGE
:
1189 fprintf(f_errorlog
, "error: BULLET_DAMAGE\n");
1192 case ID_MIN_BULLET_SPEED
:
1193 fprintf(f_errorlog
, "error: MIN_BULLET_SPEED\n");
1196 case ID_USE_ANT_ENGINE
:
1197 fprintf(f_errorlog
, "error: USE_ANT_ENGINE:\n");
1200 case ID_MAX_FIRE_ANTS
:
1201 fprintf(f_errorlog
, "error: MAX_FIRE_ANTS\n");
1205 fprintf(f_errorlog
, "error: MAX_BOTS\n");
1208 case ID_USE_GARDEN_AREA
:
1209 fprintf(f_errorlog
, "error: USE_GARDEN_AREA\n");
1212 case ID_MAX_TRAIL_STACK
:
1213 fprintf(f_errorlog
, "error: MAX_TRAIL_STACK\n");
1216 case ID_DYING_STATE
:
1217 fprintf(f_errorlog
, "error: DYING_STATE\n");
1220 case ID_MAX_PHEROMONES
:
1221 fprintf(f_errorlog
, "error: MAX_PHEROMONES\n");
1224 case ID_PHEROMONE_LIFE
:
1225 fprintf(f_errorlog
, "error: PHEROMONE_LIFE\n");
1228 case ID_PHEROMONE_DROP
:
1229 fprintf(f_errorlog
, "error: PHEROMONE_DROP\n");
1232 case ID_MAX_BULLETS
:
1233 fprintf(f_errorlog
, "error: MAX_BULLETS\n");
1236 case ID_MAX_FIRE_SPEED
:
1237 fprintf(f_errorlog
, "error: MAX_FIRE_SPEED\n");
1240 case ID_MAX_GARDENS
:
1241 fprintf(f_errorlog
, "error: MAX_GARDENS\n");
1245 fprintf(f_errorlog
, "error: BOT_SPEED\n");
1248 case ID_BOT_MAX_SPEED
:
1249 fprintf(f_errorlog
, "error: BOT_MAX_SPEED\n");
1252 case ID_MIN_TURN_SPEED
:
1253 fprintf(f_errorlog
, "error: MIN_TURN_SPEED\n");
1256 case ID_CHECK_RESPAWN
:
1257 fprintf(f_errorlog
, "error: CHECK_RESPAWN\n");
1260 case ID_GARD_RESPAWN_RATE
:
1261 fprintf(f_errorlog
, "error: GARD_RESPAWN_RATE\n");
1264 case ID_MIN_STRAIGHT_STEPS
:
1265 fprintf(f_errorlog
, "error: MIN_STRAIGHT_STEPS\n");
1268 case ID_MAX_STRAIGHT_STEPS
:
1269 fprintf(f_errorlog
, "error: MAX_STRAIGHT_STEPS\n");
1272 case ID_MIN_STRAIGHT_STEPS_2
:
1273 fprintf(f_errorlog
, "error: MIN_STRAIGHT_STEPS_2:\n");
1276 case ID_MAX_STRAIGHT_STEPS_2
:
1277 fprintf(f_errorlog
, "error: MAX_STRAIGHT_STEPS_2\n");
1280 case ID_INITIAL_ANT_FOOD
:
1281 fprintf(f_errorlog
, "error: INITIAL_ANT_FOOD\n");
1284 case ID_INITIAL_GARD_FOOD
:
1285 fprintf(f_errorlog
, "error: INITIAL_GARD_FOOD\n");
1289 fprintf(f_errorlog
, "error: FOOD_WIDTH\n");
1292 case ID_INIT_FOOD_RATE
:
1293 fprintf(f_errorlog
, "error: INIT_FOOD_RATE\n");
1296 case ID_MAX_FOOD_RATE
:
1297 fprintf(f_errorlog
, "error: MAX_FOOD_RATE\n");
1300 case ID_MOVE_FOOD_RATE
:
1301 fprintf(f_errorlog
, "error: MOVE_FOOD_RATE\n");
1305 fprintf(f_errorlog
, "error: FOOD_RATE\n");
1309 fprintf(f_errorlog
, "error: INVALID_ERROR_CODE\n");
1316 } // end of the function
1320 // - set one of the variables
1321 // based on the incoming buffer
1323 void Set_Variable(int id
, char *val
, int f_flag
)
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;
1344 case ID_LINE_OF_SIGHT
:
1347 LINE_OF_SIGHT
= f_val
;
1349 LINE_OF_SIGHT
= i_val
;
1352 case ID_ATTACK_RADIUS
:
1354 ATTACK_RADIUS
= f_val
;
1356 ATTACK_RADIUS
= i_val
;
1359 case ID_BULLET_DAMAGE
:
1361 BULLET_DAMAGE
= f_val
;
1363 BULLET_DAMAGE
= i_val
;
1366 case ID_MIN_BULLET_SPEED
:
1368 MIN_BULLET_SPEED
= f_val
;
1370 MIN_BULLET_SPEED
= i_val
;
1373 case ID_USE_ANT_ENGINE
:
1375 USE_ANT_ENGINE
= f_val
;
1377 USE_ANT_ENGINE
= i_val
;
1380 case ID_MAX_FIRE_ANTS
:
1382 MAX_FIRE_ANTS
= f_val
;
1384 MAX_FIRE_ANTS
= i_val
;
1395 case ID_USE_GARDEN_AREA
:
1397 USE_GARDEN_AREA
= f_val
;
1399 USE_GARDEN_AREA
= i_val
;
1402 case ID_MAX_TRAIL_STACK
:
1404 MAX_TRAIL_STACK
= f_val
;
1406 MAX_TRAIL_STACK
= i_val
;
1409 case ID_DYING_STATE
:
1411 DYING_STATE
= f_val
;
1413 DYING_STATE
= i_val
;
1416 case ID_MAX_PHEROMONES
:
1418 MAX_PHEROMONES
= f_val
;
1420 MAX_PHEROMONES
= i_val
;
1423 case ID_PHEROMONE_LIFE
:
1425 PHEROMONE_LIFE
= f_val
;
1427 PHEROMONE_LIFE
= i_val
;
1430 case ID_PHEROMONE_DROP
:
1432 PHEROMONE_DROP
= f_val
;
1434 PHEROMONE_DROP
= i_val
;
1437 case ID_MAX_BULLETS
:
1439 MAX_BULLETS
= f_val
;
1441 MAX_BULLETS
= i_val
;
1444 case ID_MAX_FIRE_SPEED
:
1446 MAX_FIRE_SPEED
= f_val
;
1448 MAX_FIRE_SPEED
= i_val
;
1451 case ID_MAX_GARDENS
:
1453 MAX_GARDENS
= f_val
;
1455 MAX_GARDENS
= i_val
;
1465 case ID_BOT_MAX_SPEED
:
1467 BOT_MAX_SPEED
= f_val
;
1469 BOT_MAX_SPEED
= i_val
;
1472 case ID_MIN_TURN_SPEED
:
1474 MIN_TURN_SPEED
= f_val
;
1476 MIN_TURN_SPEED
= i_val
;
1479 case ID_CHECK_RESPAWN
:
1481 CHECK_RESPAWN
= f_val
;
1483 CHECK_RESPAWN
= i_val
;
1486 case ID_GARD_RESPAWN_RATE
:
1489 GARD_RESPAWN_RATE
= f_val
;
1491 GARD_RESPAWN_RATE
= i_val
;
1494 case ID_MIN_STRAIGHT_STEPS
:
1496 MIN_STRAIGHT_STEPS
= f_val
;
1498 MIN_STRAIGHT_STEPS
= i_val
;
1501 case ID_MAX_STRAIGHT_STEPS
:
1503 MAX_STRAIGHT_STEPS
= f_val
;
1505 MAX_STRAIGHT_STEPS
= i_val
;
1508 case ID_MIN_STRAIGHT_STEPS_2
:
1510 MIN_STRAIGHT_STEPS_2
= f_val
;
1512 MIN_STRAIGHT_STEPS_2
= i_val
;
1515 case ID_MAX_STRAIGHT_STEPS_2
:
1517 MAX_STRAIGHT_STEPS_2
= f_val
;
1519 MAX_STRAIGHT_STEPS_2
= i_val
;
1522 case ID_INITIAL_ANT_FOOD
:
1524 INITIAL_ANT_FOOD
= f_val
;
1526 INITIAL_ANT_FOOD
= i_val
;
1529 case ID_INITIAL_GARD_FOOD
:
1531 INITIAL_GARD_FOOD
= f_val
;
1533 INITIAL_GARD_FOOD
= i_val
;
1543 case ID_INIT_FOOD_RATE
:
1545 INIT_FOOD_RATE
= f_val
;
1547 INIT_FOOD_RATE
= i_val
;
1550 case ID_MAX_FOOD_RATE
:
1552 MAX_FOOD_RATE
= f_val
;
1554 MAX_FOOD_RATE
= i_val
;
1557 case ID_MOVE_FOOD_RATE
:
1559 MOVE_FOOD_RATE
= f_val
;
1561 MOVE_FOOD_RATE
= i_val
;
1577 } // end of the function
1581 #define V_TRUE *f_flag=1
1585 // Note: this file allocates memory
1587 void *Get_ConfValue(int id
, int *f_flag
)
1589 float *f_val
= NULL
;
1593 return NULL
; // no negatives
1598 case ID_LINE_OF_SIGHT
:
1599 f_val
= (float *)malloc(sizeof(float));
1600 *f_val
= D_LINE_OF_SIGHT
;
1606 case ID_ATTACK_RADIUS
:
1607 f_val
= (float *)malloc(sizeof(float));
1608 *f_val
= D_ATTACK_RADIUS
;
1614 case ID_BULLET_DAMAGE
:
1615 f_val
= (float *)malloc(sizeof(float));
1616 *f_val
= D_BULLET_DAMAGE
;
1622 case ID_MIN_BULLET_SPEED
:
1623 f_val
= (float *)malloc(sizeof(float));
1624 *f_val
= D_MIN_BULLET_SPEED
;
1630 case ID_USE_ANT_ENGINE
:
1631 i_val
= (int *)malloc(sizeof(int));
1632 *i_val
= D_USE_ANT_ENGINE
;
1636 case ID_MAX_FIRE_ANTS
:
1637 i_val
= (int *)malloc(sizeof(int));
1639 *i_val
= D_MAX_FIRE_ANTS
;
1645 i_val
= (int *)malloc(sizeof(int));
1646 *i_val
= D_MAX_BOTS
;
1651 case ID_USE_GARDEN_AREA
:
1652 i_val
= (int *)malloc(sizeof(int));
1653 *i_val
= D_USE_GARDEN_AREA
;
1657 case ID_MAX_TRAIL_STACK
:
1659 i_val
= (int *)malloc(sizeof(int));
1660 *i_val
= D_MAX_TRAIL_STACK
;
1666 case ID_DYING_STATE
:
1668 i_val
= (int *)malloc(sizeof(int));
1669 *i_val
= D_DYING_STATE
;
1673 case ID_MAX_PHEROMONES
:
1674 i_val
= (int *)malloc(sizeof(int));
1675 *i_val
= D_MAX_PHEROMONES
;
1680 case ID_PHEROMONE_LIFE
:
1682 i_val
= (int *)malloc(sizeof(int));
1683 *i_val
= D_PHEROMONE_LIFE
;
1688 case ID_PHEROMONE_DROP
:
1689 i_val
= (int *)malloc(sizeof(int));
1690 *i_val
= D_PHEROMONE_DROP
;
1695 case ID_MAX_BULLETS
:
1696 i_val
= (int *)malloc(sizeof(int));
1697 *i_val
= D_MAX_BULLETS
;
1702 case ID_MAX_FIRE_SPEED
:
1703 i_val
= (int *)malloc(sizeof(int));
1704 *i_val
= D_MAX_FIRE_SPEED
;
1710 case ID_MAX_GARDENS
:
1712 i_val
= (int *)malloc(sizeof(int));
1713 *i_val
= D_MAX_GARDENS
;
1720 f_val
= (float *)malloc(sizeof(float));
1721 *f_val
= D_BOT_SPEED
;
1727 case ID_BOT_MAX_SPEED
:
1729 f_val
= (float *)malloc(sizeof(float));
1730 *f_val
= D_BOT_MAX_SPEED
;
1738 case ID_MIN_TURN_SPEED
:
1740 f_val
= (float *)malloc(sizeof(float));
1741 *f_val
= D_MIN_TURN_SPEED
;
1748 case ID_CHECK_RESPAWN
:
1749 i_val
= (int *)malloc(sizeof(int));
1750 *i_val
= D_CHECK_RESPAWN
;
1755 case ID_GARD_RESPAWN_RATE
:
1757 i_val
= (int *)malloc(sizeof(int));
1758 *i_val
= D_GARD_RESPAWN_RATE
;
1764 case ID_MIN_STRAIGHT_STEPS
:
1766 i_val
= (int *)malloc(sizeof(int));
1767 *i_val
= D_MIN_STRAIGHT_STEPS
;
1773 case ID_MAX_STRAIGHT_STEPS
:
1775 i_val
= (int *)malloc(sizeof(int));
1776 *i_val
= D_MAX_STRAIGHT_STEPS
;
1782 case ID_MIN_STRAIGHT_STEPS_2
:
1783 i_val
= (int *)malloc(sizeof(int));
1784 *i_val
= D_MIN_STRAIGHT_STEPS_2
;
1791 case ID_MAX_STRAIGHT_STEPS_2
:
1793 i_val
= (int *)malloc(sizeof(int));
1794 *i_val
= D_MAX_STRAIGHT_STEPS_2
;
1799 case ID_INITIAL_ANT_FOOD
:
1801 i_val
= (int *)malloc(sizeof(int));
1802 *i_val
= D_INITIAL_ANT_FOOD
;
1807 case ID_INITIAL_GARD_FOOD
:
1809 i_val
= (int *)malloc(sizeof(int));
1810 *i_val
= D_INITIAL_GARD_FOOD
;
1816 f_val
= (float *)malloc(sizeof(float));
1817 *f_val
= D_FOOD_WIDTH
;
1824 case ID_INIT_FOOD_RATE
:
1825 i_val
= (int *)malloc(sizeof(int));
1826 *i_val
= D_INIT_FOOD_RATE
;
1830 case ID_MAX_FOOD_RATE
:
1832 i_val
= (int *)malloc(sizeof(int));
1833 *i_val
= D_MAX_FOOD_RATE
;
1837 case ID_MOVE_FOOD_RATE
:
1838 f_val
= (float *)malloc(sizeof(float));
1839 *f_val
= D_MOVE_FOOD_RATE
;
1848 f_val
= (float *)malloc(sizeof(float));
1850 *f_val
= D_FOOD_RATE
;
1864 } // end of the function
1874 // - if the config file is messed up
1875 // set the appropriate variable
1877 void Reset_Value(int id
)
1880 return; // no negatives
1884 case ID_LINE_OF_SIGHT
:
1886 LINE_OF_SIGHT
= D_LINE_OF_SIGHT
;
1889 case ID_ATTACK_RADIUS
:
1890 ATTACK_RADIUS
= D_ATTACK_RADIUS
;
1893 case ID_BULLET_DAMAGE
:
1894 BULLET_DAMAGE
= D_BULLET_DAMAGE
;
1897 case ID_MIN_BULLET_SPEED
:
1898 MIN_BULLET_SPEED
= D_MIN_BULLET_SPEED
;
1901 case ID_USE_ANT_ENGINE
:
1902 USE_ANT_ENGINE
= D_USE_ANT_ENGINE
;
1905 case ID_MAX_FIRE_ANTS
:
1907 MAX_FIRE_ANTS
= D_MAX_FIRE_ANTS
;
1912 MAX_BOTS
= D_MAX_BOTS
;
1916 case ID_USE_GARDEN_AREA
:
1918 USE_GARDEN_AREA
= D_USE_GARDEN_AREA
;
1921 case ID_MAX_TRAIL_STACK
:
1922 MAX_TRAIL_STACK
= D_MAX_TRAIL_STACK
;
1926 case ID_DYING_STATE
:
1928 DYING_STATE
= D_DYING_STATE
;
1931 case ID_MAX_PHEROMONES
:
1933 MAX_PHEROMONES
= D_MAX_PHEROMONES
;
1936 case ID_PHEROMONE_LIFE
:
1938 PHEROMONE_LIFE
= D_PHEROMONE_LIFE
;
1942 case ID_PHEROMONE_DROP
:
1944 PHEROMONE_DROP
= D_PHEROMONE_DROP
;
1947 case ID_MAX_BULLETS
:
1948 MAX_BULLETS
= D_MAX_BULLETS
;
1951 case ID_MAX_FIRE_SPEED
:
1952 MAX_FIRE_SPEED
= D_MAX_FIRE_SPEED
;
1956 case ID_MAX_GARDENS
:
1958 MAX_GARDENS
= D_MAX_GARDENS
;
1964 BOT_SPEED
= D_BOT_SPEED
;
1967 case ID_BOT_MAX_SPEED
:
1969 BOT_MAX_SPEED
= D_BOT_MAX_SPEED
;
1973 case ID_MIN_TURN_SPEED
:
1975 MIN_TURN_SPEED
= D_MIN_TURN_SPEED
;
1979 case ID_CHECK_RESPAWN
:
1981 CHECK_RESPAWN
= D_CHECK_RESPAWN
;
1984 case ID_GARD_RESPAWN_RATE
:
1986 GARD_RESPAWN_RATE
= D_GARD_RESPAWN_RATE
;
1990 case ID_MIN_STRAIGHT_STEPS
:
1992 MIN_STRAIGHT_STEPS
= D_MIN_STRAIGHT_STEPS
;
1996 case ID_MAX_STRAIGHT_STEPS
:
1998 MAX_STRAIGHT_STEPS
= D_MAX_STRAIGHT_STEPS
;
2001 case ID_MIN_STRAIGHT_STEPS_2
:
2005 case ID_MAX_STRAIGHT_STEPS_2
:
2007 MAX_STRAIGHT_STEPS_2
= D_MAX_STRAIGHT_STEPS_2
;
2010 case ID_INITIAL_ANT_FOOD
:
2012 INITIAL_ANT_FOOD
= D_INITIAL_ANT_FOOD
;
2015 case ID_INITIAL_GARD_FOOD
:
2017 INITIAL_GARD_FOOD
= D_INITIAL_GARD_FOOD
;
2022 FOOD_WIDTH
= D_FOOD_WIDTH
;
2025 case ID_INIT_FOOD_RATE
:
2027 INIT_FOOD_RATE
= D_INIT_FOOD_RATE
;
2030 case ID_MAX_FOOD_RATE
:
2032 MAX_FOOD_RATE
= D_MAX_FOOD_RATE
;
2035 case ID_MOVE_FOOD_RATE
:
2036 MOVE_FOOD_RATE
= D_MOVE_FOOD_RATE
;
2041 FOOD_RATE
= D_FOOD_RATE
;
2051 } // end of the function
2057 // Process_ConfigFile
2059 int Process_ConfigFile(char *buffer
)
2064 // not case sensitive
2066 for (i
= 0; i
< MAX_ERRORS
; i
++)
2068 res
= strcasecmp(buffer
, error_str
[i
]);
2079 } // end of the function
2082 // void Read_ConfigFile
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
)
2117 } // end of the while
2133 buffer
[c_index
] = c
;
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
2177 } // end of the while
2179 var
[c_index
] = '\0';
2182 // the final step, send in a
2184 Set_Variable(res
,var
,float_flag
);
2192 } // end of the while
2194 } // end of the function
2200 // if the file doesnt exist
2202 void Rewrite_File(void)
2209 float *tmp_f
= 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
]);
2222 for (i
= 0; i
< MAX_ERRORS
; i
++)
2227 fprintf(f_newfile
, "[");
2228 fprintf(f_newfile
, "%s", error_str
[i
]);
2229 fprintf(f_newfile
, "]=");
2233 tmp
= Get_ConfValue(i
, &f_flag
);
2236 tmp_f
= (float *)tmp
;
2237 fprintf(f_newfile
,"%0.2ff;\n", *tmp_f
);
2240 fprintf(f_newfile
,"%d;\n",*tmp_i
);
2246 RELEASE_OBJECT(tmp
);
2251 fprintf(f_newfile
, "\n\n");
2255 } // end of the function
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)
2268 for (index
= 0; index
< MAX_ERRORS
; index
++)
2270 if (index
== ID_FILE_NOT_FOUND
)
2273 if (config_errors
[index
])
2275 // write the file --
2276 Add_ErrorLog(index
);
2278 // now get the variable
2285 } // end of the function
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
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"
2324 } // end of the function
2327 Read_ConfigFile(f_config
);
2333 } // end of the function