Commit f63dfd93 authored by Gerhard Stein's avatar Gerhard Stein

more adaptations to the SectorEffector Code

parent eebe647b
......@@ -54,6 +54,8 @@ public:
virtual ~CBehaviorEngine();
bool m_PlatExtending;
private:
std::vector<CTileProperties> m_TileProperties[2];
CPhysicsSettings m_PhysicsSettings;
......
......@@ -222,7 +222,7 @@ void CMapLoader::addWorldMapObject(unsigned int t, Uint16 x, Uint16 y, int episo
{
if (!m_NessieAlreadySpawned)
{
CMessie *messie = new CMessie(mp_map, x<<CSF, y<<CSF);
CMessie *messie = new CMessie(mp_map, x<<CSF, y<<CSF, *mp_vec_Player);
m_NessieAlreadySpawned = true;
mp_objvect->push_back(messie);
}
......@@ -344,8 +344,8 @@ void CMapLoader::addEnemyObject(unsigned int t, Uint16 x, Uint16 y, int episode,
}
else if (episode==3)
{
//enemyobject = new CVortiMom( mp_map, *mp_vec_Player,
// x<<CSF, y<<CSF);
enemyobject = new CVortiMom( mp_map, x<<CSF, y<<CSF,
*mp_vec_Player, *mp_objvect);
}
break;
case 4: // butler (ep1) or scrub (ep2) or meep (ep3)
......@@ -383,11 +383,12 @@ void CMapLoader::addEnemyObject(unsigned int t, Uint16 x, Uint16 y, int episode,
case 7: // spark (ep2) ball (ep3) ice cannon upwards (ep1)
if (episode==1)
{
enemyobject = new CIceCannon( mp_map,x<<CSF, y<<CSF,*mp_vec_Player,*mp_objvect,0,-1);
enemyobject = new CIceCannon( mp_map,x<<CSF, y<<CSF, *mp_vec_Player,*mp_objvect,0,-1);
}
else if (episode==2)
{
//enemyobject = new CSectorEffector( mp_map, *mp_vec_Player, x<<CSF, y<<CSF);
enemyobject = new CSectorEffector( mp_map, x<<CSF, y<<CSF,
*mp_vec_Player,*mp_objvect, OBJ_SPARK);
}
else if (episode==3)
{
......@@ -432,13 +433,13 @@ void CMapLoader::addEnemyObject(unsigned int t, Uint16 x, Uint16 y, int episode,
}
break;
case 12: // sparks in mortimer's machine
// enemyobject = new CSectorEffector( mp_map, *mp_vec_Player, x<<CSF, y<<CSF );
// enemyobject->setype = SE_MORTIMER_SPARK;
enemyobject = new CSectorEffector( mp_map, x<<CSF, y<<CSF,
*mp_vec_Player,*mp_objvect, SE_MORTIMER_SPARK);
enemyobject->solid = false;
break;
case 13: // mortimer's heart
// enemyobject = new CSectorEffector( mp_map, *mp_vec_Player, x<<CSF, y<<CSF, );
// enemyobject->setype = SE_MORTIMER_HEART;
enemyobject = new CSectorEffector( mp_map, x<<CSF, y<<CSF,
*mp_vec_Player,*mp_objvect, SE_MORTIMER_HEART);
enemyobject->solid = false;
break;
case 14: // right-pointing raygun (ep3)
......@@ -448,18 +449,18 @@ void CMapLoader::addEnemyObject(unsigned int t, Uint16 x, Uint16 y, int episode,
enemyobject = new CAutoRay(mp_map, x<<CSF, y<<CSF, *mp_objvect, CAutoRay::VERTICAL);
break;
case 16: // mortimer's arms
// enemyobject = new CSectorEffector( mp_map, *mp_vec_Player, x<<CSF, y<<CSF );
// enemyobject->setype = SE_MORTIMER_ARM;
enemyobject = new CSectorEffector( mp_map, x<<CSF, y<<CSF,
*mp_vec_Player,*mp_objvect, SE_MORTIMER_ARM );
enemyobject->solid = false;
break;
case 17: // mortimer's left leg
// enemyobject = new CSectorEffector( mp_map, *mp_vec_Player, x<<CSF, y<<CSF );
// enemyobject->setype = SE_MORTIMER_LEG_LEFT;
enemyobject = new CSectorEffector( mp_map, x<<CSF, y<<CSF,
*mp_vec_Player,*mp_objvect, SE_MORTIMER_LEG_LEFT );
enemyobject->solid = false;
break;
case 18: // mortimer's right leg
// enemyobject = new CSectorEffector( mp_map, *mp_vec_Player, x<<CSF, y<<CSF );
// enemyobject->setype = SE_MORTIMER_LEG_RIGHT;
enemyobject = new CSectorEffector( mp_map, x<<CSF, y<<CSF,
*mp_vec_Player,*mp_objvect, SE_MORTIMER_LEG_RIGHT );
enemyobject->solid = false;
break;
default:
......
......@@ -566,6 +566,26 @@ void CObject::getShotByRay()
}
}
// anything (players/enemies) occupying the map tile at [mpx,mpy] is killed
void CObject::kill_intersecting_tile(int mpx, int mpy, CObject &theObject)
{
unsigned int xpix,ypix;
unsigned int x, y;
xpix = mpx<<CSF;
ypix = mpy<<CSF;
std::vector<CObject*>::iterator object;
for( object=m_Objvect.begin() ; object!=m_Objvect.end() ; object++ )
{
x = theObject.getXMidPos();
y = theObject.getYUpPos();
if (theObject.exists)
if (xpix-(1<<CSF) <= x && xpix+(1<<CSF) >= x)
if (ypix <= y && ypix+(1<<CSF) >= y)
theObject.kill();
}
}
const int COLISION_RES = 4;
bool CObject::checkSolidR( int x2, int y1, int y2)
{
......
......@@ -86,21 +86,6 @@ public:
bool needinit;
// data for ai and such, used differently depending on
// what kind of object it is
union ai
{
// ep1
stRopeData rope;
// ep2
stVortEliteData vortelite;
// ep3
stMotherData mother;
stNessieData nessie;
} ai;
void setupObjectType(int Episode);
void checkinitialCollisions();
void setScrPos( int px, int py );
......@@ -144,6 +129,7 @@ public:
void processFalling();
virtual void getTouchedBy(CObject &theObject) {};
virtual void getShotByRay();
void kill_intersecting_tile(int mpx, int mpy, CObject &theObject);
void draw();
void drawMask(SDL_Surface *dst, CSprite &Sprite, int mx, int my);
......
......@@ -8,7 +8,7 @@
#include "CEarthExplosion.h"
CEarthExplosion::CEarthExplosion(CMap *p_map, Uint32 x, Uint32 y) :
CObject(p_map, x, y)
CRay(p_map, x, y, RIGHT)
{
onscreen = true;
}
......@@ -20,26 +20,26 @@ CObject(p_map, x, y)
void CEarthExplosion::process()
{
/*sprite = EXPLODESPRITE + animframe;
sprite = EXPLODESPRITE + animframe;
if (animtimer > EXPLODE_ANIM_RATE)
{
if (m_Direction==NONE && animframe==0)
if (m_Direction!=RIGHT && animframe==0)
{
exists = false;
}
else
{
//animframe += (animframe%2);
//if (direction==1 && animframe==3)
animframe += (animframe%2);
if (animframe==3)
{
int x, y;
x = getXPosition()>>CSF;
y = getYPosition()>>CSF;
m_Direction = NONE;
m_Direction = LEFT;
mp_Map->setTile((x+8)>>4,(y+8)>>4, SPACETILE, true);
}
}
animtimer = 0;
}
else animtimer++;*/
else animtimer++;
}
......@@ -8,9 +8,9 @@
#ifndef CEARTHEXPLOSION_H_
#define CEARTHEXPLOSION_H_
#include "../../../common/CObject.h"
#include "CRay.h"
class CEarthExplosion : public CObject {
class CEarthExplosion : public CRay {
public:
CEarthExplosion(CMap *p_map, Uint32 x, Uint32 y);
void process();
......
......@@ -26,45 +26,10 @@ CRay(p_map, x, y, dir, byType, byID)
void CFireBall::process()
{
/*int speed;
// check if it hit keen
if (touchPlayer)
{
killplayer(touchedBy);
// make a ZAP-ZOT animation
m_type = OBJ_RAY;
state = RAY_STATE_SETZAPZOT;
inhibitfall = 1;
needinit = 0;
return;
}
// test if it hit a baddie
std::vector<CObject*>::iterator it_obj = m_Objvect.begin()++;
for( ; it_obj!=m_Objvect.end() ; it_obj++)
{
if (!(*it_obj)->exists || (*it_obj)->m_index==m_index) continue;
if ( (*it_obj)->m_type==OBJ_FIREBALL) continue;
if ((*it_obj)->canbezapped || (*it_obj)->m_type==OBJ_RAY)
{
if ((*it_obj)->hitdetect(object) && owner != (*it_obj)->m_index)
{
m_type = OBJ_RAY;
state = RAY_STATE_SETZAPZOT;
inhibitfall = 1;
needinit = 0;
(*it_obj)->zapped++;
(*it_obj)->moveTo(getXPosition(), getYPosition());
(*it_obj)->zappedbyenemy = 1;
return;
}
}
}
int speed;
// check if it was shot
if (zapped)
if (HealthPoints <= 0)
{
if (onscreen) g_pSound->playStereofromCoord(SOUND_SHOT_HIT, PLAY_NOW, scrx);
m_type = OBJ_RAY;
......@@ -82,7 +47,7 @@ void CFireBall::process()
{
if (offscreentime > FIREBALL_OFFSCREEN_KILL_TIME)
{
deleteObj(object);
exists = false;
return;
}
else offscreentime++;
......@@ -90,8 +55,8 @@ void CFireBall::process()
else offscreentime = 0;
// fly through the air
speed = hard ? FIREBALL_HARD_SPEED : FIREBALL_SPEED;
if (direction == RIGHT)
speed = (mp_Map->m_Difficulty>1) ? FIREBALL_HARD_SPEED : FIREBALL_SPEED;
if (m_Direction == RIGHT)
{
sprite = FIREBALL_RIGHT_FRAME + animframe;
if (blockedr || blockedl)
......@@ -124,8 +89,5 @@ void CFireBall::process()
animframe ^= 1;
animtimer = 0;
}
else animtimer++;*/
else animtimer++;
}
......@@ -12,6 +12,7 @@
class CFireBall : public CRay
{
public:
CFireBall(CMap *p_map, Uint32 x, Uint32 y,
direction_t dir, object_t byType, size_t byID);
void process();
......
......@@ -41,7 +41,7 @@ void CIceCannon::process()
sprite = BLANKSPRITE;
inhibitfall = 1;
if(m_gunfiretimer<GUNFIRE_TIMER) m_gunfiretimer++;
if(m_gunfiretimer<GUNFIRE_TIMER_EP1) m_gunfiretimer++;
else
{
int newpos_x = getXPosition()+(vector_x)*512;
......
......@@ -12,7 +12,7 @@
#include "../../../common/CPlayer.h"
#include <vector>
#define GUNFIRE_TIMER 50
#define GUNFIRE_TIMER_EP1 50
unsigned int rnd(void);
......
......@@ -18,61 +18,54 @@ enum nessie_actions{
void nessie_find_next_checkpoint(int o);
CMessie::CMessie(CMap *p_map, Uint32 x, Uint32 y) :
CObject(p_map, x, y)
CMessie::CMessie(CMap *p_map, Uint32 x, Uint32 y,
std::vector<CPlayer>& Player) :
CObject(p_map, x, y),
m_Player(Player)
{
onscreen = true;
solid = false;
}
void CMessie::process()
{
baseframe = NESSIE_DOWNLEFT_FRAME;
leftrightdir = LEFT;
updowndir = DOWN;
animframe = 0;
animtimer = 0;
state = NESSIE_SWIMNORMAL;
pausetimer = 0;
mortimer_swim_amt = 0;
destx = 0;
desty = 0;
inhibitfall = 1;
canbezapped = 0;
needinit = 0;
for(size_t i=0;i<=NESSIETRAILLEN;i++)
{
tiletrailX[i] = 0;
tiletrailY[i] = 0;
}
// kick nessie into going counter-clockwise
// (otherwise she'll go clockwise)
int mx, my;
mx = getXPosition()>>CSF;
my = getYPosition()>>CSF;
tiletrailX[0] = mx;
tiletrailY[0] = my;
tiletrailX[1] = mx+1;
tiletrailY[1] = my;
tiletrailhead = 2;
for(size_t i=0;i<MAX_PLAYERS;i++)
{
mounted[i] = false;
}
nessie_find_next_checkpoint();
}
/*
void CObjectAI::nessie_ai(CObject& object)
void CMessie::process()
{
if (object.needinit)
{
object.ai.nessie.baseframe = NESSIE_DOWNLEFT_FRAME;
object.ai.nessie.leftrightdir = LEFT;
object.ai.nessie.updowndir = DOWN;
object.ai.nessie.animframe = 0;
object.ai.nessie.animtimer = 0;
object.ai.nessie.state = NESSIE_SWIMNORMAL;
object.ai.nessie.pausetimer = 0;
object.ai.nessie.mortimer_swim_amt = 0;
object.ai.nessie.destx = 0;
object.ai.nessie.desty = 0;
object.inhibitfall = 1;
object.canbezapped = 0;
object.needinit = 0;
for(size_t i=0;i<=NESSIETRAILLEN;i++)
{
object.ai.nessie.tiletrailX[i] = 0;
object.ai.nessie.tiletrailY[i] = 0;
}
// kick nessie into going counter-clockwise
// (otherwise she'll go clockwise)
int x, y;
x = object.getXPosition()>>CSF;
y = object.getYPosition()>>CSF;
object.ai.nessie.tiletrailX[0] = x;
object.ai.nessie.tiletrailY[0] = y;
object.ai.nessie.tiletrailX[1] = x+1;
object.ai.nessie.tiletrailY[1] = y;
object.ai.nessie.tiletrailhead = 2;
for(size_t i=0;i<MAX_PLAYERS;i++)
{
object.ai.nessie.mounted[i] = false;
}
nessie_find_next_checkpoint(object);
}
// find out if nessie is mounted, and for all players that are
// mounted keep them stuck to nessie
bool isMounted = false;
......@@ -80,99 +73,99 @@ void CObjectAI::nessie_ai(CObject& object)
std::vector<CPlayer>::iterator it_player = m_Player.begin();
for( ; it_player != m_Player.end() ; it_player++ )
{
if (object.ai.nessie.mounted[it_player->m_index])
if (mounted[it_player->m_index])
{
int x = object.getXPosition();
int y = object.getYPosition();
int x = getXPosition();
int y = getYPosition();
it_player->moveTo(x, y);
isMounted = true;
}
}
// animation
object.sprite = object.ai.nessie.baseframe + object.ai.nessie.animframe;
if (isMounted) object.sprite += 8;
sprite = baseframe + animframe;
if (isMounted) sprite += 8;
if (object.ai.nessie.animtimer > NESSIE_ANIM_RATE)
if (animtimer > NESSIE_ANIM_RATE)
{
object.ai.nessie.animframe ^= 1;
object.ai.nessie.animtimer = 0;
animframe ^= 1;
animtimer = 0;
}
else object.ai.nessie.animtimer++;
else animtimer++;
switch(object.ai.nessie.state)
switch(state)
{
case NESSIE_SWIMNORMAL:
// arrived at destination?
unsigned int x,y;
x = object.getXPosition();
y = object.getYPosition();
if ( x > (object.ai.nessie.destx-NESSIE_SPEED/2) &&
x < (object.ai.nessie.destx+NESSIE_SPEED/2) )
x = getXPosition();
y = getYPosition();
if ( x > (destx-NESSIE_SPEED/2) &&
x < (destx+NESSIE_SPEED/2) )
{
if ( y > (object.ai.nessie.desty-NESSIE_SPEED/2) &&
y < (object.ai.nessie.desty+NESSIE_SPEED/2) )
if ( y > (desty-NESSIE_SPEED/2) &&
y < (desty+NESSIE_SPEED/2) )
{
nessie_find_next_checkpoint(object);
nessie_find_next_checkpoint();
// set up/down and left/right direction flags for frame selection
x = object.getXPosition();
y = object.getYPosition();
if (object.ai.nessie.destx > x)
object.ai.nessie.leftrightdir = RIGHT;
else if (object.ai.nessie.destx < x)
object.ai.nessie.leftrightdir = LEFT;
if (object.ai.nessie.desty < y)
object.ai.nessie.updowndir = UP;
else if (object.ai.nessie.destx > y)
object.ai.nessie.updowndir = DOWN;
x = getXPosition();
y = getYPosition();
if (destx > x)
leftrightdir = RIGHT;
else if (destx < x)
leftrightdir = LEFT;
if (desty < y)
updowndir = UP;
else if (destx > y)
updowndir = DOWN;
}
}
move_nessie(object);
move_nessie();
break;
case NESSIE_PAUSE:
if(object.ai.nessie.pausetimer)
if(pausetimer)
{
object.ai.nessie.pausetimer--;
pausetimer--;
}
else
{
object.ai.nessie.state = NESSIE_SWIMNORMAL;
move_nessie(object);
state = NESSIE_SWIMNORMAL;
move_nessie();
}
break;
}
}
void CObjectAI::move_nessie(CObject& object)
void CMessie::move_nessie()
{
unsigned int x = object.getXPosition();
unsigned int y = object.getYPosition();
unsigned int x = getXPosition();
unsigned int y = getYPosition();
// select proper frame based on up/down and left/right direction flags
if (object.ai.nessie.updowndir==DOWN && object.ai.nessie.leftrightdir==LEFT)
object.ai.nessie.baseframe = NESSIE_DOWNLEFT_FRAME;
else if (object.ai.nessie.updowndir==DOWN && object.ai.nessie.leftrightdir==RIGHT)
object.ai.nessie.baseframe = NESSIE_DOWNRIGHT_FRAME;
else if (object.ai.nessie.updowndir==UP && object.ai.nessie.leftrightdir==LEFT)
object.ai.nessie.baseframe = NESSIE_UPLEFT_FRAME;
else if (object.ai.nessie.updowndir==UP && object.ai.nessie.leftrightdir==RIGHT)
object.ai.nessie.baseframe = NESSIE_UPRIGHT_FRAME;
if (updowndir==DOWN && leftrightdir==LEFT)
baseframe = NESSIE_DOWNLEFT_FRAME;
else if (updowndir==DOWN && leftrightdir==RIGHT)
baseframe = NESSIE_DOWNRIGHT_FRAME;
else if (updowndir==UP && leftrightdir==LEFT)
baseframe = NESSIE_UPLEFT_FRAME;
else if (updowndir==UP && leftrightdir==RIGHT)
baseframe = NESSIE_UPRIGHT_FRAME;
// head to destination
if (x < object.ai.nessie.destx)
object.moveRight(NESSIE_SPEED);
else if (x > object.ai.nessie.destx)
object.moveLeft(NESSIE_SPEED);
if (y < object.ai.nessie.desty)
object.moveDown(NESSIE_SPEED);
else if (y > object.ai.nessie.desty)
object.moveUp(NESSIE_SPEED);
if (x < destx)
moveRight(NESSIE_SPEED);
else if (x > destx)
moveLeft(NESSIE_SPEED);
if (y < desty)
moveDown(NESSIE_SPEED);
else if (y > desty)
moveUp(NESSIE_SPEED);
}
void CObjectAI::nessie_find_next_checkpoint(CObject& object)
void CMessie::nessie_find_next_checkpoint()
{
int x,y,i;
int xa,ya;
......@@ -181,8 +174,8 @@ void CObjectAI::nessie_find_next_checkpoint(CObject& object)
// search in the 8 surrounding tiles and head to the first pathtile
// we find that's not one of the last 5 we've been to
x = ((object.getXPosition())>>CSF)-1;
y = ((object.getYPosition()+(8<<STC))>>CSF)-1;
x = ((getXPosition())>>CSF)-1;
y = ((getYPosition()+(8<<STC))>>CSF)-1;
destx = desty = 0;
......@@ -200,8 +193,8 @@ void CObjectAI::nessie_find_next_checkpoint(CObject& object)
bool oneoflasttiles = false;
for(i=0;i<NESSIETRAILLEN;i++)
{
if (object.ai.nessie.tiletrailX[i]==destx &&
object.ai.nessie.tiletrailY[i]==desty)
if (tiletrailX[i]==destx &&
tiletrailY[i]==desty)
{
oneoflasttiles = true;
break;
......@@ -210,12 +203,12 @@ void CObjectAI::nessie_find_next_checkpoint(CObject& object)
if (!oneoflasttiles)
{
object.ai.nessie.tiletrailX[object.ai.nessie.tiletrailhead] = destx;
object.ai.nessie.tiletrailY[object.ai.nessie.tiletrailhead] = desty;
object.ai.nessie.tiletrailhead++;
if (object.ai.nessie.tiletrailhead>=NESSIETRAILLEN)
tiletrailX[tiletrailhead] = destx;
tiletrailY[tiletrailhead] = desty;
tiletrailhead++;
if (tiletrailhead>=NESSIETRAILLEN)
{
object.ai.nessie.tiletrailhead = 0;
tiletrailhead = 0;
}
goto foundtile;
} // end if (!oneoflasttiles)
......@@ -225,19 +218,18 @@ void CObjectAI::nessie_find_next_checkpoint(CObject& object)
} // end for(ya...
// If Nessie went to an dead end. Go back!
object.ai.nessie.tiletrailhead = 0;
tiletrailhead = 0;
return;
foundtile: ;
object.ai.nessie.destx = (destx<<CSF);
object.ai.nessie.desty = (desty<<CSF)-(8<<STC);
destx = (destx<<CSF);
desty = (desty<<CSF)-(8<<STC);
int obj = mp_Map->getObjectat(destx, desty);
if(obj == NESSIE_WEED || obj == NESSIE_LAND)
{
object.ai.nessie.state = NESSIE_PAUSE;
object.ai.nessie.pausetimer = NESSIE_PAUSE_TIME;
state = NESSIE_PAUSE;
pausetimer = NESSIE_PAUSE_TIME;
}
}
*/
......@@ -9,13 +9,38 @@
#define CMESSIE_H_
#include "../../../common/CObject.h"
#include "../../../common/CPlayer.h"
#define NESSIETRAILLEN 5
class CMessie : public CObject
{
public:
CMessie(CMap *p_map, Uint32 x, Uint32 y);
CMessie(CMap *p_map, Uint32 x, Uint32 y,
std::vector<CPlayer>& Player);
void process();
private:
void move_nessie();
void nessie_find_next_checkpoint();
//private:
char state;
char leftrightdir, updowndir;
unsigned int baseframe;
unsigned int tiletrailX[NESSIETRAILLEN+1];
unsigned int tiletrailY[NESSIETRAILLEN+1];
int tiletrailhead;
char animframe, animtimer;
unsigned int destx, desty;
unsigned int pausetimer;
unsigned int pausex, pausey;
unsigned int mortimer_swim_amt;
bool mounted[MAX_PLAYERS];
std::vector<CPlayer>& m_Player;
};
#endif /* CMESSIE_H_ */
......@@ -133,26 +133,6 @@ void CObjectAI::killplayer(int theplayer)
m_Player[theplayer].kill();
}
// anything (players/enemies) occupying the map tile at [mpx,mpy] is killed
void CObjectAI::kill_all_intersecting_tile(int mpx, int mpy)
{
unsigned int xpix,ypix;
unsigned int x, y;
xpix = mpx<<CSF;
ypix = mpy<<CSF;
std::vector<CObject*>::iterator object;
for( object=m_Objvect.begin() ; object!=m_Objvect.end() ; object++ )
{
x = (*object)->getXMidPos();
y = (*object)->getYUpPos();
if ((*object)->exists)
if (xpix-(1<<CSF) <= x && xpix+(1<<CSF) >= x)
if (ypix <= y && ypix+(1<<CSF) >= y)
(*object)->kill();
}
}
///
// Cleanup Routine
///
......
......@@ -105,7 +105,7 @@ private:
void killplayer(int theplayer);
void SetAllCanSupportPlayer(CObject &object, bool state);
void kill_all_intersecting_tile(int mpx, int mpy);
void kill_all_intersecting_tile(int mpx, int mpy, CObject &theObject);
// Variables
CMap *mp_Map;
......
......@@ -166,7 +166,7 @@ void CRay::process()
}
moveLeft(rayspeed);
}
/*else if (m_Direction == DOWN)
else if (m_Direction == DOWN)
{
if (blockedd || blockedu)
{
......@@ -175,7 +175,7 @@ void CRay::process()
if (onscreen) g_pSound->playStereofromCoord(SOUND_SHOT_HIT, PLAY_NOW, scrx);
}
moveDown(rayspeed);
}*/
}
break;
case RAY_STATE_SETZAPZOT:
state = RAY_STATE_ZAPZOT;
......