git repos / blockattack-game

blame: source/code/replay.h

normal view · raw

89c4a3a6 sago007 2008-08-29 14:32 1
/*
c53e6443 sago007 2012-04-17 11:04 2
===========================================================================
c53e6443 sago007 2012-04-17 11:04 3
blockattack - Block Attack - Rise of the Blocks
c53e6443 sago007 2012-04-17 11:04 4
Copyright (C) 2005-2012 Poul Sander
c53e6443 sago007 2012-04-17 11:04 5
c53e6443 sago007 2012-04-17 11:04 6
This program is free software: you can redistribute it and/or modify
c53e6443 sago007 2012-04-17 11:04 7
it under the terms of the GNU General Public License as published by
c53e6443 sago007 2012-04-17 11:04 8
the Free Software Foundation, either version 2 of the License, or
c53e6443 sago007 2012-04-17 11:04 9
(at your option) any later version.
c53e6443 sago007 2012-04-17 11:04 10
c53e6443 sago007 2012-04-17 11:04 11
This program is distributed in the hope that it will be useful,
c53e6443 sago007 2012-04-17 11:04 12
but WITHOUT ANY WARRANTY; without even the implied warranty of
c53e6443 sago007 2012-04-17 11:04 13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c53e6443 sago007 2012-04-17 11:04 14
GNU General Public License for more details.
c53e6443 sago007 2012-04-17 11:04 15
c53e6443 sago007 2012-04-17 11:04 16
You should have received a copy of the GNU General Public License
c53e6443 sago007 2012-04-17 11:04 17
along with this program.  If not, see http://www.gnu.org/licenses/
c53e6443 sago007 2012-04-17 11:04 18
c53e6443 sago007 2012-04-17 11:04 19
Source information and contacts persons can be found at
c53e6443 sago007 2012-04-17 11:04 20
http://blockattack.sf.net
c53e6443 sago007 2012-04-17 11:04 21
===========================================================================
89c4a3a6 sago007 2008-08-29 14:32 22
*/
89c4a3a6 sago007 2008-08-29 14:32 23
89c4a3a6 sago007 2008-08-29 14:32 24
//headerfile for replay.h
89c4a3a6 sago007 2008-08-29 14:32 25
/*
89c4a3a6 sago007 2008-08-29 14:32 26
replay is used to save a replay, there is saved 10 moves per second, should be
89c4a3a6 sago007 2008-08-29 14:32 27
able to give a realistic replay
89c4a3a6 sago007 2008-08-29 14:32 28
*/
89c4a3a6 sago007 2008-08-29 14:32 29
17916a2e sago007 2010-11-07 11:26 30
#ifndef REPLAY_H
17916a2e sago007 2010-11-07 11:26 31
#define REPLAY_H 1
17916a2e sago007 2010-11-07 11:26 32
89c4a3a6 sago007 2008-08-29 14:32 33
//constants - 3000 is 5 minutes
89c4a3a6 sago007 2008-08-29 14:32 34
#define FRAMESPERSEC 10
89c4a3a6 sago007 2008-08-29 14:32 35
89c4a3a6 sago007 2008-08-29 14:32 36
#include "SDL.h"
89c4a3a6 sago007 2008-08-29 14:32 37
#include <stdlib.h>
89c4a3a6 sago007 2008-08-29 14:32 38
#include <iostream>
89c4a3a6 sago007 2008-08-29 14:32 39
#include <fstream>
89c4a3a6 sago007 2008-08-29 14:32 40
#include <vector>
89c4a3a6 sago007 2008-08-29 14:32 41
89c4a3a6 sago007 2008-08-29 14:32 42
using namespace std;
89c4a3a6 sago007 2008-08-29 14:32 43
89c4a3a6 sago007 2008-08-29 14:32 44
//board_package, stores a board can be used for network play and replay
89c4a3a6 sago007 2008-08-29 14:32 45
struct boardPackage //92 bytes
89c4a3a6 sago007 2008-08-29 14:32 46
{
c53e6443 sago007 2012-04-17 11:04 47
	Uint32 time; //game time
c53e6443 sago007 2012-04-17 11:04 48
	Uint8 brick[6][13];
c53e6443 sago007 2012-04-17 11:04 49
	Uint8 pixels; //pixels pushed
c53e6443 sago007 2012-04-17 11:04 50
	Uint8 cursorX; //Cursor coordinate
c53e6443 sago007 2012-04-17 11:04 51
	Uint8 cursorY; // -||-
c53e6443 sago007 2012-04-17 11:04 52
	Uint32 score;
c53e6443 sago007 2012-04-17 11:04 53
	Uint8 speed;
c53e6443 sago007 2012-04-17 11:04 54
	Uint8 chain;
c53e6443 sago007 2012-04-17 11:04 55
	Uint8 result; //0=none,1=gameOver,2=winner,4=draw
89c4a3a6 sago007 2008-08-29 14:32 56
};
89c4a3a6 sago007 2008-08-29 14:32 57
d12916ab sago007 2012-04-19 23:30 58
struct Action
d12916ab sago007 2012-04-19 23:30 59
{
d12916ab sago007 2012-04-19 23:30 60
	Uint32 time;
6c9b4cd7 sago007 2012-05-01 19:34 61
	int action;
6c9b4cd7 sago007 2012-05-01 19:34 62
	string param;
d12916ab sago007 2012-04-19 23:30 63
};
d12916ab sago007 2012-04-19 23:30 64
c53e6443 sago007 2012-04-17 11:04 65
class Replay
c53e6443 sago007 2012-04-17 11:04 66
{
89c4a3a6 sago007 2008-08-29 14:32 67
private:
89c4a3a6 sago007 2008-08-29 14:32 68
//Our replay is stored in an array of TOTALFRAMES length
c53e6443 sago007 2012-04-17 11:04 69
	//boardPackage bps[TOTALFRAMES];
c53e6443 sago007 2012-04-17 11:04 70
	vector<boardPackage> bps;
d12916ab sago007 2012-04-19 23:30 71
	vector<Action> actions;
89c4a3a6 sago007 2008-08-29 14:32 72
//The final package is not set to any specific time
c53e6443 sago007 2012-04-17 11:04 73
	boardPackage finalPack;
89c4a3a6 sago007 2008-08-29 14:32 74
//We store number of frames, so we know how long to read the array
c53e6443 sago007 2012-04-17 11:04 75
	Uint32 nrOfFrames;
89c4a3a6 sago007 2008-08-29 14:32 76
//An enumerator, so we know how it ends! (should be removed then boardPackage is the 92 byte version)
c53e6443 sago007 2012-04-17 11:04 77
	enum { gameOver=0, winner, looser, draw } theResult;
89c4a3a6 sago007 2008-08-29 14:32 78
//If we are loaded from a file, then we are read only
c53e6443 sago007 2012-04-17 11:04 79
	bool isLoaded;
6c9b4cd7 sago007 2012-05-01 19:34 80
//Store player name
6c9b4cd7 sago007 2012-05-01 19:34 81
	string name;
c96f480e sago007 2009-03-28 18:59 82
89c4a3a6 sago007 2008-08-29 14:32 83
public:
c53e6443 sago007 2012-04-17 11:04 84
6c9b4cd7 sago007 2012-05-01 19:34 85
	
c53e6443 sago007 2012-04-17 11:04 86
c53e6443 sago007 2012-04-17 11:04 87
	Replay(); //Constructor
c53e6443 sago007 2012-04-17 11:04 88
	Replay(const Replay& r); //Copy constructor
c53e6443 sago007 2012-04-17 11:04 89
	Uint32 getNumberOfFrames(); //Returns number of frames
c53e6443 sago007 2012-04-17 11:04 90
	void setFrameSecTo(Uint32,boardPackage); //Sets frame at a given time to the package
c53e6443 sago007 2012-04-17 11:04 91
	void setFinalFrame(boardPackage,int); //Sets the final package
c53e6443 sago007 2012-04-17 11:04 92
	boardPackage getFrameSec(Uint32);  //Gets a frame to a time
c53e6443 sago007 2012-04-17 11:04 93
	boardPackage getFinalFrame(); //Gets the last frame, that must remain
c53e6443 sago007 2012-04-17 11:04 94
	int getFinalStatus();	//Return the result: winner, looser, draw or gameOver
c53e6443 sago007 2012-04-17 11:04 95
	bool isFinnished(Uint32); //Returns true if we are done
d12916ab sago007 2012-04-19 23:30 96
	
6c9b4cd7 sago007 2012-05-01 19:34 97
	//New replay type 2.0.0+:
6c9b4cd7 sago007 2012-05-01 19:34 98
	void addAction(int tick, int action, string param);
89c4a3a6 sago007 2008-08-29 14:32 99
89c4a3a6 sago007 2008-08-29 14:32 100
//Ok, I'll ignore this for some time, and just save to file, if however, we ever use a dynamic saving structure, we are fucked
c53e6443 sago007 2012-04-17 11:04 101
	bool saveReplay(string);	//Saves a replay
c53e6443 sago007 2012-04-17 11:04 102
	bool saveReplay(string,Replay p2); //saves a replay, plus another replay given as a parameter
c53e6443 sago007 2012-04-17 11:04 103
	bool loadReplay(string); //laods a replay
6c9b4cd7 sago007 2012-05-01 19:34 104
	bool loadReplay2(string);
6c9b4cd7 sago007 2012-05-01 19:34 105
    void setName(string name);
6c9b4cd7 sago007 2012-05-01 19:34 106
    string getName() const; //loads the second part of the replay file, if it exists, returns false otherwise
c96f480e sago007 2009-03-28 18:59 107
c96f480e sago007 2009-03-28 18:59 108
89c4a3a6 sago007 2008-08-29 14:32 109
};
17916a2e sago007 2010-11-07 11:26 110
17916a2e sago007 2010-11-07 11:26 111
#endif
1970-01-01 00:00 112