Prepared load/save.
This commit is contained in:
parent
b3a2fa6aef
commit
d4d9f3597b
8 changed files with 190 additions and 56 deletions
src
game
include
stratagus
ui
|
@ -10,7 +10,7 @@
|
|||
##
|
||||
## Makefile - The make file (3 level).
|
||||
##
|
||||
## (c) Copyright 2000 by Lutz Sammer
|
||||
## (c) Copyright 2000,2001 by Lutz Sammer
|
||||
##
|
||||
## $Id$
|
||||
##
|
||||
|
@ -21,6 +21,6 @@ include $(TOPDIR)/Rules.make
|
|||
|
||||
MODULE = game
|
||||
|
||||
OBJS = game.$(OE)
|
||||
OBJS = game.$(OE) savegame.$(OE) loadgame.$(OE)
|
||||
|
||||
include $(TOPDIR)/Common.mk
|
||||
|
|
|
@ -64,12 +64,12 @@ global int lcm_prevent_recurse = 0; /// prevent recursion through LoadGameMap
|
|||
----------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
** Load a clone map.
|
||||
** Load a FreeCraft map.
|
||||
**
|
||||
** @param filename map filename
|
||||
** @param map map loaded
|
||||
*/
|
||||
local void LoadCloneMap(const char* filename,WorldMap* map)
|
||||
local void LoadFreeCraftMap(const char* filename,WorldMap* map)
|
||||
{
|
||||
DebugLevel3Fn("%p \n",map);
|
||||
|
||||
|
@ -124,7 +124,7 @@ global void LoadMap(const char* filename,WorldMap* map)
|
|||
|| !strcmp(tmp,".cm.bz2")
|
||||
#endif
|
||||
) {
|
||||
LoadCloneMap(filename,map);
|
||||
LoadFreeCraftMap(filename,map);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
71
src/game/loadgame.cpp
Normal file
71
src/game/loadgame.cpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
// ___________ _________ _____ __
|
||||
// \_ _____/______ ____ ____ \_ ___ \____________ _/ ____\/ |_
|
||||
// | __) \_ __ \_/ __ \_/ __ \/ \ \/\_ __ \__ \\ __\\ __\
|
||||
// | \ | | \/\ ___/\ ___/\ \____| | \// __ \| | | |
|
||||
// \___ / |__| \___ >\___ >\______ /|__| (____ /__| |__|
|
||||
// \/ \/ \/ \/ \/
|
||||
// ______________________ ______________________
|
||||
// T H E W A R B E G I N S
|
||||
// FreeCraft - A free fantasy real time strategy game engine
|
||||
//
|
||||
/**@name savegame.c - Save game. */
|
||||
//
|
||||
// (c) Copyright 2001 by Lutz Sammer, Andreas Arens
|
||||
//
|
||||
// $Id$
|
||||
|
||||
//@{
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Includes
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "freecraft.h"
|
||||
#include "icons.h"
|
||||
#include "ccl.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Variables
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Functions
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
** Cleanup all.
|
||||
**
|
||||
** Call each module to clean up.
|
||||
*/
|
||||
global void CleanupAll(void)
|
||||
{
|
||||
CleanIcons();
|
||||
#if 0
|
||||
// SaveUI();
|
||||
CleanUnitTypes();
|
||||
CleanUnits();
|
||||
CleanUpgrades();
|
||||
CleanDependencies();
|
||||
CleanButtons();
|
||||
CleanMissileTypes();
|
||||
CleanMissiles();
|
||||
CleanTileset();
|
||||
CleanMap();
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
** Load all game data.
|
||||
*/
|
||||
global void LoadAll(void)
|
||||
{
|
||||
CleanupAll();
|
||||
|
||||
gh_eval_file("save_file_of_freecraft.ccl");
|
||||
|
||||
MustRedraw=RedrawEverything; // redraw everything
|
||||
}
|
||||
|
||||
//@}
|
100
src/game/savegame.cpp
Normal file
100
src/game/savegame.cpp
Normal file
|
@ -0,0 +1,100 @@
|
|||
// ___________ _________ _____ __
|
||||
// \_ _____/______ ____ ____ \_ ___ \____________ _/ ____\/ |_
|
||||
// | __) \_ __ \_/ __ \_/ __ \/ \ \/\_ __ \__ \\ __\\ __\
|
||||
// | \ | | \/\ ___/\ ___/\ \____| | \// __ \| | | |
|
||||
// \___ / |__| \___ >\___ >\______ /|__| (____ /__| |__|
|
||||
// \/ \/ \/ \/ \/
|
||||
// ______________________ ______________________
|
||||
// T H E W A R B E G I N S
|
||||
// FreeCraft - A free fantasy real time strategy game engine
|
||||
//
|
||||
/**@name savegame.c - Save game. */
|
||||
//
|
||||
// (c) Copyright 2001 by Lutz Sammer, Andreas Arens
|
||||
//
|
||||
// $Id$
|
||||
|
||||
//@{
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Includes
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "freecraft.h"
|
||||
|
||||
#include "icons.h"
|
||||
#include "ui.h"
|
||||
#include "unittype.h"
|
||||
#include "unit.h"
|
||||
#include "upgrade.h"
|
||||
#include "depend.h"
|
||||
#include "interface.h"
|
||||
#include "missile.h"
|
||||
#include "tileset.h"
|
||||
#include "map.h"
|
||||
|
||||
#include "ccl.h"
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Variables
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Functions
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
** Save a game to file.
|
||||
**
|
||||
** @param filename File name to be stored.
|
||||
**
|
||||
** @note Later we want to store in a more compact binary format.
|
||||
*/
|
||||
global void SaveGame(const char* filename)
|
||||
{
|
||||
time_t now;
|
||||
FILE* file;
|
||||
|
||||
file=fopen(filename,"wb");
|
||||
if( !file ) {
|
||||
fprintf(stderr,"Can't save to `%s'\n",filename);
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(file,";;; -----------------------------------------\n");
|
||||
fprintf(file,";;; Save file generated by FreeCraft Version " VERSION "\n");
|
||||
fprintf(file,";;;\thttp://FreeCraft.Org\n");
|
||||
time(&now);
|
||||
fprintf(file,";;;\tDate: %s",ctime(&now));
|
||||
fprintf(file,";;;\tMap: %s\n",TheMap.Description);
|
||||
fprintf(file,";;; -----------------------------------------\n\n");
|
||||
|
||||
SaveIcons(file);
|
||||
// SaveUI(file);
|
||||
SaveUnitTypes(file);
|
||||
SaveUnits(file);
|
||||
SaveUpgrades(file);
|
||||
SaveDependencies(file);
|
||||
SaveButtons(file);
|
||||
SaveMissileTypes(file);
|
||||
SaveMissiles(file);
|
||||
SaveTileset(file);
|
||||
SaveMap(file);
|
||||
|
||||
// FIXME: find all state information which must be saved.
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
/**
|
||||
** Test function for the later save functions.
|
||||
*/
|
||||
global void SaveAll(void)
|
||||
{
|
||||
SaveGame("save_file_of_freecraft.ccl");
|
||||
}
|
||||
|
||||
//@}
|
|
@ -354,6 +354,7 @@ extern int SpeedKeyScroll; /// Keyboard Scrolling Speed, in Frames
|
|||
extern int SpeedMouseScroll; /// Mouse Scrolling Speed, in Frames
|
||||
|
||||
extern void SaveAll(void); /// Call all modules to save states
|
||||
extern void LoadAll(void); /// Load all data back.
|
||||
|
||||
extern int SyncRand(void);
|
||||
|
||||
|
|
|
@ -174,50 +174,6 @@ global int SlowFrameCounter; /// profile, frames out of sync
|
|||
// FIXME: not the correct place
|
||||
global enum MustRedraw_e MustRedraw=RedrawEverything; /// redraw flags
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- SAVE/LOAD
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
** Test function for the later save functions.
|
||||
*/
|
||||
global void SaveAll(void)
|
||||
{
|
||||
FILE* file;
|
||||
time_t now;
|
||||
const char* name;
|
||||
|
||||
name="save_file_of_freecraft.ccl";
|
||||
// FIXME: must choose better name.
|
||||
file=fopen(name,"wb");
|
||||
if( !file ) {
|
||||
fprintf(stderr,"Can't save to `%s'\n",name);
|
||||
return;
|
||||
}
|
||||
fprintf(file,";;; -----------------------------------------\n");
|
||||
fprintf(file,";;; Save file generated by FreeCraft Version " VERSION "\n");
|
||||
time(&now);
|
||||
fprintf(file,";;;\tDate: %s",ctime(&now));
|
||||
fprintf(file,";;;\tMap: %s\n",TheMap.Description);
|
||||
fprintf(file,";;; -----------------------------------------\n\n\n");
|
||||
|
||||
SaveIcons(file);
|
||||
// SaveUI(file);
|
||||
SaveUnitTypes(file);
|
||||
SaveUnits(file);
|
||||
SaveUpgrades(file);
|
||||
SaveDependencies(file);
|
||||
SaveButtons(file);
|
||||
SaveMissileTypes(file);
|
||||
SaveMissiles(file);
|
||||
SaveTileset(file);
|
||||
SaveMap(file);
|
||||
|
||||
// FIXME: find all state information which must be saved.
|
||||
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Random
|
||||
----------------------------------------------------------------------------*/
|
||||
|
|
|
@ -460,10 +460,10 @@ local int CommandKey(int key)
|
|||
break;
|
||||
}
|
||||
case KeyCodeF12:
|
||||
SetStatusLine("Loading not supported");
|
||||
LoadAll();
|
||||
break;
|
||||
|
||||
case 's'&0x1F: // Ctrl + S - Turn sound on / off
|
||||
case 's'&0x1F: // Ctrl + S - Turn sound on / off
|
||||
UiToggleSound();
|
||||
break;
|
||||
|
||||
|
@ -860,16 +860,16 @@ global int HoldClickDelay=1000; /// Time to detect hold clicks.
|
|||
local enum {
|
||||
InitialMouseState, /// start state
|
||||
ClickedMouseState, /// button is clicked
|
||||
} MouseState; /// Current state of mouse
|
||||
} MouseState; /// Current state of mouse
|
||||
|
||||
local int LastMouseButton; /// last mouse button handled
|
||||
local int StartMouseTicks; /// Ticks of first click
|
||||
local int LastMouseTicks; /// Ticks of last mouse event
|
||||
local int LastMouseTicks; /// Ticks of last mouse event
|
||||
|
||||
/**
|
||||
** Called if any mouse button is pressed down
|
||||
**
|
||||
** Handles event conversion to double click, dragging, hold.
|
||||
** Handles event conversion to double click, dragging, hold.
|
||||
**
|
||||
** FIXME: dragging is not supported.
|
||||
**
|
||||
|
@ -878,7 +878,7 @@ local int LastMouseTicks; /// Ticks of last mouse event
|
|||
*/
|
||||
global void InputMouseButtonPress(const EventCallback* callbacks,
|
||||
unsigned ticks,unsigned button)
|
||||
{
|
||||
{
|
||||
//
|
||||
// Button new pressed.
|
||||
//
|
||||
|
|
|
@ -53,6 +53,7 @@ local void EndMenu(void);
|
|||
----------------------------------------------------------------------------*/
|
||||
|
||||
local void GameMenuSave(void);
|
||||
local void GameMenuLoad(void);
|
||||
local void GameMenuEnd(void);
|
||||
local void GameMenuReturn(void);
|
||||
|
||||
|
@ -148,7 +149,7 @@ local Menuitem GameMenuItems[] = {
|
|||
{ MI_TYPE_BUTTON, 16, 40, MenuButtonDisabled, LargeFont, NULL, NULL,
|
||||
{ button:{ "Save (~<F11~>)", 106, 27, MBUTTON_GM_HALF, GameMenuSave, KeyCodeF11} } },
|
||||
{ MI_TYPE_BUTTON, 16 + 12 + 106, 40, MenuButtonDisabled, LargeFont, NULL, NULL,
|
||||
{ button:{ "Load (~<F12~>)", 106, 27, MBUTTON_GM_HALF, NULL, KeyCodeF12} } },
|
||||
{ button:{ "Load (~<F12~>)", 106, 27, MBUTTON_GM_HALF, GameMenuLoad, KeyCodeF12} } },
|
||||
{ MI_TYPE_BUTTON, 16, 40 + 36, MenuButtonDisabled, LargeFont, NULL, NULL,
|
||||
{ button:{ "Options (~<F5~>)", 224, 27, MBUTTON_GM_FULL, NULL, KeyCodeF5} } },
|
||||
{ MI_TYPE_BUTTON, 16, 40 + 36 + 36, MenuButtonDisabled, LargeFont, NULL, NULL,
|
||||
|
@ -939,6 +940,11 @@ local void GameMenuSave(void)
|
|||
SaveAll(); // FIXME: Sample code
|
||||
}
|
||||
|
||||
local void GameMenuLoad(void)
|
||||
{
|
||||
LoadAll(); // FIXME: Sample code
|
||||
}
|
||||
|
||||
local void GameMenuEnd(void)
|
||||
{
|
||||
Exit(0);
|
||||
|
|
Loading…
Add table
Reference in a new issue