Remember how I wanted multiple and text-commented replays? (see
my previous post if you can't remember.)
Well, I've fiddled around in the source code and came up with something that writes demofiles into a demo/ with incrementing filename and accompanying text file. The text file looks like this:
Code: Select all
*****************************
* *
* TA Spring demo file *
* *
*****************************
Version: 0.51b2
Mapname: SmallDivide.smf
================================================
Side | Team | Ally team | Player
------------------------------------------------
arm | 3 | 3 | colorblind
arm | 2 | 2 | LewsTherin
arm | 1 | 1 | nuudleh
arm | 0 | 0 | mcdumpsterxi
================================================
================================================
Time | Event
------------------------------------------------
00:18 | Team 3 (colorblind) was annihilated
00:31 | Team 0 (mcdumpsterxi) was annihilated
00:36 | Team 1 (nuudleh) was annihilated
Hmm ... the tabs looked okay in my text editor/viewer. Anyhow, the codechanges are below. They're quite reasonable in size, so take your time.
NET.H
In net.h change line 134
to
Code: Select all
char demoBinFile[50];
char demoTxtFile[50];
void CreateDemoFile(void);
NET.CPP
In net.cpp change line 153
to
Change the function CreateDemoFile (which begins on line 546) from
Code: Select all
void CNet::CreateDemoFile(char* name)
{
recordDemo=new ofstream(name, ios::out|ios::binary);
if(gameSetup){
char c=1;
recordDemo->write(&c,1);
recordDemo->write((char*)&gameSetup->gameSetupTextLength,sizeof(int));
recordDemo->write(gameSetup->gameSetupText,gameSetup->gameSetupTextLength);
} else {
char c=0;
recordDemo->write(&c,1);
}
}
to
Code: Select all
void CNet::CreateDemoFile()
{
for(int a=0;a<9999;++a){
sprintf(demoBinFile,"demos/demo%03i.sdf",a);
sprintf(demoTxtFile,"demos/demo%03i.txt",a);
CFileHandler ifs(demoBinFile);
if(!ifs.FileExists())
break;
}
recordDemo=new ofstream(demoBinFile, ios::out|ios::binary);
if(gameSetup){
char c=1;
recordDemo->write(&c,1);
recordDemo->write((char*)&gameSetup->gameSetupTextLength,sizeof(int));
recordDemo->write(gameSetup->gameSetupText,gameSetup->gameSetupTextLength);
ofstream fout(demoTxtFile, ios::trunc);
fout << "*****************************\n";
fout << "* *\n";
fout << "* TA Spring demo file *\n";
fout << "* *\n";
fout << "*****************************\n";
fout << "\n";
fout << "\n";
fout << "Version:\t" << game->version << "\n";
fout << "Mapname:\t" << pregame->mapName << "\n";
fout << "\n";
fout << "\n";
fout << "================================================\n";
fout << "Side\t| Team\t| Ally team\t| Player\n";
fout << "------------------------------------------------\n";
for(int a=0;a<gameSetup->numPlayers;++a){
if(!gs->players[a]->spectator){ // we don't care for spectators
int team = gs->players[a]->team;
fout << gs->teams[team]->side << " \t| " << team << " \t| ";
fout << gs->team2allyteam[team] << " \t\t| " << gs->players[a]->playerName << "\n";
}
}
fout << "================================================\n";
fout << "\n";
fout << "\n";
fout << "================================================\n";
fout << "Time\t| Event\n";
fout << "------------------------------------------------\n";
fout << flush;
fout.close();
} else {
char c=0;
recordDemo->write(&c,1);
}
}
Pregame.h will have to be included for the mapname info. Furthermore I've introduced a 'Spring version' variable, which is stored in the game instance. Perhaps a global constant is better, but I'll leave that to the SY. Here's how I've put it in the game object:
GAME.H
In game.h, after
Code: Select all
class CGame : public CGameController
{
public:
add the following:
Code: Select all
std::string version;
std::string fullversion;
GAME.CPP
In game.cpp add after
Code: Select all
CGame::CGame(bool server,std::string mapname)
{
the following:
Code: Select all
version = "0.51b2";
fullversion = "TA Spring " + version;
Change line 248 from
Code: Select all
info->AddLine("TA Spring 0.51b1");
to
I couldn't get this to work in myGL.cpp on line 84 with font->glPrintAt() ... looks like glPrintAt() is very picky with its arguments.
Anyway, back to demo text file.
TEAM.CPP
In teamp.cpp, add after lines 203-212
Code: Select all
if(units.empty()){
info->AddLine("Team %i (%s) is no more",teamNum,gs->players[leader]->playerName.c_str());
isDead=true;
for(int a=0;a<MAX_PLAYERS;++a){
...
}
the following:
Code: Select all
char time[10];
sprintf(time,"%02i:%02i",gs->frameNum/60/30,(gs->frameNum/30)%60);
ofstream fout(net->demoTxtFile, ios::app);
fout << time << "\t| ";
fout << "Team " << teamNum << " (" << gs->players[leader]->playerName << ") was annihilated\n";
fout << flush;
fout.close();
Net.h has to be included for getting net->demoTxtFile.
And of course I'd appreciate very much if this gets into the CVS :)