Commit 4bca7986 authored by alistert's avatar alistert

Some overdue C++ising. Fixed multiplayer starting position.

parent ec9b06cc
...@@ -29,14 +29,6 @@ ...@@ -29,14 +29,6 @@
#include <SDL/SDL.h> #include <SDL/SDL.h>
// Constants
// Displayed statistics
#define S_NONE 0
#define S_PLAYERS 1
#define S_SCREEN 2
// Macros // Macros
// For converting between tile positions and int/fixed values // For converting between tile positions and int/fixed values
...@@ -46,7 +38,13 @@ ...@@ -46,7 +38,13 @@
#define TTOI(x) ((x) << 5) #define TTOI(x) ((x) << 5)
// Enum // Enums
enum LevelStats {
S_PLAYERS = 1, S_SCREEN = 2
};
enum LevelStage { enum LevelStage {
...@@ -60,7 +58,7 @@ enum LevelStage { ...@@ -60,7 +58,7 @@ enum LevelStage {
class BaseLevel { class BaseLevel {
protected: protected:
SDL_Surface *tileSet; SDL_Surface* tileSet;
SDL_Color palette[256]; SDL_Color palette[256];
unsigned int tickOffset, prevStepTicks, prevTicks, ticks; unsigned int tickOffset, prevStepTicks, prevTicks, ticks;
unsigned int endTime; unsigned int endTime;
......
...@@ -453,7 +453,7 @@ int Bonus::play () { ...@@ -453,7 +453,7 @@ int Bonus::play () {
pmessage = pmenu = false; pmessage = pmenu = false;
option = 0; option = 0;
stats = S_NONE; stats = 0;
returnTime = 0; returnTime = 0;
......
...@@ -33,10 +33,11 @@ ...@@ -33,10 +33,11 @@
#include "menu/menu.h" #include "menu/menu.h"
#include "player/player.h" #include "player/player.h"
#include <iostream>
#include <string.h> #include <string.h>
ClientGame::ClientGame (char *address) { ClientGame::ClientGame (char* address) {
unsigned char buffer[BUFFER_LENGTH]; unsigned char buffer[BUFFER_LENGTH];
unsigned int timeout; unsigned int timeout;
...@@ -106,7 +107,7 @@ ClientGame::ClientGame (char *address) { ...@@ -106,7 +107,7 @@ ClientGame::ClientGame (char *address) {
} }
printf("Connected to server (version %d).\n", buffer[2]); std::cout << "Connected to server (version " << int(buffer[2]) << ").\n";
// Copy game parameters // Copy game parameters
mode = GameModeType(buffer[3]); mode = GameModeType(buffer[3]);
...@@ -115,8 +116,8 @@ ClientGame::ClientGame (char *address) { ...@@ -115,8 +116,8 @@ ClientGame::ClientGame (char *address) {
nPlayers = buffer[6]; nPlayers = buffer[6];
clientID = buffer[7]; clientID = buffer[7];
printf("Game mode %d, difficulty %d, %d of %d players.\n", mode, std::cout << "Game mode " << mode << ", difficulty " << difficulty << ", " <<
difficulty, nPlayers, maxPlayers); nPlayers << " of " << maxPlayers << " players.\n";
if (nPlayers > maxPlayers) { if (nPlayers > maxPlayers) {
...@@ -243,7 +244,7 @@ ClientGame::~ClientGame () { ...@@ -243,7 +244,7 @@ ClientGame::~ClientGame () {
} }
int ClientGame::setLevel (char *fileName) { int ClientGame::setLevel (char* fileName) {
int ret; int ret;
...@@ -300,7 +301,7 @@ int ClientGame::setLevel (char *fileName) { ...@@ -300,7 +301,7 @@ int ClientGame::setLevel (char *fileName) {
} }
void ClientGame::send (unsigned char *buffer) { void ClientGame::send (unsigned char* buffer) {
net->send(sock, buffer); net->send(sock, buffer);
...@@ -397,19 +398,18 @@ int ClientGame::step (unsigned int ticks) { ...@@ -397,19 +398,18 @@ int ClientGame::step (unsigned int ticks) {
if ((recvBuffer[1] == MT_G_PJOIN) && if ((recvBuffer[1] == MT_G_PJOIN) &&
(recvBuffer[3] < maxPlayers)) { (recvBuffer[3] < maxPlayers)) {
printf("Player %d joined the game.\n", recvBuffer[3]); std::cout << "Player " << int(recvBuffer[3]) << " joined the game.\n";
// Add the new player, and any that have been missed // Add the new player, and any that have been missed
for (count = nPlayers; count <= recvBuffer[3]; count++) for (count = nPlayers; count <= recvBuffer[3]; count++) {
{
players[count].init((char *)recvBuffer + 9, players[count].init((char *)recvBuffer + 9,
recvBuffer + 5, recvBuffer[4]); recvBuffer + 5, recvBuffer[4]);
players[count].reset(); resetPlayer(players + count, false);
printf("Player %d joined team %d.\n", std::cout << "Player " << count << " joined team " <<
count, recvBuffer[4]); recvBuffer[4] << ".\n";
} }
...@@ -423,7 +423,7 @@ int ClientGame::step (unsigned int ticks) { ...@@ -423,7 +423,7 @@ int ClientGame::step (unsigned int ticks) {
if ((recvBuffer[1] == MT_G_PQUIT) && if ((recvBuffer[1] == MT_G_PQUIT) &&
(recvBuffer[2] < nPlayers)) { (recvBuffer[2] < nPlayers)) {
printf("Player %d left the game.\n", recvBuffer[2]); std::cout << "Player " << int(recvBuffer[2]) << " left the game.\n";
// Remove the player // Remove the player
......
...@@ -107,7 +107,7 @@ int Game::setBonus (int ext) { ...@@ -107,7 +107,7 @@ int Game::setBonus (int ext) {
if (bonusFile) delete[] bonusFile; if (bonusFile) delete[] bonusFile;
if (level != NULL) bonusFile = createFileName(F_BONUSMAP, ext); if (ext >= 0) bonusFile = createFileName(F_BONUSMAP, ext);
else bonusFile = NULL; else bonusFile = NULL;
return E_NONE; return E_NONE;
......
...@@ -32,10 +32,11 @@ ...@@ -32,10 +32,11 @@
#include "level/level.h" #include "level/level.h"
#include "player/player.h" #include "player/player.h"
#include <iostream>
#include <string.h> #include <string.h>
ServerGame::ServerGame (GameModeType mode, char *firstLevel, int gameDifficulty) { ServerGame::ServerGame (GameModeType mode, char* firstLevel, int gameDifficulty) {
int count; int count;
...@@ -104,9 +105,9 @@ ServerGame::~ServerGame () { ...@@ -104,9 +105,9 @@ ServerGame::~ServerGame () {
} }
int ServerGame::setLevel (char *fileName) { int ServerGame::setLevel (char* fileName) {
File *file; File* file;
int count; int count;
if (levelFile) delete[] levelFile; if (levelFile) delete[] levelFile;
...@@ -161,7 +162,7 @@ int ServerGame::setLevel (char *fileName) { ...@@ -161,7 +162,7 @@ int ServerGame::setLevel (char *fileName) {
} }
void ServerGame::send (unsigned char *buffer) { void ServerGame::send (unsigned char* buffer) {
int count; int count;
...@@ -247,8 +248,8 @@ int ServerGame::step (unsigned int ticks) { ...@@ -247,8 +248,8 @@ int ServerGame::step (unsigned int ticks) {
if ((recvBuffers[count][1] == MT_G_PJOIN) && if ((recvBuffers[count][1] == MT_G_PJOIN) &&
(clientPlayer[count] == -1)) { (clientPlayer[count] == -1)) {
printf("Player %d (client %d) joined the game.\n", std::cout << "Player " << nPlayers << " (client " <<
nPlayers, count); count <<") joined the game.\n";
// Set up the new player // Set up the new player
...@@ -260,8 +261,8 @@ int ServerGame::step (unsigned int ticks) { ...@@ -260,8 +261,8 @@ int ServerGame::step (unsigned int ticks) {
recvBuffers[count][4]); recvBuffers[count][4]);
players[nPlayers].reset(); players[nPlayers].reset();
printf("Player %d joined team %d.\n", std::cout << "Player " << nPlayers << " joined team " <<
nPlayers, recvBuffers[count][4]); recvBuffers[count][4] << ".\n";
recvBuffers[count][3] = clientPlayer[count] = recvBuffers[count][3] = clientPlayer[count] =
nPlayers; nPlayers;
...@@ -329,7 +330,7 @@ int ServerGame::step (unsigned int ticks) { ...@@ -329,7 +330,7 @@ int ServerGame::step (unsigned int ticks) {
if (clientSock[count] != -1) { if (clientSock[count] != -1) {
printf("Client %d connected.\n", count); std::cout << "Client " << count << " connected.\n";
clientPlayer[count] = -1; clientPlayer[count] = -1;
received[count] = 0; received[count] = 0;
...@@ -350,6 +351,13 @@ int ServerGame::step (unsigned int ticks) { ...@@ -350,6 +351,13 @@ int ServerGame::step (unsigned int ticks) {
// Initiate sending of level data // Initiate sending of level data
clientStatus[count] = 0; clientStatus[count] = 0;
// Inform the new client of the checkpoint
sendBuffer[0] = MTL_G_CHECK;
sendBuffer[1] = MT_G_CHECK;
sendBuffer[2] = checkX;
sendBuffer[3] = checkY;
net->send(clientSock[count], sendBuffer);
// Inform the new client of the existing players // Inform the new client of the existing players
sendBuffer[1] = MT_G_PJOIN; sendBuffer[1] = MT_G_PJOIN;
...@@ -377,8 +385,8 @@ int ServerGame::step (unsigned int ticks) { ...@@ -377,8 +385,8 @@ int ServerGame::step (unsigned int ticks) {
if (!(net->isConnected(clientSock[count]))) { if (!(net->isConnected(clientSock[count]))) {
printf("Client %d disconnected (code: %d).\n", count, std::cout << "Client " << count << " disconnected (code: " <<
net->getError()); net->getError() << ").\n";
// Disconnect client // Disconnect client
net->close(clientSock[count]); net->close(clientSock[count]);
...@@ -388,8 +396,8 @@ int ServerGame::step (unsigned int ticks) { ...@@ -388,8 +396,8 @@ int ServerGame::step (unsigned int ticks) {
// Remove the client's player // Remove the client's player
printf("Player %d (client %d) left the game.\n", std::cout << "Player " << clientPlayer[count] <<
clientPlayer[count], count); " (client " << count << ") left the game.\n";
nPlayers--; nPlayers--;
...@@ -475,16 +483,12 @@ void ServerGame::setCheckpoint (unsigned char gridX, unsigned char gridY) { ...@@ -475,16 +483,12 @@ void ServerGame::setCheckpoint (unsigned char gridX, unsigned char gridY) {
unsigned char buffer[MTL_G_CHECK]; unsigned char buffer[MTL_G_CHECK];
if (gameMode) {
buffer[0] = MTL_G_CHECK; buffer[0] = MTL_G_CHECK;
buffer[1] = MT_G_CHECK; buffer[1] = MT_G_CHECK;
buffer[2] = gridX; buffer[2] = gridX;
buffer[3] = gridY; buffer[3] = gridY;
send(buffer); send(buffer);
}
checkX = gridX; checkX = gridX;
checkY = gridY; checkY = gridY;
......
...@@ -25,9 +25,9 @@ ...@@ -25,9 +25,9 @@
#include "io/gfx/video.h" #include "io/gfx/video.h"
File::File (const char * name, bool write) { File::File (const char* name, bool write) {
Path *path; Path* path;
// Try opening the file from all the available directories // Try opening the file from all the available directories
...@@ -49,9 +49,11 @@ File::File (const char * name, bool write) { ...@@ -49,9 +49,11 @@ File::File (const char * name, bool write) {
File::~File () { File::~File () {
fclose(f); stream.close();
LOG("Closed file", filePath); #ifdef VERBOSE
log("Closed file", filePath);
#endif
delete[] filePath; delete[] filePath;
...@@ -60,17 +62,20 @@ File::~File () { ...@@ -60,17 +62,20 @@ File::~File () {
} }
bool File::open (const char * path, const char * name, bool write) { bool File::open (const char* path, const char* name, bool write) {
// Create the file path for the given directory // Create the file path for the given directory
filePath = createString(path, name); filePath = createString(path, name);
// Open the file from the path // Open the file from the path
f = fopen(filePath, write ? "wb": "rb"); stream.clear();
stream.open(filePath, (write ? std::ios::out: std::ios::in) | std::ios::binary);
if (f) { if (stream.is_open() && stream.good()) {
LOG("Opened file", filePath); #ifdef VERBOSE
log("Opened file", filePath);
#endif
return true; return true;
...@@ -87,13 +92,13 @@ int File::getSize () { ...@@ -87,13 +92,13 @@ int File::getSize () {
int pos, size; int pos, size;
pos = ftell(f); pos = stream.tellg();
fseek(f, 0, SEEK_END); stream.seekg(0, std::ios::end);
size = ftell(f); size = stream.tellg();
fseek(f, pos, SEEK_SET); stream.seekg(pos, std::ios::beg);
return size; return size;
...@@ -101,13 +106,13 @@ int File::getSize () { ...@@ -101,13 +106,13 @@ int File::getSize () {
int File::tell () { int File::tell () {
return ftell(f); return stream.tellg();
} }
void File::seek (int offset, bool reset) { void File::seek (int offset, bool reset) {
fseek(f, offset, reset ? SEEK_SET: SEEK_CUR); stream.seekg(offset, reset ? std::ios::beg: std::ios::cur);
return; return;
...@@ -115,14 +120,14 @@ void File::seek (int offset, bool reset) { ...@@ -115,14 +120,14 @@ void File::seek (int offset, bool reset) {
unsigned char File::loadChar () { unsigned char File::loadChar () {
return fgetc(f); return stream.get();
} }
void File::storeChar (unsigned char val) { void File::storeChar (unsigned char val) {
fputc(val, f); stream.put(val);
return; return;
...@@ -133,8 +138,8 @@ unsigned short int File::loadShort () { ...@@ -133,8 +138,8 @@ unsigned short int File::loadShort () {
unsigned short int val; unsigned short int val;
val = fgetc(f); val = stream.get();
val += fgetc(f) << 8; val += stream.get() << 8;
return val; return val;
...@@ -143,8 +148,8 @@ unsigned short int File::loadShort () { ...@@ -143,8 +148,8 @@ unsigned short int File::loadShort () {
void File::storeShort (unsigned short int val) { void File::storeShort (unsigned short int val) {
fputc(val & 255, f); stream.put(val & 255);
fputc(val >> 8, f); stream.put(val >> 8);
return; return;
...@@ -155,10 +160,10 @@ signed long int File::loadInt () { ...@@ -155,10 +160,10 @@ signed long int File::loadInt () {
unsigned long int val; unsigned long int val;
val = fgetc(f); val = stream.get();
val += fgetc(f) << 8; val += stream.get() << 8;
val += fgetc(f) << 16; val += stream.get() << 16;
val += fgetc(f) << 24; val += stream.get() << 24;
return *((signed long int *)&val); return *((signed long int *)&val);
...@@ -171,38 +176,38 @@ void File::storeInt (signed long int val) { ...@@ -171,38 +176,38 @@ void File::storeInt (signed long int val) {
uval = *((unsigned long int *)&val); uval = *((unsigned long int *)&val);
fputc(uval & 255, f); stream.put(uval & 255);
fputc((uval >> 8) & 255, f); stream.put((uval >> 8) & 255);
fputc((uval >> 16) & 255, f); stream.put((uval >> 16) & 255);
fputc(uval >> 24, f); stream.put(uval >> 24);
return; return;
} }
unsigned char * File::loadBlock (int length) { unsigned char* File::loadBlock (int length) {
unsigned char *buffer; unsigned char *buffer;
buffer = new unsigned char[length]; buffer = new unsigned char[length];
fread(buffer, 1, length, f); stream.read((char *)buffer, length);
return buffer; return buffer;
} }
unsigned char * File::loadRLE (int length) { unsigned char* File::loadRLE (int length) {
unsigned char *buffer; unsigned char* buffer;
int rle, pos, byte, count, next; int rle, pos, byte, count, next;
// Determine the offset that follows the block // Determine the offset that follows the block
next = fgetc(f); next = stream.get();
next += fgetc(f) << 8; next += stream.get() << 8;
next += ftell(f); next += stream.tellg();
buffer = new unsigned char[length]; buffer = new unsigned char[length];
...@@ -210,11 +215,11 @@ unsigned char * File::loadRLE (int length) { ...@@ -210,11 +215,11 @@ unsigned char * File::loadRLE (int length) {
while (pos < length) { while (pos < length) {
rle = fgetc(f); rle = stream.get();
if (rle & 128) { if (rle & 128) {
byte = fgetc(f); byte = stream.get();
for (count = 0; count < (rle & 127); count++) { for (count = 0; count < (rle & 127); count++) {
...@@ -227,16 +232,16 @@ unsigned char * File::loadRLE (int length) { ...@@ -227,16 +232,16 @@ unsigned char * File::loadRLE (int length) {
for (count = 0; count < rle; count++) { for (count = 0; count < rle; count++) {
buffer[pos++] = fgetc(f); buffer[pos++] = stream.get();
if (pos >= length) break; if (pos >= length) break;
} }
} else buffer[pos++] = fgetc(f); } else buffer[pos++] = stream.get();
} }
fseek(f, next, SEEK_SET); stream.seekg(next, std::ios::beg);
return buffer; return buffer;
...@@ -247,27 +252,27 @@ void File::skipRLE () { ...@@ -247,27 +252,27 @@ void File::skipRLE () {
int next; int next;
next = fgetc(f); next = stream.get();
next += fgetc(f) << 8; next += stream.get() << 8;
fseek(f, next, SEEK_CUR); stream.seekg(next, std::ios::cur);
return; return;
} }
char * File::loadString () { char* File::loadString () {
char *string; char* string;
int length, count; int length, count;
length = fgetc(f); length = stream.get();
if (length) { if (length) {
string = new char[length + 1]; string = new char[length + 1];
fread(string, 1, length, f); stream.read(string, length);
} else { } else {
...@@ -276,13 +281,13 @@ char * File::loadString () { ...@@ -276,13 +281,13 @@ char * File::loadString () {
for (count = 0; count < 9; count++) { for (count = 0; count < 9; count++) {
string[count] = fgetc(f); string[count] = stream.get();
if (string[count] == '.') { if (string[count] == '.') {
string[++count] = fgetc(f); string[++count] = stream.get();
string[++count] = fgetc(f); string[++count] = stream.get();
string[++count] = fgetc(f); string[++count] = stream.get();
count++; count++;
break; break;
...@@ -301,10 +306,10 @@ char * File::loadString () { ...@@ -301,10 +306,10 @@ char * File::loadString () {
} }
SDL_Surface * File::loadSurface (int width, int height) { SDL_Surface* File::loadSurface (int width, int height) {
SDL_Surface *surface; SDL_Surface* surface;
unsigned char *pixels; unsigned char* pixels;
pixels = loadRLE(width * height); pixels = loadRLE(width * height);
...@@ -317,9 +322,9 @@ SDL_Surface * File::loadSurface (int width, int height) { ...@@ -317,9 +322,9 @@ SDL_Surface * File::loadSurface (int width, int height) {
} }
void File::loadPalette (SDL_Color *palette) { void File::loadPalette (SDL_Color* palette) {
unsigned char *buffer; unsigned char* buffer;
int count; int count;
buffer = loadRLE(768); buffer = loadRLE(768);
...@@ -341,7 +346,7 @@ void File::loadPalette (SDL_Color *palette) { ...@@ -341,7 +346,7 @@ void File::loadPalette (SDL_Color *palette) {
} }
Path::Path (Path *newNext, char *newPath) { Path::Path (Path* newNext, char* newPath) {
next = newNext; next = newNext;
path = newPath; path = newPath;
......
...@@ -27,21 +27,21 @@ ...@@ -27,21 +27,21 @@
#include "OpenJazz.h" #include "OpenJazz.h"
#include <SDL/SDL.h> #include <SDL/SDL.h>
#include <stdio.h> #include <fstream>
// Class // Classes
class File { class File {
private: private:
FILE *f; std::fstream stream;
char *filePath; char* filePath;
bool open (const char * path, const char * name, bool write); bool open (const char* path, const char* name, bool write);
public: public:
File (const char * name, bool write); File (const char* name, bool write);
~File (); ~File ();
int getSize (); int getSize ();
...@@ -53,11 +53,11 @@ class File { ...@@ -53,11 +53,11 @@ class File {
void storeShort (unsigned short int val); void storeShort (unsigned short int val);
signed long int loadInt (); signed long int loadInt ();
void storeInt (signed long int val); void storeInt (signed long int val);
unsigned char * loadBlock (int length); unsigned char* loadBlock (int length);
unsigned char * loadRLE (int length); unsigned char* loadRLE (int length);
void skipRLE (); void skipRLE ();
char * loadString (); char* loadString ();
SDL_Surface * loadSurface (int width, int height); SDL_Surface* loadSurface (int width, int height);
void loadPalette (SDL_Color *palette); void loadPalette (SDL_Color *palette);
}; };
...@@ -65,10 +65,10 @@ class File { ...@@ -65,10 +65,10 @@ class File {
class Path { class Path {
public: public:
Path *next; Path* next;
char *path; char* path;
Path (Path *newNext, char *newPath); Path (Path* newNext, char* newPath);
~Path (); ~Path ();
}; };
...@@ -77,7 +77,7 @@ class Path { ...@@ -77,7 +77,7 @@ class Path {
// Variable // Variable
// Paths to files // Paths to files
EXTERN Path *firstPath; EXTERN Path* firstPath;
#endif #endif
...@@ -33,10 +33,11 @@ ...@@ -33,10 +33,11 @@
#include <string.h> #include <string.h>
Font::Font (const char * fileName) { Font::Font (const char* fileName) {
File *file; File* file;
unsigned char *pixels, *blank; unsigned char* pixels;
unsigned char* blank;
int fileSize; int fileSize;
int count, size, width, height; int count, size, width, height;
...@@ -71,8 +72,6 @@ Font::Font (const char * fileName) { ...@@ -71,8 +72,6 @@ Font::Font (const char * fileName) {
for (count = 0; count < 128; count++) { for (count = 0; count < 128; count++) {
size = file->loadShort();
if (file->tell() >= fileSize) { if (file->tell() >= fileSize) {
nCharacters = count; nCharacters = count;
...@@ -81,6 +80,8 @@ Font::Font (const char * fileName) { ...@@ -81,6 +80,8 @@ Font::Font (const char * fileName) {
} }
size = file->loadShort();
if (size) { if (size) {
pixels = file->loadRLE(size); pixels = file->loadRLE(size);
...@@ -147,9 +148,9 @@ Font::Font (const char * fileName) { ...@@ -147,9 +148,9 @@ Font::Font (const char * fileName) {
} }
Font::Font (unsigned char *pixels, bool big) { Font::Font (unsigned char* pixels, bool big) {
unsigned char *chrPixels; unsigned char* chrPixels;
int count, y; int count, y;
if (big) lineHeight = 8; if (big) lineHeight = 8;
...@@ -207,8 +208,9 @@ Font::Font (unsigned char *pixels, bool big) { ...@@ -207,8 +208,9 @@ Font::Font (unsigned char *pixels, bool big) {
Font::Font () { Font::Font () {
File *file; File* file;
unsigned char *pixels, *sorted; unsigned char* pixels;
unsigned char* sorted;
int fileSize; int fileSize;
int count, width, height; int count, width, height;
...@@ -234,11 +236,6 @@ Font::Font () { ...@@ -234,11 +236,6 @@ Font::Font () {
for (count = 0; count < nCharacters; count++) { for (count = 0; count < nCharacters; count++) {
width = file->loadShort() << 2;
height = file->loadShort();
file->seek(4, false);
if (file->tell() >= fileSize) { if (file->tell() >= fileSize) {
nCharacters = count; nCharacters = count;
...@@ -247,6 +244,11 @@ Font::Font () { ...@@ -247,6 +244,11 @@ Font::Font () {
} }
width = file->loadShort() << 2;
height = file->loadShort();
file->seek(4, false);
pixels = file->loadBlock(width * height); pixels = file->loadBlock(width * height);
sorted = sortPixels(pixels, width * height); sorted = sortPixels(pixels, width * height);
...@@ -308,9 +310,9 @@ Font::~Font () { ...@@ -308,9 +310,9 @@ Font::~Font () {
} }
int Font::showString (const char *string, int x, int y) { int Font::showString (const char* string, int x, int y) {
SDL_Surface *surface; SDL_Surface* surface;
SDL_Rect dst; SDL_Rect dst;
unsigned int count; unsigned int count;
int xOffset, yOffset; int xOffset, yOffset;
...@@ -350,9 +352,9 @@ int Font::showString (const char *string, int x, int y) { ...@@ -350,9 +352,9 @@ int Font::showString (const char *string, int x, int y) {
} }
int Font::showSceneString (const unsigned char *string, int x, int y) { int Font::showSceneString (const unsigned char* string, int x, int y) {
SDL_Surface *surface; SDL_Surface* surface;
SDL_Rect dst; SDL_Rect dst;
unsigned int count; unsigned int count;
int offset; int offset;
......
...@@ -37,10 +37,10 @@ ...@@ -37,10 +37,10 @@
#include "player/player.h" #include "player/player.h"
DemoLevel::DemoLevel (const char *fileName) { DemoLevel::DemoLevel (const char* fileName) {
File *file; File* file;
char *levelFile; char* levelFile;
int lNum, wNum, diff, ret; int lNum, wNum, diff, ret;
gameMode = NULL; gameMode = NULL;
...@@ -101,7 +101,7 @@ int DemoLevel::play () { ...@@ -101,7 +101,7 @@ int DemoLevel::play () {
ticks = 16; ticks = 16;
prevStepTicks = 0; prevStepTicks = 0;
stats = S_NONE; stats = 0;
usePalette(palette); usePalette(palette);
......
...@@ -65,7 +65,7 @@ Level::Level () { ...@@ -65,7 +65,7 @@ Level::Level () {
} }
Level::Level (char *fileName, unsigned char diff, bool checkpoint) { Level::Level (char* fileName, unsigned char diff, bool checkpoint) {
int ret; int ret;
...@@ -228,7 +228,7 @@ void Level::setTile (unsigned char gridX, unsigned char gridY, ...@@ -228,7 +228,7 @@ void Level::setTile (unsigned char gridX, unsigned char gridY,
} }
signed char * Level::getEvent (unsigned char gridX, unsigned char gridY) { signed char* Level::getEvent (unsigned char gridX, unsigned char gridY) {
int event = grid[gridY][gridX].event; int event = grid[gridY][gridX].event;
...@@ -281,9 +281,9 @@ void Level::clearEvent (unsigned char gridX, unsigned char gridY) { ...@@ -281,9 +281,9 @@ void Level::clearEvent (unsigned char gridX, unsigned char gridY) {
} }
int Level::hitEvent (unsigned char gridX, unsigned char gridY, Player *source) { int Level::hitEvent (unsigned char gridX, unsigned char gridY, Player* source) {
GridElement *ge; GridElement* ge;
unsigned char buffer[MTL_L_GRID]; unsigned char buffer[MTL_L_GRID];
int hitsToKill; int hitsToKill;
...@@ -341,28 +341,28 @@ void Level::setEventTime (unsigned char gridX, unsigned char gridY, ...@@ -341,28 +341,28 @@ void Level::setEventTime (unsigned char gridX, unsigned char gridY,
} }
signed char * Level::getBullet (unsigned char bullet) { signed char* Level::getBullet (unsigned char bullet) {
return bulletSet[bullet]; return bulletSet[bullet];
} }
Sprite * Level::getSprite (unsigned char sprite) { Sprite* Level::getSprite (unsigned char sprite) {
return spriteSet + sprite; return spriteSet + sprite;
} }
Anim * Level::getAnim (unsigned char anim) { Anim* Level::getAnim (unsigned char anim) {
return animSet + anim; return animSet + anim;
} }
Anim * Level::getMiscAnim (unsigned char anim) { Anim* Level::getMiscAnim (unsigned char anim) {
return animSet + miscAnims[anim]; return animSet + miscAnims[anim];
...@@ -437,7 +437,7 @@ LevelStage Level::getStage () { ...@@ -437,7 +437,7 @@ LevelStage Level::getStage () {
} }
Scene * Level::createScene () { Scene* Level::createScene () {
try { try {
...@@ -452,7 +452,7 @@ Scene * Level::createScene () { ...@@ -452,7 +452,7 @@ Scene * Level::createScene () {
} }
void Level::receive (unsigned char *buffer) { void Level::receive (unsigned char* buffer) {
// Interpret data received from client/server // Interpret data received from client/server
...@@ -503,7 +503,7 @@ void Level::receive (unsigned char *buffer) { ...@@ -503,7 +503,7 @@ void Level::receive (unsigned char *buffer) {
int Level::play () { int Level::play () {
const char *options[5] = const char* options[5] =
{"continue game", "save game", "load game", "setup options", "quit game"}; {"continue game", "save game", "load game", "setup options", "quit game"};
PaletteEffect *levelPE; PaletteEffect *levelPE;
char *string; char *string;
...@@ -521,7 +521,7 @@ int Level::play () { ...@@ -521,7 +521,7 @@ int Level::play () {
pmessage = pmenu = false; pmessage = pmenu = false;
option = 0; option = 0;
stats = S_NONE; stats = 0;
returnTime = 0; returnTime = 0;
timeBonus = -1; timeBonus = -1;
......
...@@ -344,7 +344,7 @@ int Menu::joinGame () { ...@@ -344,7 +344,7 @@ int Menu::joinGame () {
int ret; int ret;
ret = textInput("ip address:", &netAddress); ret = textInput("ip address:", netAddress);
if (ret < 0) return ret; if (ret < 0) return ret;
......
...@@ -78,7 +78,7 @@ int Menu::main () { ...@@ -78,7 +78,7 @@ int Menu::main () {
#if (defined USE_SOCKETS) || (defined USE_SDL_NET) #if (defined USE_SOCKETS) || (defined USE_SDL_NET)
while (true) { while (true) {
ret = generic(newGameOptions, 6, &suboption); ret = generic(newGameOptions, 6, suboption);
if (ret == E_QUIT) return E_QUIT; if (ret == E_QUIT) return E_QUIT;
if (ret < 0) break; if (ret < 0) break;
......
...@@ -41,13 +41,13 @@ ...@@ -41,13 +41,13 @@
class Menu { class Menu {
private: private:
SDL_Surface *screens[15]; SDL_Surface* screens[15];
int episodes; int episodes;
unsigned char difficulty; unsigned char difficulty;
int message (const char *text); int message (const char* text);
int generic (const char **optionNames, int options, int *chosen); int generic (const char** optionNames, int options, int& chosen);
int textInput (const char *request, char **text); int textInput (const char* request, char*& text);
int newGameDifficulty (GameModeType mode, int levelNum, int worldNum); int newGameDifficulty (GameModeType mode, int levelNum, int worldNum);
int newGameLevel (GameModeType mode); int newGameLevel (GameModeType mode);
int newGameEpisode (GameModeType mode); int newGameEpisode (GameModeType mode);
...@@ -75,7 +75,7 @@ class Menu { ...@@ -75,7 +75,7 @@ class Menu {
// Variable // Variable
EXTERN Menu *menu; EXTERN Menu* menu;
#endif #endif
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include <string.h> #include <string.h>
int Menu::message (const char *text) { int Menu::message (const char* text) {
// Display a message to the user // Display a message to the user
...@@ -62,7 +62,7 @@ int Menu::message (const char *text) { ...@@ -62,7 +62,7 @@ int Menu::message (const char *text) {
} }
int Menu::generic (const char **optionNames, int options, int *chosen) { int Menu::generic (const char** optionNames, int options, int& chosen) {
// Let the user select from a menu of the given options // Let the user select from a menu of the given options
...@@ -70,7 +70,7 @@ int Menu::generic (const char **optionNames, int options, int *chosen) { ...@@ -70,7 +70,7 @@ int Menu::generic (const char **optionNames, int options, int *chosen) {
usePalette(palettes[1]); usePalette(palettes[1]);
if (*chosen >= options) *chosen = 0; if (chosen >= options) chosen = 0;
while (true) { while (true) {
...@@ -84,18 +84,18 @@ int Menu::generic (const char **optionNames, int options, int *chosen) { ...@@ -84,18 +84,18 @@ int Menu::generic (const char **optionNames, int options, int *chosen) {
for (count = 0; count < options; count++) { for (count = 0; count < options; count++) {
if (count == *chosen) fontmn2->mapPalette(240, 8, 114, 16); if (count == chosen) fontmn2->mapPalette(240, 8, 114, 16);
fontmn2->showString(optionNames[count], canvasW >> 2, fontmn2->showString(optionNames[count], canvasW >> 2,
(canvasH >> 1) + (count << 4) - (options << 3)); (canvasH >> 1) + (count << 4) - (options << 3));
if (count == *chosen) fontmn2->restorePalette(); if (count == chosen) fontmn2->restorePalette();
} }
if (controls.release(C_UP)) *chosen = (*chosen + options - 1) % options; if (controls.release(C_UP)) chosen = (chosen + options - 1) % options;
if (controls.release(C_DOWN)) *chosen = (*chosen + 1) % options; if (controls.release(C_DOWN)) chosen = (chosen + 1) % options;
if (controls.release(C_ENTER)) { if (controls.release(C_ENTER)) {
...@@ -112,7 +112,7 @@ int Menu::generic (const char **optionNames, int options, int *chosen) { ...@@ -112,7 +112,7 @@ int Menu::generic (const char **optionNames, int options, int *chosen) {
} }
int Menu::textInput (const char *request, char **text) { int Menu::textInput (const char* request, char*& text) {
// Let the user to edit a text string // Let the user to edit a text string
...@@ -121,7 +121,7 @@ int Menu::textInput (const char *request, char **text) { ...@@ -121,7 +121,7 @@ int Menu::textInput (const char *request, char **text) {
unsigned int cursor; unsigned int cursor;
// Create input string // Create input string
input = createEditableString(*text); input = createEditableString(text);
cursor = strlen(input); cursor = strlen(input);
...@@ -218,8 +218,8 @@ int Menu::textInput (const char *request, char **text) { ...@@ -218,8 +218,8 @@ int Menu::textInput (const char *request, char **text) {
playSound(S_ORB); playSound(S_ORB);
// Replace the original string with the input string // Replace the original string with the input string
delete[] *text; delete[] text;
*text = input; text = input;
return E_NONE; return E_NONE;
......
...@@ -511,7 +511,7 @@ int Menu::setup () { ...@@ -511,7 +511,7 @@ int Menu::setup () {
while (true) { while (true) {
ret = generic(setupOptions, 6, &option); ret = generic(setupOptions, 6, option);
if (ret == E_UNUSED) return E_NONE; if (ret == E_UNUSED) return E_NONE;
if (ret < 0) return ret; if (ret < 0) return ret;
...@@ -524,7 +524,7 @@ int Menu::setup () { ...@@ -524,7 +524,7 @@ int Menu::setup () {
while (true) { while (true) {
ret = generic(setupCharacterOptions, 5, &suboption); ret = generic(setupCharacterOptions, 5, suboption);
if (ret == E_QUIT) return E_QUIT; if (ret == E_QUIT) return E_QUIT;
if (ret < 0) break; if (ret < 0) break;
...@@ -533,15 +533,14 @@ int Menu::setup () { ...@@ -533,15 +533,14 @@ int Menu::setup () {
case 0: // Character name case 0: // Character name
textInput("character name:", &characterName); textInput("character name:", characterName);
break; break;
default: // Character colour default: // Character colour
subsuboption = 0; subsuboption = 0;
ret = generic(setupCharacterColOptions, 8, ret = generic(setupCharacterColOptions, 8, subsuboption);
&subsuboption);
if (ret == E_QUIT) return E_QUIT; if (ret == E_QUIT) return E_QUIT;
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#define _SCENE_H #define _SCENE_H
#include <io/file.h> #include "io/file.h"
#include <SDL/SDL.h> #include <SDL/SDL.h>
...@@ -67,7 +67,7 @@ class Font; ...@@ -67,7 +67,7 @@ class Font;
class SceneText { class SceneText {
public: public:
unsigned char *text; unsigned char* text;
int alignment; int alignment;
int fontId; int fontId;
int x; int x;
...@@ -92,7 +92,7 @@ class ScenePage { ...@@ -92,7 +92,7 @@ class ScenePage {
int pageTime; int pageTime;
SceneText texts[100]; SceneText texts[100];
int nTexts; int nTexts;
char *musicFile; char* musicFile;
int paletteIndex; int paletteIndex;
ScenePage(); ScenePage();
...@@ -103,11 +103,11 @@ class ScenePage { ...@@ -103,11 +103,11 @@ class ScenePage {
class SceneImage { class SceneImage {
public: public:
SceneImage *next; SceneImage* next;
SDL_Surface *image; SDL_Surface* image;
int id; int id;
SceneImage (SceneImage *newNext); SceneImage (SceneImage* newNext);
~SceneImage (); ~SceneImage ();
}; };
...@@ -119,7 +119,7 @@ class ScenePalette { ...@@ -119,7 +119,7 @@ class ScenePalette {
SDL_Color palette[256]; SDL_Color palette[256];
int id; int id;
ScenePalette (ScenePalette *newNext); ScenePalette (ScenePalette* newNext);
~ScenePalette (); ~ScenePalette ();
}; };
...@@ -135,25 +135,25 @@ class SceneFont { ...@@ -135,25 +135,25 @@ class SceneFont {
class Scene { class Scene {
private: private:
SDL_Surface *background; SDL_Surface* background;
SceneImage *images; SceneImage* images;
ScenePalette *palettes; ScenePalette* palettes;
SceneFont fonts[5]; SceneFont fonts[5];
int nFonts; int nFonts;
unsigned short int scriptItems; unsigned short int scriptItems;
unsigned short int dataItems; unsigned short int dataItems;
signed long int *scriptStarts; signed long int* scriptStarts;
signed long int *dataOffsets; signed long int* dataOffsets;
// Scripts all information needed to render script pages, text etc // Scripts all information needed to render script pages, text etc
ScenePage *pages; ScenePage* pages;
void loadScripts (File *f); void loadScripts (File* f);
void loadData (File *f); void loadData (File* f);
void loadAni (File* f, int dataIndex); void loadAni (File* f, int dataIndex);
public: public:
Scene (const char * fileName); Scene (const char* fileName);
~Scene (); ~Scene ();
int play (); int play ();
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* Part of the OpenJazz project * Part of the OpenJazz project
* *
* *
* Copyright (c) 2005-2009 Alister Thomson * Copyright (c) 2005-2010 Alister Thomson
* *
* OpenJazz is distributed under the terms of * OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0 * the GNU General Public License, version 2.0
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "io/file.h" #include "io/file.h"
#include <iostream>
#include <string.h> #include <string.h>
...@@ -38,7 +39,9 @@ bool fileExists (const char * fileName) { ...@@ -38,7 +39,9 @@ bool fileExists (const char * fileName) {
File *file; File *file;
//printf("Check: "); #ifdef VERBOSE
std::cout << "Check: ";
#endif
try { try {
...@@ -151,7 +154,7 @@ char * createEditableString (const char *string) { ...@@ -151,7 +154,7 @@ char * createEditableString (const char *string) {
void log (const char *message) { void log (const char *message) {
printf("%s\n", message); std::cout << message << std::endl;
return; return;
...@@ -160,7 +163,7 @@ void log (const char *message) { ...@@ -160,7 +163,7 @@ void log (const char *message) {
void log (const char *message, const char *detail) { void log (const char *message, const char *detail) {
printf("%s: %s\n", message, detail); std::cout << message << ": " << detail << std::endl;
return; return;
...@@ -169,7 +172,7 @@ void log (const char *message, const char *detail) { ...@@ -169,7 +172,7 @@ void log (const char *message, const char *detail) {
void log (const char *message, int number) { void log (const char *message, int number) {
printf("%s: %d\n", message, number); std::cout << message << ": " << number << std::endl;
return; return;
...@@ -178,7 +181,7 @@ void log (const char *message, int number) { ...@@ -178,7 +181,7 @@ void log (const char *message, int number) {
void logError (const char *message, const char *detail) { void logError (const char *message, const char *detail) {
fprintf(stderr, "%s: %s\n", message, detail); std::cerr << message << ": " << detail << std::endl;
return; return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment