Game replay supports custom scenario options, fixed bug that made the replay go out of sync

This commit is contained in:
jsalmon3 2002-08-02 21:09:08 +00:00
parent fef0f6da52
commit 344d972c19
2 changed files with 61 additions and 26 deletions
src
network
stratagus

View file

@ -48,6 +48,7 @@
#include "commands.h"
#include "interface.h"
#include "iocompat.h"
#include "settings.h"
//----------------------------------------------------------------------------
// Declaration
@ -59,6 +60,7 @@
global int CommandLogDisabled; /// True if command log is off
local int DisabledLog; /// Disabled log for replay
local int DisabledShowTips; /// Disabled show tips
local SCM ReplayLog; /// Replay log
local FILE* LogFile; /// Replay log file
local int NextLogCycle; /// Next log cycle number
@ -126,7 +128,6 @@ local void CommandLog(const char* name,const Unit* unit,int flag,
//
// Parseable header
// TODO: add custom start options (eg high resources, game type, etc)
//
fprintf(LogFile,"(replay-log\n");
fprintf(LogFile," 'comment\t\"Generated by FreeCraft Version " VERSION "\"\n");
@ -137,6 +138,12 @@ local void CommandLog(const char* name,const Unit* unit,int flag,
fprintf(LogFile," 'map\t\"%s\"\n",TheMap.Description);
fprintf(LogFile," 'map-id\t%u\n",TheMap.Info->MapUID);
fprintf(LogFile," 'map-path\t\"%s\"\n",CurrentMapPath);
fprintf(LogFile," 'race\t%d\n",GameSettings.Presets[0].Race);
fprintf(LogFile," 'resources\t%d\n",GameSettings.Resources);
fprintf(LogFile," 'num-units\t%d\n",GameSettings.NumUnits);
fprintf(LogFile," 'tileset\t%d\n",GameSettings.Terrain);
fprintf(LogFile," 'game-type\t%d\n",GameSettings.GameType);
fprintf(LogFile," 'opponents\t%d\n",GameSettings.Opponents);
fprintf(LogFile," 'engine\t'(%d %d %d)\n",
FreeCraftMajorVersion,FreeCraftMinorVersion,FreeCraftPatchLevel);
fprintf(LogFile," 'network\t'(%d %d %d)\n",
@ -258,6 +265,24 @@ local SCM CclReplayLog(SCM list)
mappath=get_c_string(gh_car(list));
strcpy(CurrentMapPath,mappath);
list=gh_cdr(list);
} else if( gh_eq_p(value,gh_symbol2scm("race")) ) {
GameSettings.Presets[0].Race=gh_scm2int(gh_car(list));
list=gh_cdr(list);
} else if( gh_eq_p(value,gh_symbol2scm("resources")) ) {
GameSettings.Resources=gh_scm2int(gh_car(list));
list=gh_cdr(list);
} else if( gh_eq_p(value,gh_symbol2scm("num-units")) ) {
GameSettings.NumUnits=gh_scm2int(gh_car(list));
list=gh_cdr(list);
} else if( gh_eq_p(value,gh_symbol2scm("tileset")) ) {
GameSettings.Terrain=gh_scm2int(gh_car(list));
list=gh_cdr(list);
} else if( gh_eq_p(value,gh_symbol2scm("game-type")) ) {
GameSettings.GameType=gh_scm2int(gh_car(list));
list=gh_cdr(list);
} else if( gh_eq_p(value,gh_symbol2scm("opponents")) ) {
GameSettings.Opponents=gh_scm2int(gh_car(list));
list=gh_cdr(list);
} else if( gh_eq_p(value,gh_symbol2scm("engine")) ) {
sublist=gh_car(list);
ever1=gh_scm2int(gh_car(sublist));
@ -298,6 +323,12 @@ global int LoadReplay(char* name)
CommandLogDisabled=1;
DisabledLog=1;
}
if( ShowTips ) {
ShowTips=0;
DisabledShowTips=1;
} else {
DisabledShowTips=0;
}
return 0;
}
@ -315,6 +346,10 @@ global void EndReplayLog(void)
CommandLogDisabled=0;
DisabledLog=0;
}
if( DisabledShowTips ) {
ShowTips=1;
DisabledShowTips=0;
}
}
/**
@ -392,53 +427,53 @@ local void DoNextReplay(void)
}
if( !strcmp(name,"stop") ) {
SendCommandStopUnit(Units[unit]);
SendCommandStopUnit(UnitSlots[unit]);
} else if( !strcmp(name,"stand-ground") ) {
SendCommandStandGround(Units[unit],flags);
SendCommandStandGround(UnitSlots[unit],flags);
} else if( !strcmp(name,"follow") ) {
SendCommandFollow(Units[unit],Units[dest],flags);
SendCommandFollow(UnitSlots[unit],UnitSlots[dest],flags);
} else if( !strcmp(name,"move") ) {
SendCommandMove(Units[unit],posx,posy,flags);
SendCommandMove(UnitSlots[unit],posx,posy,flags);
} else if( !strcmp(name,"repair") ) {
SendCommandRepair(Units[unit],posx,posy,Units[dest],flags);
SendCommandRepair(UnitSlots[unit],posx,posy,UnitSlots[dest],flags);
} else if( !strcmp(name,"attack") ) {
SendCommandAttack(Units[unit],posx,posy,Units[dest],flags);
SendCommandAttack(UnitSlots[unit],posx,posy,UnitSlots[dest],flags);
} else if( !strcmp(name,"attack-ground") ) {
SendCommandAttackGround(Units[unit],posx,posy,flags);
SendCommandAttackGround(UnitSlots[unit],posx,posy,flags);
} else if( !strcmp(name,"patrol") ) {
SendCommandPatrol(Units[unit],posx,posy,flags);
SendCommandPatrol(UnitSlots[unit],posx,posy,flags);
} else if( !strcmp(name,"board") ) {
SendCommandBoard(Units[unit],posx,posy,Units[dest],flags);
SendCommandBoard(UnitSlots[unit],posx,posy,UnitSlots[dest],flags);
} else if( !strcmp(name,"unload") ) {
SendCommandUnload(Units[unit],posx,posy,dest!=-1?Units[dest]:NoUnitP,flags);
SendCommandUnload(UnitSlots[unit],posx,posy,dest!=-1?UnitSlots[dest]:NoUnitP,flags);
} else if( !strcmp(name,"build") ) {
SendCommandBuildBuilding(Units[unit],posx,posy,UnitTypeByIdent(val),flags);
SendCommandBuildBuilding(UnitSlots[unit],posx,posy,UnitTypeByIdent(val),flags);
} else if( !strcmp(name,"cancel-build") ) {
SendCommandCancelBuilding(Units[unit],Units[dest]);
SendCommandCancelBuilding(UnitSlots[unit],UnitSlots[dest]);
} else if( !strcmp(name,"harvest") ) {
SendCommandHarvest(Units[unit],posx,posy,flags);
SendCommandHarvest(UnitSlots[unit],posx,posy,flags);
} else if( !strcmp(name,"mine") ) {
SendCommandMineGold(Units[unit],Units[dest],flags);
SendCommandMineGold(UnitSlots[unit],UnitSlots[dest],flags);
} else if( !strcmp(name,"haul") ) {
SendCommandHaulOil(Units[unit],Units[dest],flags);
SendCommandHaulOil(UnitSlots[unit],UnitSlots[dest],flags);
} else if( !strcmp(name,"return") ) {
SendCommandReturnGoods(Units[unit],Units[dest],flags);
SendCommandReturnGoods(UnitSlots[unit],UnitSlots[dest],flags);
} else if( !strcmp(name,"train") ) {
SendCommandTrainUnit(Units[unit],UnitTypeByIdent(val),flags);
SendCommandTrainUnit(UnitSlots[unit],UnitTypeByIdent(val),flags);
} else if( !strcmp(name,"cancel-train") ) {
SendCommandCancelTraining(Units[unit],num,UnitTypeByIdent(val));
SendCommandCancelTraining(UnitSlots[unit],num,UnitTypeByIdent(val));
} else if( !strcmp(name,"upgrade-to") ) {
SendCommandUpgradeTo(Units[unit],UnitTypeByIdent(val),flags);
SendCommandUpgradeTo(UnitSlots[unit],UnitTypeByIdent(val),flags);
} else if( !strcmp(name,"cancel-upgrade-to") ) {
SendCommandCancelUpgradeTo(Units[unit]);
SendCommandCancelUpgradeTo(UnitSlots[unit]);
} else if( !strcmp(name,"research") ) {
SendCommandResearch(Units[unit],UpgradeByIdent(val),flags);
SendCommandResearch(UnitSlots[unit],UpgradeByIdent(val),flags);
} else if( !strcmp(name,"cancel-research") ) {
SendCommandCancelResearch(Units[unit]);
SendCommandCancelResearch(UnitSlots[unit]);
} else if( !strcmp(name,"demolish") ) {
SendCommandDemolish(Units[unit],posx,posy,Units[dest],flags);
SendCommandDemolish(UnitSlots[unit],posx,posy,UnitSlots[dest],flags);
} else if( !strcmp(name,"spell-cast") ) {
SendCommandSpellCast(Units[unit],posx,posy,Units[dest],num,flags);
SendCommandSpellCast(UnitSlots[unit],posx,posy,UnitSlots[dest],num,flags);
} else if( !strcmp(name,"diplomacy") ) {
int state;
if( !strcmp(val,"neutral") ) {

View file

@ -733,6 +733,7 @@ global void GameMainLoop(void)
// Game logic part
//
if (!GamePaused && NetworkInSync && !SkipGameCycle) {
ReplayEachCycle();
if( !++GameCycle ) {
// FIXME: tests with game cycle counter now fails :(
// FIXME: Should happen in 68 years :)
@ -741,7 +742,6 @@ global void GameMainLoop(void)
fprintf(stderr,"FIXME: *** round robin ***\n");
fprintf(stderr,"FIXME: *** round robin ***\n");
}
ReplayEachCycle();
NetworkCommands(); // Get network commands
UnitActions(); // handle units
MissileActions(); // handle missiles