Updates for a new interface to the networking
[crack-attack.git] / src / ActionRecorder.cxx
blobf68e674bb233e8c1b81caaf140f49abcbe154d33
1 /*
2 * ActionRecorder.cxx
3 *
4 * Crack Attack! is the legal property of its developers, whose names
5 * are too numerous to list here. Please refer to the COPYRIGHT file
6 * distributed with this source distribution for a full listing.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include <fstream>
24 #include "TextureLoader.h"
26 using namespace std;
28 #include "ActionRecorder.h"
30 std::vector<Action> ActionRecorder::actions;
32 struct offset_subtract :
33 public unary_function<
34 Action, void >
36 offset_subtract(int b) : base(b) {}
37 int base;
38 void operator() (Action act) {
39 act.time_step -= base;
43 void ActionRecorder::gameFinish ( )
45 char file_name[256];
46 if(actions.size()==0) return;
47 int base_ts = actions[0].time_step;
48 for(size_t i = 0; i < actions.size(); ++i) {
49 actions[i].time_step -= base_ts;
51 TextureLoader::buildLocalDataFileName(GC_REPLAY_FILE_NAME, file_name);
52 ofstream mult(file_name);
53 if(!mult.fail()) {
54 size_t size = actions.size();
55 for (size_t i=0; i < size; ++i) {
56 mult << actions[i].name << "\n" << actions[i].time_step << endl;
58 mult.close();