Main Page   Data Structures   File List   Data Fields   Globals   Related Pages  

nix-common/savegame_be.c File Reference

back-end code for savegames More...

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <main.h>
#include <globals.h>
#include <handler.h>
#include <ui.h>
#include <simulation.h>
#include <inttypes.h>
#include <strings.h>
#include <mem_compat.h>
#include <stringsearch.h>
#include <savegame_be.h>

Go to the source code of this file.

Data Structures

struct  embedded_savegame
 an embedded savegame inside a savegame More...

struct  save_tag
 a savegame structure More...


Functions

unsigned char * mapm_int32 (unsigned char *mem, unsigned char *val)
 map a memory element that's 32bits long

savegame_t * savegame_open (char *filename)
 open a savegame file, breaking it into games

void savegame_close (savegame_t *sg)
 close a previously created savegame structure

char * savegame_getcityname (savegame_t *sg, int item)
 get the name of a city in the savegame structure

int savegame_getcity (savegame_t *sg, int item, GameStruct *gs, char **map)
 get a city structure from the savegame structure

int savegame_setcity (savegame_t *sg, int item, GameStruct *gs, char *map)
 store the contents of a city into the savegame structure

int savegame_citycount (savegame_t *sg)
 get the count of the cities in a savegame structure

int load_defaultfilename (void)
 load the default file name into the default game structures

int save_defaultfilename ()
 save the default savegame file and map

int save_filename (char *sel, GameStruct *gs, char *world)
 save a filename using the gamestruct and worldptr passed

void NewGame (void)
 Initialize the game structures for a new game.

char * getCityFileName (void)
 get the name of default city file

int setCityFileName (char *newName)
 set the city file name


Detailed Description

back-end code for savegames

Deals with the savegames being loaded and saved. Can perform read-only work on palmOS games directly, but performs read/write on native games.

The code needs to be made more platform-independent, as it is it depends a lot on the endianness of the machine you're running it on.

Todo:
change the savegame format to XML for the linux platforms.

Definition in file savegame_be.c.


Function Documentation

char* getCityFileName void   
 

get the name of default city file

Returns:
NULL if it's not set.

Definition at line 473 of file savegame_be.c.

Referenced by load_defaultfilename(), save_defaultfilename(), and savegame_handler().

int load_defaultfilename void   
 

load the default file name into the default game structures

Returns:
-1 if something went wrong, 0 otherwise

Definition at line 396 of file savegame_be.c.

References getCityFileName(), savegame_close(), savegame_getcity(), and savegame_open().

unsigned char* mapm_int32 unsigned char *    mem,
unsigned char *    val
[static]
 

map a memory element that's 32bits long

Parameters:
mem  the memory to map
val  the value to populate with the value
Returns:
pointer to just after the data

Definition at line 126 of file savegame_be.c.

References Int32.

int save_defaultfilename void   
 

save the default savegame file and map

Returns:
-1 if something went wrong, 0 otherwise

Definition at line 408 of file savegame_be.c.

References getCityFileName(), and save_filename().

Referenced by savegame_handler(), and store_filename().

int save_filename char *    sel,
GameStruct   gs,
char *    world
 

save a filename using the gamestruct and worldptr passed

Parameters:
sel  the name of the file to save
gs  the gamestruct to save
world  the worldpointer to save
Returns:
-1 on error, 0 otherwise.

Definition at line 414 of file savegame_be.c.

References _game_struct06a::mapx, and _game_struct06a::mapy.

Referenced by save_defaultfilename().

int savegame_citycount savegame_t *    sg
 

get the count of the cities in a savegame structure

Parameters:
sg  the savegame structure
Returns:
the count of the cities, or -1 on error

Definition at line 389 of file savegame_be.c.

Referenced by doOpen(), and loadCities().

void savegame_close savegame_t *    sg
 

close a previously created savegame structure

Parameters:
sg  the gamestructure from an savegame_open call

Definition at line 341 of file savegame_be.c.

Referenced by doOpen(), free_listselect(), and load_defaultfilename().

int savegame_getcity savegame_t *    sg,
int    item,
GameStruct   gs,
char **    map
 

get a city structure from the savegame structure

Parameters:
sg  the savegame structure allocated from savegame_open
item  the index of the savegame to access
gs  the game structure to populate with the world
map  the reference to a pointer that will be allocated and filled with the map. It will be realloced into.
Returns:
0 if the item was copied safely, -1 otherwise
the map parameter will have it's value overwritten, so if you've allocated a pointer into it you need to free it beforehand.

Definition at line 362 of file savegame_be.c.

References _game_struct06a::mapx, and _game_struct06a::mapy.

Referenced by doOpen(), ImportOneFromGame(), and load_defaultfilename().

char* savegame_getcityname savegame_t *    sg,
int    item
 

get the name of a city in the savegame structure

Parameters:
sg  the savegame structure allocated from savegame_open
item  the savegame who's name you want to access
Returns:
a pointer to the savegame, or NULL on error

Definition at line 353 of file savegame_be.c.

savegame_t* savegame_open char *    filename
 

open a savegame file, breaking it into games

Parameters:
filename  the name of the file to open
Returns:
the savegame, or NULL if the file could not be processed.

Definition at line 274 of file savegame_be.c.

References inMem(), and SAVEGAMEVERSION.

Referenced by doOpen(), and load_defaultfilename().

int savegame_setcity savegame_t *    sg,
int    item,
GameStruct   gs,
char *    map
 

store the contents of a city into the savegame structure

Parameters:
sg  the savegame structure
item  the index of the savegame to set
gs  the game structure to store
map  the map to store
Returns:
0 on success, -1 on error

Definition at line 375 of file savegame_be.c.

References _game_struct06a::mapx, and _game_struct06a::mapy.

int setCityFileName char *    name
 

set the city file name

Returns:
-1 if the name was rejected (ended in .pdb)

Definition at line 479 of file savegame_be.c.

Referenced by doOpen(), and store_filename().


Generated on Mon Aug 30 19:44:18 2004 for pocketcity by doxygen1.2.18