Commit 96741e4c authored by Gerhard Stein's avatar Gerhard Stein

File reorganisation

parent 6eba5cb3
This diff is collapsed.
/*
* CSpriteObject.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"
// The bouncing box used by the object which is used to determine the collisions
struct BoundingBox{
unsigned int x1, x2, y1, y2;
BoundingBox(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) {}
};
class CSpriteObject
{
public:
CSpriteObject(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 mHealthPoints; // 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
// Bounding Boxes
BoundingBox 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<CSpriteObject*> *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; // Deprecated. Is only there so savegame mode still works.
bool m_canturnaround;
// This is used for action format only
// Hopefully in Vorticons we also can use that structure some time
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 calcBoundingBoxes();
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(CSpriteObject &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(CSpriteObject &theObject) {};
virtual bool isNearby(CSpriteObject &theObject) { return true; }
virtual void getShotByRay(object_t &obj_type);
void kill_intersecting_tile(int mpx, int mpy, CSpriteObject &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 ~CSpriteObject();
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_ */
/*
* CSpriteObjectAI.cpp
*
* Created on: 26.10.2009
* Author: gerstrong
*/
#include "CSpriteObjectAI.h"
#include "sdl/CVideoDriver.h"
#include "CLogFile.h"
CSpriteObjectAI::CSpriteObjectAI(CMap *p_map, std::vector<CSpriteObject*> &objvect, std::vector<CPlayer> &Player,
int NumPlayers, int episode, int level, bool &dark) :
m_Objvect(objvect),
m_Player(Player),
m_dark(dark)
{
mp_Map = p_map;
mp_Options = g_pBehaviorEngine->m_option;
m_Level = level;
m_Episode = episode;
m_gunfiretimer = 0;
}
//////////////////
// AI Processes //
//////////////////
void CSpriteObjectAI::process()
{
for( size_t i=0 ; i < m_Objvect.size() ; i++ )
{
CSpriteObject &object = *m_Objvect.at(i);
if( object.checkforScenario() )
{
object.performCollisions();
object.processFalling();
if(!object.dead) // Only do that if not dead
{
// hit detection with players
object.touchPlayer = false;
std::vector<CPlayer>::iterator it_player = m_Player.begin();
for( ; it_player != m_Player.end() ; it_player++ )
{
if (!it_player->pdie)
{
if ( object.hitdetect(*it_player) )
{
object.getTouchedBy(*it_player);
object.touchPlayer = true;
object.touchedBy = it_player->m_index;
break;
}
}
}
object.process();
std::vector<CSpriteObject*>::iterator theOther = m_Objvect.begin();
for( ; theOther != m_Objvect.end() ; theOther++ )
{
if( *theOther != &object )
{
if( object.hitdetect(**theOther) )
object.getTouchedBy(**theOther);
}
}
}
object.processEvents();
object.InertiaAndFriction_X();
}
}
// Try always to remove the last objects if they aren't used anymore!
CSpriteObject* p_object;
while(m_Objvect.size()>0)
{
p_object = m_Objvect.at( m_Objvect.size()-1 );
if(!p_object->exists)
{
delete p_object;
m_Objvect.pop_back();
}
else
break;
}
if(m_gunfiretimer < ((m_Episode==3) ? 180 : 50 )) m_gunfiretimer++;
else m_gunfiretimer=0;
}
void CSpriteObjectAI::SetAllCanSupportPlayer(CSpriteObject &object, bool state)
{
std::vector<CPlayer>::iterator it_player = m_Player.begin();
for( ; it_player != m_Player.end() ; it_player++ )
{
object.cansupportplayer = state;
if(!state && it_player->supportedbyobject)
{
it_player->pfalling=true;
it_player->moveDown(1);
it_player->blockedd=false;
}
}
}
///
// Cleanup Routine
///
void CSpriteObjectAI::deleteAllObjects()
{
// The real delete happens, when all the AI is done
// If the last object was deleted, throw it out of the list
if(!m_Objvect.empty())
{
std::vector<CSpriteObject*>::iterator obj=m_Objvect.begin();
for( ; obj != m_Objvect.end() ; obj++ )
delete *obj;
m_Objvect.clear();
}
}
CSpriteObjectAI::~CSpriteObjectAI() {
deleteAllObjects();
}
/*
* CSpriteObjectAI.h
*
* Created on: 26.10.2009
* Author: gerstrong
*/
#ifndef CSPRITEOBJECTAI_H_
#define CSPRITEOBJECTAI_H_
#include "common/CMap.h"
#include "common/CSpriteObject.h"
#include "common/options.h"
#include "common/CPlayer.h"
#include "common/CBehaviorEngine.h"
#include "graphics/CGfxEngine.h"
#include <vector>
class CSpriteObjectAI
{
public:
CSpriteObjectAI(CMap *p_map, std::vector<CSpriteObject*> &objvect, std::vector<CPlayer> &Player,
int NumPlayers, int episode, int level, bool &dark);
// main functions
void process();
virtual ~CSpriteObjectAI();
private:
// main AI functions
bool checkforAIObject( CSpriteObject &object );
void deleteAllObjects();
void icechunk_ai(CSpriteObject &object);
void smash(CSpriteObject &object);
void icebit_ai(CSpriteObject &object);
void icecannon_ai(CSpriteObject &object);
void rope_ai(CSpriteObject &object);
void rope_movestone(CSpriteObject &object);
// ep2
void baby_ai(CSpriteObject &object, int episode, bool hard);
void baby_jump(CSpriteObject &object, int big);
void scrub_ai(CSpriteObject &object);
void walkLeft(CSpriteObject &object, int mx, int my);
void walkRight(CSpriteObject &object, int mx, int my);
void walkUp(CSpriteObject &object);
void walkDown(CSpriteObject &object);
void fall(CSpriteObject &object);
void preparetoFall(CSpriteObject &object);
void Scrub_TurnOnCansupportWhereNotKicked(CSpriteObject &object);
void tankep2_ai(CSpriteObject &object, bool hardmode);
void tank2_fire(CSpriteObject &object);
void tank_searchplayers(CSpriteObject &object);
void platform_ai(CSpriteObject &object);
void vortelite_ai(CSpriteObject &object, bool darkness);
void vortelite_initiatejump(CSpriteObject &object);
// Sector Effector Members
void se_ai(CSpriteObject &object);
void se_extend_plat(CSpriteObject &object, bool &PlatExtending);
void se_retract_plat(CSpriteObject &object, bool &PlatExtending);
void se_mortimer_arm(CSpriteObject &object);
void se_mortimer_spark(CSpriteObject &object);
void se_mortimer_heart(CSpriteObject &object);
void se_mortimer_zapsup(CSpriteObject &object);
void se_mortimer_leg_left(CSpriteObject &object);
void se_mortimer_leg_right(CSpriteObject &object);
void se_mortimer_randomzaps(CSpriteObject &object);
void set_mortimer_surprised(bool yes);
void explosion_ai(CSpriteObject &object);
void earthchunk_ai(CSpriteObject &object);
// ep3
void foob_ai(CSpriteObject &object, bool hardmode);
void ninja_ai(CSpriteObject &object, bool hardmode);
void meep_ai(CSpriteObject& object);
void sndwave_ai(CSpriteObject& object, bool hardmode);
void mother_ai(CSpriteObject& object, bool hardmode);
void fireball_ai(CSpriteObject &object, bool hard);
void ballandjack_ai(CSpriteObject& object);
bool BJ_BlockedD(CSpriteObject &object);
void platvert_ai(CSpriteObject& object);
void nessie_ai(CSpriteObject& object);
void move_nessie(CSpriteObject& object);
void nessie_find_next_checkpoint(CSpriteObject& object);
// Common Objects
void autoray_ai(CSpriteObject &object);
void gotpoints_ai(CSpriteObject &Object);
void ray_ai( CSpriteObject &object, bool automatic_raygun, char pShotSpeed=0 );
void door_ai( CSpriteObject &object, char DoorOpenDir );
void teleporter_ai(CSpriteObject &object);
void killplayer(int theplayer);
void SetAllCanSupportPlayer(CSpriteObject &object, bool state);
void kill_all_intersecting_tile(int mpx, int mpy, CSpriteObject &theObject);
// Variables
CMap *mp_Map;
std::vector<CSpriteObject*> &m_Objvect;
std::vector<CPlayer> &m_Player;
stOption *mp_Options;
int m_Level;
int m_Episode;
int m_gunfiretimer;
bool &m_dark;
};
#endif /* CSPRITEOBJECTAI_H_ */
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