persist.cc
mud++0.35/src/persist.cc · 2.5 KB
From the archive mud++0.35.tar.gz
Download the archive « Back to the archive contents
/*
....[@@@..[@@@..............[@.................. MUD++ is a written from
....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and
....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++.
....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing
....[@......[@..[@@@@@..[@@@@@.................. development project. All
................................................ contributions are welcome.
....Copyright(C).1995.Melvin.Smith.............. Enjoy.
------------------------------------------------------------------------------
Melvin Smith (aka Fusion) msmith@hom.net
MUD++ development mailing list mudpp@van.ml.org
------------------------------------------------------------------------------
persist.cpp
*/
// Data file is used for saving informations that should persist between
// reboots, but do not fit in area files, nor the player files
// example: pc shops data, last wandering camp position etc.
#include "config.h"
#include "io.h"
#include "garbcoll.h"
#include "area.h"
#include "room.h"
#include "global.h"
#include "shop.h"
int GC_stack_hint = 0;
int GC_free_hint = 0;
void loadPersistentData()
{
char buf[BUF];
InputFile data( "../etc/persist.dat" );
if ( !data )
return;
ShopKeeper * sk;
Room * room;
// load shops
while ( *data.getword(buf) != '#' )
{
switch( *buf )
{
case 'G':
if ( !strcmp( buf, "GC_stack_hint" ) )
{
GC_stack_hint = data.getnum();
continue;
}
else if ( !strcmp( buf, "GC_free_hint" ) )
{
GC_free_hint = data.getnum();
continue;
}
break;
case 'S':
if ( !strcmp( buf, "Shop" ) )
{
data.getword(buf);
room = lookupRoom(buf);
sk = new ShopKeeper();
sk->readFrom(data);
shops.add(sk);
if ( !room )
{
Cout << "Warning: room " << buf << " for shopkeeper not found.\n\r";
continue;
}
// a bit tricky - will change
sk->toWorld();
room->addCharInv(sk);
continue;
}
break;
default:
break;
}
Cout << "Unknown persistent data " << buf << " at line " <<
data.getLineNo() << endl;
}
}
void savePersistentData()
{
OutputFile data("../etc/persist.dat");
ShopKeeper * sk;
data << "GC_stack_hint " << GC_getStackSize() <<endl;
data << "GC_free_hint " << GC_getFreeCount() <<endl;
for_each( shops, sk )
{
data << "Shop " << sk->inRoom()->getArea()->getKey() << ":" <<
sk->inRoom()->getKey() << endl;
sk->writeTo(data);
}
data << "#";
return;
}