/* Copyright (C) 2003 Parallel Realities This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* #include "loadSave.h" */ #include #ifndef PATH_MAX #define PATH_MAX 4096 #endif /* #define NULL */ typedef struct obj { signed char active; signed char classDef; // Used by aliens to determine what they are signed char AIType; // Type of articifial intelligence signed char id; // The "job" of the obj void *target; // index target in enemy array signed char reload[2]; int systemPower; // computer systems for craft int shield; // current shield int maxShield; // max shield (for recharging) int deathCounter; // how long to explode for signed char speed; unsigned char damage; // Contact damage for bullets int score; // How much a kill of this is worth unsigned char ammo[2]; // Ammo for 2nd weapon. Max of 100 (except laser) signed char face; // Either 0 or 1 void *owner; // Who owns this obj int chance[2]; // Chance of using the weapons (out of 1000) int *image[2]; // For facing left and right unsigned char imageIndex[2]; // used for loading signed char hit; // used to make a craft "flash" if it is struck by a shot int engineX; // The place for the engine on the other side of the craft int engineY; // The middle of the engine on the craft int thinktime; // When the obj will next react signed char weaponType[2]; // Weapon types signed char collectChance; // Chance of dropping the obj signed char collectType; // What the obj is carrying unsigned char collectValue; // What it is worth int flags; // Various flags for an obj float x, y, dx, dy; void *next; } obj; typedef struct Game { obj thePlayer; obj playerWeapon; obj playerWeapon2; unsigned char system; unsigned char area; unsigned char musicVolume; unsigned char sfxVolume; signed char fullScreen; signed char useMusic; signed char useSound; signed char autoSaveSlot; unsigned int cash; unsigned int cashEarned; unsigned int shots; unsigned int hits; unsigned char accuracy; unsigned char hasWingMate1, hasWingMate2; unsigned int totalKills, wingMate1Kills, wingMate2Kills; unsigned char wingMate1Ejects, wingMate2Ejects; unsigned int totalOtherKills; unsigned char secondaryMissions, secondaryMissionsCompleted; unsigned int shieldPickups, rocketPickups, cellPickups, powerups, minesKilled, cargoPickups; // slaves for Eyananth unsigned int slavesRescued; // remaining shield for experimental fighter unsigned int experimentalShield; unsigned int timeTaken; // In seconds unsigned char missionCompleted[10]; signed char stationedPlanet; signed char destinationPlanet; char stationedName[20]; char destinationName[20]; int distanceCovered; unsigned char maxPlasmaRate; unsigned char maxPlasmaDamage; unsigned char maxPlasmaOutput; unsigned char maxPlasmaAmmo; unsigned char maxRocketAmmo; unsigned char shieldUnits; } Game; Game mygame; /* Fill in later... */ signed char loadGame(int slot) { char filename[PATH_MAX]; FILE *fp; sprintf(filename, "save%.2d.dat", slot); fp = fopen(filename, "rb"); if (fp == NULL) return 0; if (fread(&mygame, sizeof(Game), 1, fp) != 1) { printf("Save game error. The file was not of the expected format.\n"); fclose(fp); return 0; } fclose(fp); return 1; } void saveGame(int slot) { FILE *fp; char filename[PATH_MAX]; if ((slot < 1) || (slot > 5)) { printf("Error - Saves may only be 1 to 5\n"); return; } sprintf(filename, "edit_save%.2d.dat", slot); fp = fopen(filename, "wb"); if (fp != NULL) { if (fwrite(&mygame, sizeof(Game), 1, fp) != 1) { printf("Error Saving Game to Slot %d\n", slot); } fclose(fp); } else { printf("Error Saving Game to Slot %d\n", slot); } } int main ( char *argv[], int argc ) { printf("save game edit\n"); loadGame(1); printf("cash = %d\n", mygame.cash); printf("cashEarned = %d\n", mygame.cashEarned); mygame.cash +=20000; mygame.cashEarned +=20000; printf("cash = %d\n", mygame.cash); printf("cashEarned = %d\n", mygame.cashEarned); saveGame(1); printf("saved\n"); }