Each module now includes its own header first. Removed sstream.h and the definition...
[crack-attack.git] / src / ActionRecorder.cxx
blob56a89a61c692e067d0eb41e5228a5e7523b587be
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 "ActionRecorder.h"
25 #include <fstream>
27 #include "TextureLoader.h"
30 std::vector<Action> ActionRecorder::actions;
32 struct offset_subtract :
33 public std::unary_function< Action, void >
35 offset_subtract(int b) : base(b) {}
36 int base;
37 void operator() (Action act) {
38 act.time_step -= base;
42 void ActionRecorder::gameFinish ( )
44 char file_name[256];
45 if(actions.size()==0) return;
46 int base_ts = actions[0].time_step;
47 for(size_t i = 0; i < actions.size(); ++i) {
48 actions[i].time_step -= base_ts;
50 TextureLoader::buildLocalDataFileName(GC_REPLAY_FILE_NAME, file_name);
51 std::ofstream mult(file_name);
52 if(!mult.fail()) {
53 size_t size = actions.size();
54 for (size_t i=0; i < size; ++i) {
55 mult << actions[i].name << "\n" << actions[i].time_step << std::endl;
57 mult.close();