home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Issue 2 / Freelog_HS_3_Setp_Oct_Nov_2000_CD2.mdx / Arcade / Orbit / src / prefs.c < prev    next >
C/C++ Source or Header  |  1999-09-16  |  6KB  |  158 lines

  1. /*
  2.  
  3. ORBIT, a freeware space combat simulator
  4. Copyright (C) 1999  Steve Belczyk <steve1@genesis.nred.ma.us>
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20. */
  21.  
  22. #include "orbit.h"
  23.  
  24. /*
  25.  *  Read and write the preferences file
  26.  */
  27.  
  28. WritePrefs()
  29. {
  30.     FILE *fd;
  31.  
  32.     Log ("WritePrefs: Writing preferences file");
  33.  
  34.     /* Open it */
  35.     if (NULL == (fd = fopen ("prefs.txt", "wt")))
  36.     {
  37.         Log ("WritePrefs: Can't open prefs.txt");
  38.         return;
  39.     }
  40.  
  41.     /* Write stuff */
  42.     fprintf (fd, "mission %s\n", mission.fn);
  43.     fprintf (fd, "screenwidth %d\n", ScreenWidth);
  44.     fprintf (fd, "screenheight %d\n", ScreenHeight);
  45.     fprintf (fd, "fullscreen %d\n", fullscreen);
  46.     fprintf (fd, "gamemode %s\n", gamemode);
  47.     fprintf (fd, "name %s\n", player.name);
  48.     fprintf (fd, "model %s\n", player.model);
  49.     fprintf (fd, "vulnerable %d\n", vulnerable);
  50.     fprintf (fd, "fov %lf\n", fov);
  51.     fprintf (fd, "joy_throttle %d\n", joy_throttle);
  52.     fprintf (fd, "deadzone %lf\n", deadzone);
  53.     fprintf (fd, "starfield %d\n", starfield);
  54.     fprintf (fd, "drawhud %d\n", drawhud);
  55.     fprintf (fd, "showfps %d\n", showfps);
  56.     fprintf (fd, "gravity %d\n", gravity);
  57.     fprintf (fd, "draw_orbits %d\n", draw_orbits);
  58.     fprintf (fd, "orbit %d\n", orbit);
  59.     fprintf (fd, "compression %lf\n", compression);
  60.     fprintf (fd, "junk %d\n", junk);
  61.     fprintf (fd, "sound %d\n", sound);
  62.     fprintf (fd, "show_names %d\n", show_names);
  63.     fprintf (fd, "screen_shot_num %d\n", screen_shot_num);
  64.     fprintf (fd, "rings %d\n", rings);
  65.     fprintf (fd, "ring_sectors %d\n", ring_sectors);
  66.     fprintf (fd, "textures %d\n", textures);
  67.     fprintf (fd, "realdistances %d\n", realdistances);
  68.     fprintf (fd, "weapon %d\n", player.weapon);
  69.     fprintf (fd, "mouse_control %d\n", mouse_control);
  70.     fprintf (fd, "mouse_flipx %d\n", mouse.flipx);
  71.     fprintf (fd, "mouse_flipy %d\n", mouse.flipy);
  72.     fprintf (fd, "flightmodel %d\n", player.flightmodel);
  73.     fprintf (fd, "fullstop %d\n", fullstop);
  74.     fprintf (fd, "superwarp %d\n", superwarp);
  75.     fprintf (fd, "port %d\n", server.port);
  76.     fprintf (fd, "posx %lf\n", player.pos[0]);
  77.     fprintf (fd, "posy %lf\n", player.pos[1]);
  78.     fprintf (fd, "posz %lf\n", player.pos[2]);
  79.     fprintf (fd, "slices0 %d\n", slices0);
  80.     fprintf (fd, "stacks0 %d\n", stacks0);
  81.     fprintf (fd, "slices1 %d\n", slices1);
  82.     fprintf (fd, "stacks1 %d\n", stacks1);
  83.     fprintf (fd, "slices2 %d\n", slices2);
  84.     fprintf (fd, "stacks2 %d\n", stacks2);
  85.  
  86.     /* Adios */
  87.     fclose (fd);
  88. }
  89.  
  90. ReadPrefs()
  91. {
  92.     FILE *fd;
  93.     char c1[64], c2[64];
  94.  
  95.     /* Open it */
  96.     if (NULL == (fd = fopen ("prefs.txt", "rt"))) return;
  97.  
  98.     Log ("ReadPrefs: Reading preferences file");
  99.         
  100.     /* Read Stuff */
  101.     while (2 == fscanf (fd, "%s %s", c1, c2))
  102.     {
  103.         Log ("ReadPrefs: %s %s", c1, c2);
  104.  
  105.         if (!strcasecmp (c1, "vulnerable")) vulnerable = atoi(c2);
  106.         else if (!strcasecmp (c1, "joy_throttle")) joy_throttle = atoi(c2);
  107.         else if (!strcasecmp (c1, "deadzone")) deadzone = atof(c2);
  108.         else if (!strcasecmp (c1, "starfield")) starfield = atoi(c2);
  109.         else if (!strcasecmp (c1, "drawhud")) drawhud = atoi(c2);
  110.         else if (!strcasecmp (c1, "showfps")) showfps = atoi(c2);
  111.         else if (!strcasecmp (c1, "gravity")) gravity = atoi(c2);
  112.         else if (!strcasecmp (c1, "junk")) junk = atoi(c2);
  113.         else if (!strcasecmp (c1, "sound")) sound = atoi(c2);
  114.         else if (!strcasecmp (c1, "show_names")) show_names = atoi(c2);
  115.         else if (!strcasecmp (c1, "screen_shot_num")) screen_shot_num = atoi(c2);
  116.         else if (!strcasecmp (c1, "mission")) strcpy (mission.fn, c2);
  117.         else if (!strcasecmp (c1, "name")) strcpy (player.name, c2);
  118.         else if (!strcasecmp (c1, "model")) strcpy (player.model, c2);
  119.         else if (!strcasecmp (c1, "rings")) rings = atoi(c2);
  120.         else if (!strcasecmp (c1, "textures")) textures = atoi(c2);
  121.         else if (!strcasecmp (c1, "realdistances")) realdistances = atoi(c2);
  122.         else if (!strcasecmp (c1, "screenwidth")) ScreenWidth = atoi(c2);
  123.         else if (!strcasecmp (c1, "screenheight")) ScreenHeight = atoi(c2);
  124.         else if (!strcasecmp (c1, "fov")) fov = atof(c2);
  125.         else if (!strcasecmp (c1, "weapon")) player.weapon = atoi(c2);
  126.         else if (!strcasecmp (c1, "fullscreen")) fullscreen = atoi(c2);
  127.         else if (!strcasecmp (c1, "gamemode")) strcpy (gamemode, c2);
  128.         else if (!strcasecmp (c1, "mouse_control")) mouse_control = atoi(c2);
  129.         else if (!strcasecmp (c1, "mouse_flipx")) mouse.flipx = atoi(c2);
  130.         else if (!strcasecmp (c1, "mouse_flipy")) mouse.flipy = atoi(c2);
  131.         else if (!strcasecmp (c1, "flightmodel")) player.flightmodel = atoi(c2);
  132.         else if (!strcasecmp (c1, "ring_sectors")) ring_sectors = atoi(c2);
  133.         else if (!strcasecmp (c1, "fullstop")) fullstop = atoi(c2);
  134.         else if (!strcasecmp (c1, "superwarp")) superwarp = atoi(c2);
  135.         else if (!strcasecmp (c1, "port")) server.port = atoi(c2);
  136.         else if (!strcasecmp (c1, "posx")) player.pos[0] = atof(c2);
  137.         else if (!strcasecmp (c1, "posy")) player.pos[1] = atof(c2);
  138.         else if (!strcasecmp (c1, "posz")) player.pos[2] = atof(c2);
  139.         else if (!strcasecmp (c1, "slices0")) slices0 = atoi(c2);
  140.         else if (!strcasecmp (c1, "stacks0")) stacks0 = atoi(c2);
  141.         else if (!strcasecmp (c1, "slices1")) slices1 = atoi(c2);
  142.         else if (!strcasecmp (c1, "stacks1")) stacks1 = atoi(c2);
  143.         else if (!strcasecmp (c1, "slices2")) slices2 = atoi(c2);
  144.         else if (!strcasecmp (c1, "stacks2")) stacks2 = atoi(c2);
  145.         else if (!strcasecmp (c1, "draw_orbits")) draw_orbits = atoi(c2);
  146.         else if (!strcasecmp (c1, "orbit")) orbit = atoi(c2);
  147.         else if (!strcasecmp (c1, "compression")) compression = atof(c2);
  148.         else
  149.         {
  150.             Log ("ReadPrefs: Unrecognized entry: %s %s", c1, c2);
  151.         }
  152.     }
  153.  
  154.     /* Sayanora */
  155.     fclose (fd);
  156. }
  157.  
  158.