Commit 5802cf72 authored by Gerhard Stein's avatar Gerhard Stein

Fixed Typos and general cleanups, better variable names

parent 5707aec3
......@@ -144,7 +144,7 @@ bool CMapLoader::load( Uint8 episode, Uint8 level, const std::string& path, bool
if(mp_objvect && stategame == false)
{
std::vector<CObject*>::iterator obj = mp_objvect->begin();
std::vector<CSpriteObject*>::iterator obj = mp_objvect->begin();
for( ; obj != mp_objvect->end() ; obj++ )
{
delete *obj;
......@@ -316,7 +316,7 @@ void CMapLoader::addEnemyObject(unsigned int t, Uint16 x, Uint16 y, int episode,
}
else
{
CObject *enemyobject = NULL;
CSpriteObject *enemyobject = NULL;
switch(t)
{
......
......@@ -10,7 +10,7 @@
#include "CMap.h"
#include "CPlayer.h"
#include "CObject.h"
#include "CSpriteObject.h"
#include "options.h"
#include "sdl/music/CMusic.h"
#include "common/CBehaviorEngine.h"
......@@ -33,7 +33,7 @@ public:
bool m_checkpointset;
bool m_NessieAlreadySpawned;
std::vector<CObject*> *mp_objvect;
std::vector<CSpriteObject*> *mp_objvect;
private:
SmartPointer<CMap>& mpMap;
......
This diff is collapsed.
/*
* CObject.h
*
* Created on: 17.05.2009
* Author: gerstrong
*
* This class handles the objects like sprites that are draw on the screen
* It also handles the AI if any.
*/
#ifndef COBJECT_H_
#define COBJECT_H_
#include "engine/CEventContainer.h"
#include "ActionFormat.h"
#include "CVec.h"
#include "direction.h"
#include "CBehaviorEngine.h"
// structures for each AI module's data
#include "CMap.h"
#include "graphics/CGfxEngine.h"
#include "options.h"
#include "sdl/sound/CSound.h"
#include "CVec.h"
// Enumerations are here
#include "objenums.h"
#define SAFE_DELETE_ARRAY(x) if(x) { delete [] x; x = NULL; }
#define SAFE_DELETE(x) if(x) { delete x; x = NULL; }
// The bouncing box used by the object which is used to determine the collisions
struct BouncingBox{
unsigned int x1, x2, y1, y2;
BouncingBox(unsigned int l_x1 = 0, unsigned int l_x2 = 0,
unsigned int l_y1 = 0, unsigned int l_y2 = 0 ) :
x1(l_x1), x2(l_x2),
y1(l_y1), y2(l_y2) {}
void operator()(const unsigned int l_x1,
const unsigned int l_y1,
const unsigned int l_x2,
const unsigned int l_y2 )
{
x1 = l_x1; x2 = l_x2;
y1 = l_y1; y2 = l_y2;
}
unsigned int Width()
{ return (x2-x1); }
unsigned int Height()
{ return (y2-y1); }
};
// Event that will be used to move the objects in the game
struct ObjMove : public CEvent
{
VectorD2<int> m_Vec;
ObjMove(const VectorD2<int>& Vector) : m_Vec(Vector) {}
ObjMove(const int offx, const int offy) : m_Vec(offx, offy) {}
};
// supported by an object and you should look in player[].psupportingobj
// for it's index.
#define PSUPPORTEDBYOBJECT 0
class CObject {
public:
CObject(CMap *pmap, Uint32 x, Uint32 y, object_t type);
object_t m_type; // yorp, vorticon, etc.
unsigned int m_index; // Like an ID for some objects that need this implementation
char HealthPoints; // episode 1 style four-shots-to-kill
bool exists;
bool onscreen; // true=(scrx,scry) position is visible onscreen
bool hasbeenonscreen;
unsigned int sprite; // which sprite should this object be drawn with
direction_t m_hDir; // the direction to where the object is looking/heading to
direction_t m_vDir; // same for vertical
int scrx, scry; // x,y pixel position on screen
// Bouncing Boxes
BouncingBox m_BBox;
// if zero, priority tiles will not be honored and object will always
// appear in front of the background
bool honorPriority;
bool dontdraw; // tells the object whether to get drawn or not. The object is still existent in this while
bool solid;
bool canbezapped; // if 0 ray will not stop on hitdetect
bool inhibitfall; // if true common_enemy_ai will not do falling
bool cansupportplayer;
std::vector<CObject*> *mp_object;
bool blockedl, blockedr, blockedu, blockedd;
bool onslope;
bool falling;
signed int xinertia, yinertia;
unsigned char xinertiatimer;
unsigned int psupportingobject, lastsupportingobject;
bool supportedbyobject;
unsigned char touchPlayer; // 1=hit detection with player
unsigned char touchedBy; // which player was hit
bool dead, dying;
bool needinit;
bool m_canturnaround;
// This is used for action format only
// Hopefully in Vorticons we also can use that structure
uint16_t m_ActionTicker;
uint16_t m_ActionNumber;
size_t m_ActionBaseOffset;
bool m_jumped;
bool m_climbing;
bool m_jumpdown;
// This container will held the triggered events of the object
CEventContainer m_EventCont;
void setupObjectType(int Episode);
void calcBouncingBoxes();
void performCollisionsSameBox();
void performCollisions();
void setScrPos( int px, int py );
bool calcVisibility();
bool checkforScenario();
/**
* \description This will verify whether object has to fall or not.
* This function must be called when it might be moving
* because it also checks the lower sloped tiles cases
*
* \todo This function should also be called by foes in some cases
*/
bool verifyForFalling();
/**
* \description This function will change the direction of an object when
* it detects a coming gap while moving
* \param speed Amount of CSFed coordinates to move the object back
* when it over that gap
*/
void performCliffStop(const int &speed);
// Moving parts
void moveToForce(const VectorD2<int> &dir);
void moveToForce(const int& new_x, const int& new_y);
void moveDir(const VectorD2<int> &dir);
void moveToHorizontal(const int& new_x);
void moveToVertical(const int& new_y);
void moveTo(const VectorD2<Uint32> &new_loc);
void moveTo(const int new_x, const int new_y);
void moveXDir(const int amount, const bool force = false);
void moveYDir(const int amount);
void moveLeft(const int amnt, const bool force = false);
void moveRight(const int amnt, const bool force = false);
void moveUp(const int amnt);
void moveDown(const int amnt);
// new moving parts
/**
* \brief This function checks if there is any collision and moves the object safely
* \param dir The direction where the object has to go to...
*/
/**
* This setups the object on the Map. This is galaxy engine only so far,
*/
void setupGalaxyObjectOnMap(const size_t ActionBaseOffset = 0x0,
const size_t ActionNumber = 0x0 );
void processMove(const VectorD2<int>& dir);
void processMoveBitLeft();
void processMoveBitRight();
virtual void processMoveBitDown();
void processMoveBitUp();
void processMove(const int xoff, const int yoff);
/*
* \brief As especially in Galaxy some tiles still can get into blocks where they shouldn't
* So this function will pull them out. Same method is used in the original games
* and will give a more Commander Keen like feeling
*/
void processPushOutCollision();
void decreaseXInertia(const int& value);
void InertiaAndFriction_X();
virtual void process() { }
// The object can hold events process them here!
void processEvents();
bool hitdetect(CObject &hitobject);
bool hitdetectWithTilePropertyRect(const Uint16 Property, int &lx, int &ly, int &lw, int &lh, const int res);
bool hitdetectWithTileProperty(const int Property, const int x, const int y);
virtual void kill();
void blink(Uint16 frametime);
// Collision parts
/**
* \brief Those functions check the the collision states and return also a number of what type of block
* the collision is happening.
* \return returns the number of the block property. 0 means no collision. Any other number depends.
* 1 is blocked, the other depends on the engine. In Keen Galaxy they mostly represent sloped tiles
* In vorticons the up part have other numbers which represent ice and slippery.
*/
int checkSolidR( int x1, int x2, int y1, int y2);
int checkSolidL( int x1, int x2, int y1, int y2);
int checkSolidU( int x1, int x2, int y1, const bool push_mode=false );
int checkSolidD( int x1, int x2, int y2, const bool push_mode=false );
// special functions for sloped tiles
bool checkslopedU( int c, int y1, char blocked);
bool checkslopedD( int c, int y2, char blocked);
void adjustSlopedTiles( int x, int y1, int y2, const int xspeed );
bool moveSlopedTileDown( int x, int y, const int xspeed );
void moveSlopedTileUp( int x, int y, const int xspeed );
// getters for positions
VectorD2<Uint32> getPosition() const;
Uint32 getXPosition() const;
Uint32 getYPosition() const;
Uint32 getXLeftPos();
Uint32 getXRightPos();
Uint32 getXMidPos();
Uint32 getYUpPos();
Uint32 getYDownPos();
Uint32 getYMidPos();
void processFalling();
virtual void getTouchedBy(CObject &theObject) {};
virtual bool isNearby(CObject &theObject) { return true; }
virtual void getShotByRay(object_t &obj_type);
void kill_intersecting_tile(int mpx, int mpy, CObject &theObject);
CMap *getMapPtr() { return mp_Map; }
/**
* \description plays certain sound of an object. Stereo will automatically applied when used
*/
void playSound( const GameSound snd,
const SoundPlayMode mode=PLAY_NOW );
bool getActionNumber(int16_t ActionNumber);
bool getActionStatus(int16_t ActionNumber);
int16_t getActionNumber();
void setActionForce(size_t ActionNumber);
void setAction(size_t ActionNumber);
void setActionSprite();
void processActionRoutine();
void draw();
virtual ~CObject();
protected:
CMap *mp_Map;
Uint16 m_blinktime;
bool m_invincible;
VectorD2<Uint32> m_Pos; // x,y location in map coords, CSFed, represent as 2D Vector
static int m_number_of_objects;
// Action Format related stuff
ActionFormatType m_Action;
Uint8 transluceny;
};
#endif /* COBJECT_H_ */
/*
* CObjectCollision.cpp
* CSpriteObjectCollision.cpp
*
* Created on: 01.11.2010
* Author: gerstrong
*
* This is the second cpp file for the CObject Class
* This is the second cpp file for the CSpriteObject Class
* It is only meant to be used for collisions
*/
#include "CObject.h"
#include "CSpriteObject.h"
#include "engine/spritedefines.h"
/*
* \brief Performs collision without bouncing box recalculation
*/
void CObject::performCollisionsSameBox()
void CSpriteObject::performCollisionsSameBox()
{
const unsigned int abs_x1 = m_Pos.x+m_BBox.x1;
const unsigned int abs_x2 = m_Pos.x+m_BBox.x2;
......@@ -33,7 +33,7 @@ void CObject::performCollisionsSameBox()
/*
* \brief Calculate Bouncing Boxes
*/
void CObject::calcBouncingBoxes()
void CSpriteObject::calcBoundingBoxes()
{
CSprite &rSprite = g_pGfxEngine->getSprite(sprite);
......@@ -103,20 +103,20 @@ void getSlopePointsUpperTile(char slope, int &yb1, int &yb2)
* \brief This checks the collision. Very simple pixel based algorithm
* The collision is per pixel-based
*/
void CObject::performCollisions()
void CSpriteObject::performCollisions()
{
blockedr = blockedl = false;
blockedu = blockedd = false;
if ( sprite != BLANKSPRITE )
{
calcBouncingBoxes();
calcBoundingBoxes();
performCollisionsSameBox();
}
}
// Basic slope move independent of the left or right move
void CObject::adjustSlopedTiles( int x, int y1, int y2, const int xspeed )
void CSpriteObject::adjustSlopedTiles( int x, int y1, int y2, const int xspeed )
{
// process the sloped tiles here. Galaxy only or special patch!!
if(g_pBehaviorEngine->getEpisode() > 3)
......@@ -126,7 +126,7 @@ void CObject::adjustSlopedTiles( int x, int y1, int y2, const int xspeed )
}
}
bool CObject::moveSlopedTileDown( int x, int y, const int xspeed )
bool CSpriteObject::moveSlopedTileDown( int x, int y, const int xspeed )
{
if(yinertia!=0)
return false;
......@@ -167,7 +167,7 @@ bool CObject::moveSlopedTileDown( int x, int y, const int xspeed )
return onslope;
}
void CObject::moveSlopedTileUp( int x, int y, const int xspeed )
void CSpriteObject::moveSlopedTileUp( int x, int y, const int xspeed )
{
if(yinertia!=0)
return;
......@@ -206,7 +206,7 @@ void CObject::moveSlopedTileUp( int x, int y, const int xspeed )
}
// returns nonzero if object1 overlaps object2
bool CObject::hitdetect(CObject &hitobject)
bool CSpriteObject::hitdetect(CSpriteObject &hitobject)
{
unsigned int rect1x1, rect1y1, rect1x2, rect1y2;
unsigned int rect2x1, rect2y1, rect2x2, rect2y2;
......@@ -239,7 +239,7 @@ bool CObject::hitdetect(CObject &hitobject)
* \param from x
* \return true if detection worked with that tile having the property, else false
*/
bool CObject::hitdetectWithTilePropertyRect(const Uint16 Property, int &lx, int &ly, int &lw, int &lh, const int res)
bool CSpriteObject::hitdetectWithTilePropertyRect(const Uint16 Property, int &lx, int &ly, int &lw, int &lh, const int res)
{
std::vector<CTileProperties> &Tile = g_pBehaviorEngine->getTileProperties(1);
......@@ -265,7 +265,7 @@ bool CObject::hitdetectWithTilePropertyRect(const Uint16 Property, int &lx, int
* \param Property The Tile Property we are looking
* \return true if detection worked with that tile having the property, else false
*/
bool CObject::hitdetectWithTileProperty(const int Property, const int x, const int y)
bool CSpriteObject::hitdetectWithTileProperty(const int Property, const int x, const int y)
{
std::vector<CTileProperties> &Tile = g_pBehaviorEngine->getTileProperties(1);
const signed char behavior = Tile[mp_Map->getPlaneDataAt(1, x, y)].behaviour;
......@@ -277,7 +277,7 @@ bool CObject::hitdetectWithTileProperty(const int Property, const int x, const i
const int COLISION_RES = (1<<STC);
int CObject::checkSolidR( int x1, int x2, int y1, int y2)
int CSpriteObject::checkSolidR( int x1, int x2, int y1, int y2)
{
std::vector<CTileProperties> &TileProperty = g_pBehaviorEngine->getTileProperties();
int blocker;
......@@ -327,7 +327,7 @@ int CObject::checkSolidR( int x1, int x2, int y1, int y2)
return 0;
}
int CObject::checkSolidL( int x1, int x2, int y1, int y2)
int CSpriteObject::checkSolidL( int x1, int x2, int y1, int y2)
{
bool vorticon = (g_pBehaviorEngine->getEpisode() <= 3);
int blocker;
......@@ -373,7 +373,7 @@ int CObject::checkSolidL( int x1, int x2, int y1, int y2)
return 0;
}
int CObject::checkSolidU(int x1, int x2, int y1, const bool push_mode )
int CSpriteObject::checkSolidU(int x1, int x2, int y1, const bool push_mode )
{
bool vorticon = (g_pBehaviorEngine->getEpisode() <= 3);
std::vector<CTileProperties> &TileProperty = g_pBehaviorEngine->getTileProperties();
......@@ -436,7 +436,7 @@ int CObject::checkSolidU(int x1, int x2, int y1, const bool push_mode )
return 0;
}
int CObject::checkSolidD( int x1, int x2, int y2, const bool push_mode )
int CSpriteObject::checkSolidD( int x1, int x2, int y2, const bool push_mode )
{
bool vorticon = (g_pBehaviorEngine->getEpisode() <= 3);
std::vector<CTileProperties> &TileProperty = g_pBehaviorEngine->getTileProperties();
......@@ -530,7 +530,7 @@ int CObject::checkSolidD( int x1, int x2, int y2, const bool push_mode )
4 Bottom -> top 5 Middle -> bottom
6 Top -> middle 7 Top -> bottom
*/
bool CObject::checkslopedU( int c, int y1, char blocked)
bool CSpriteObject::checkslopedU( int c, int y1, char blocked)
{
int yb1, yb2;
......@@ -549,7 +549,7 @@ bool CObject::checkslopedU( int c, int y1, char blocked)
6 Bottom -> middle 7 Bottom -> top
8 Unused 9 Deadly, can't land on in God mode
*/
bool CObject::checkslopedD( int c, int y2, char blocked )
bool CSpriteObject::checkslopedD( int c, int y2, char blocked )
{
int yb1, yb2;
......@@ -563,7 +563,7 @@ bool CObject::checkslopedD( int c, int y2, char blocked )
const int MOVE_RES = 1;
void CObject::processMoveBitLeft()
void CSpriteObject::processMoveBitLeft()
{
/// Now check the neighboring tile to the left
const unsigned int x1 = getXPosition()+m_BBox.x1;
......@@ -580,7 +580,7 @@ void CObject::processMoveBitLeft()
adjustSlopedTiles(x1-(1<<STC), y1, y2, -MOVE_RES);
}
void CObject::processMoveBitRight()
void CSpriteObject::processMoveBitRight()
{
/// Now check the neighboring tile to the right
const unsigned int x1 = getXPosition()+m_BBox.x1;
......@@ -597,7 +597,7 @@ void CObject::processMoveBitRight()
adjustSlopedTiles(x2+(1<<STC), y1, y2, MOVE_RES);
}
void CObject::processMoveBitUp()
void CSpriteObject::processMoveBitUp()
{
/// Now check the neighboring tile to the up
const unsigned int x1 = getXPosition()+m_BBox.x1;
......@@ -612,7 +612,7 @@ void CObject::processMoveBitUp()
m_Pos.y-=MOVE_RES;
}
void CObject::processMoveBitDown()
void CSpriteObject::processMoveBitDown()
{
/// Now check the neighboring tile to the down
const unsigned int x1 = getXPosition()+m_BBox.x1;
......@@ -628,7 +628,7 @@ void CObject::processMoveBitDown()
}
void CObject::setupGalaxyObjectOnMap(const size_t ActionBaseOffset,
void CSpriteObject::setupGalaxyObjectOnMap(const size_t ActionBaseOffset,
const size_t ActionNumber )
{
m_ActionBaseOffset = ActionBaseOffset;
......@@ -647,12 +647,12 @@ void CObject::setupGalaxyObjectOnMap(const size_t ActionBaseOffset,
processActionRoutine();
}
void CObject::processMove(const VectorD2<int>& dir)
void CSpriteObject::processMove(const VectorD2<int>& dir)
{
processMove(dir.x, dir.y);
}
void CObject::processMove(const int xoff, const int yoff)
void CSpriteObject::processMove(const int xoff, const int yoff)
{
// Let's check if we have to move left or right
if(xoff>0)
......@@ -683,7 +683,7 @@ void CObject::processMove(const int xoff, const int yoff)
}
}
void CObject::processPushOutCollision()
void CSpriteObject::processPushOutCollision()
{
// If he isn't solid don't even care
if(!solid)
......@@ -764,7 +764,7 @@ void CObject::processPushOutCollision()
}
}
void CObject::processEvents()
void CSpriteObject::processEvents()
{
while(!m_EventCont.empty())
{
......
......@@ -25,8 +25,8 @@
///
CPlayer::CPlayer(const char &Episode, short &Level,
bool *mp_level_completed,
std::vector<CObject*> &m_Object, CMap &map) :
CObject(&map, 0, 0, OBJ_PLAYER),
std::vector<CSpriteObject*> &m_Object, CMap &map) :
CSpriteObject(&map, 0, 0, OBJ_PLAYER),
m_episode(Episode),
m_level(Level),
pjumpupspeed_decrease(g_pBehaviorEngine->getPhysicsSettings().player.defaultjumpupdecreasespeed),
......@@ -810,7 +810,7 @@ bool CPlayer::checkObjSolid()
{
supportedbyobject = false;
std::vector<CObject*>::iterator it_obj = mp_object->begin();
std::vector<CSpriteObject*>::iterator it_obj = mp_object->begin();
for( ; it_obj != mp_object->end() ; it_obj++ )
{
if((*it_obj)->cansupportplayer)
......
......@@ -10,7 +10,7 @@
#include <SDL.h>
#include "inventory.h"
#include "CObject.h"
#include "CSpriteObject.h"
#include "CMap.h"
#include "CStatusScreen.h"
#include "Playerdefines.h"
......@@ -32,7 +32,7 @@ enum level_triggers
///
// Class definition starts here!
///
class CPlayer : public CObject
class CPlayer : public CSpriteObject
{
public:
......@@ -44,7 +44,7 @@ public:
CPlayer(const char &Episode, short &Level,
bool *mp_level_completed,
std::vector<CObject*> &m_Object, CMap &map);
std::vector<CSpriteObject*> &m_Object, CMap &map);
void setupCameraObject();
void setDatatoZero();
void setDefaultStartValues();
......@@ -79,8 +79,8 @@ public:
void boostInertia(const int amt);
void Playerfalling();
void raygun();
void bump( CObject &theObject, direction_t direction );
void push( CObject &theObject );
void bump( CSpriteObject &theObject, direction_t direction );
void push( CSpriteObject &theObject );
void checkSolidDoors();
void SelectFrame();
int pollLevelTrigger();
......
......@@ -340,7 +340,7 @@ void CPlayer::TogglePogo_and_Switches()
if(mp_Map->m_PlatExtending)
{
// Find the object responsible for extending
std::vector<CObject*>::iterator obj = mp_object->begin();
std::vector<CSpriteObject*>::iterator obj = mp_object->begin();
for( ; obj != mp_object->end() ; obj++ )
{
if((*obj)->m_type == OBJ_BRIDGE && (*obj)->exists &&
......@@ -844,7 +844,7 @@ const int bumpamount = 160;
// yorp/scrub etc "bump".
// if solid = false, player can possibly force his way through.
// if solid = true, object acts like a solid "wall".
void CPlayer::bump( CObject &theObject, direction_t direction )
void CPlayer::bump( CSpriteObject &theObject, direction_t direction )
{
if( pjumping == PPREPAREJUMP || pjumping == PPREPAREPOGO || dead || level_done!=LEVEL_NOT_DONE )
return;
......@@ -860,7 +860,7 @@ void CPlayer::bump( CObject &theObject, direction_t direction )
}
// Scrub, etc "push".
void CPlayer::push( CObject &theObject )
void CPlayer::push( CSpriteObject &theObject )
{
if( dead || level_done!=LEVEL_NOT_DONE )
return;
......
......@@ -160,7 +160,7 @@ void CPlayer::selectFrameOnWorldMap()
void CPlayer::MountNessieIfAvailable()
{
// Look for the Nessie object
std::vector<CObject*>::iterator obj = mp_object->begin();
std::vector<CSpriteObject*>::iterator obj = mp_object->begin();
for(; obj != mp_object->end() ; obj++)
{
if((*obj)->m_type == OBJ_MESSIE)
......@@ -206,7 +206,7 @@ void CPlayer::UnmountNessie()
if(mp_Map->getObjectat(x+dx, y+dy) == NESSIE_LAND)
{
// Look for the Nessie object
std::vector<CObject*>::iterator obj = mp_object->begin();
std::vector<CSpriteObject*>::iterator obj = mp_object->begin();
for(; obj != mp_object->end() ; obj++)
{
if((*obj)->m_type == OBJ_MESSIE)
......
......@@ -5,7 +5,7 @@
* Author: gerstrong
*
* Small file which only has the enum for the possible directions in the game.
* It is mainly used by CObject but in some occasions it can be used by other classes or functions
* It is mainly used by CSpriteObject but in some occasions it can be used by other classes or functions
*/
#ifndef DIRECTION_H_
......