CCouncilMember.cpp 3.5 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * CCouncilMember.cpp
 *
 *  Created on: 23FEB2011
 *      Author: FCTW
 */

#include "CCouncilMember.h"
Gerstrong's avatar
Gerstrong committed
9
#include "engine/galaxy/ai/CPlayerLevel.h"
10
#include "misc.h"
11
#include "sdl/sound/CSound.h"
12
#include "sdl/music/CMusic.h"
Gerhard Stein's avatar
Gerhard Stein committed
13
#include <typeinfo>
14 15 16

namespace galaxy {

17 18 19 20
const int ELDER_MOVE_SPEED = 1;
const int ELDER_MOVE_TIMER = 10;


21 22
CCouncilMember::CCouncilMember(CMap *pmap, const Uint16 foeID, Uint32 x, Uint32 y) :
CGalaxySpriteObject(pmap, foeID, x, y),
23 24
rescued(false),
m_timer(0)
25
{
Gerstrong's avatar
Gerstrong committed
26
	setupGalaxyObjectOnMap(0x1FB8, A_COUNCIL_MEMBER_MOVE);
27
	mp_processState = &CCouncilMember::processWalking;
28 29 30 31 32 33 34 35 36 37

	answermap[0] = "KEEN_NOSWEAT_TEXT";
	answermap[1] = "KEEN_BEARDED_ONE_TEXT";
	answermap[2] = "KEEN_NO_PROBLEMO_TEXT";
	answermap[3] = "KEEN_GREAT_TEXT";
	answermap[4] = "KEEN_LOOKS_LIKE_SAME_GUY_TEXT";
	answermap[5] = "KEEN_GOOD_IDEA_GRAMPS";
	answermap[6] = "KEEN_ROAD_RISE_FEET_TEXT";
	answermap[7] = "KEEN_WISE_PLAN_TEXT";
	answermap[8] = "KEEN_LAST_ELDER_TEXT";
38 39
}

40 41 42 43 44 45



void CCouncilMember::processWalking()
{
	performCollisions();
46
	performGravityLow();
47 48 49


	// Check if there is a cliff and move him back in case
50
	performCliffStop(m_Action.velX<<1);
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72


	if( m_timer < ELDER_MOVE_TIMER )
	{
		m_timer++;
		return;
	}
	else
	{
		m_timer = 0;
	}

	// Chance if he will think
	if( getProbability(25) )
	{
		m_timer = 0;
		mp_processState = &CCouncilMember::processThinking;
		setAction(A_COUNCIL_MEMBER_THINK);
		return;
	}

	// Move normally in the direction
Gerhard Stein's avatar
Gerhard Stein committed
73
	if( xDirection == RIGHT )
74
		moveRight( m_Action.velX<<1 );
75
	else
76
		moveLeft( m_Action.velX<<1 );
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93

}



void CCouncilMember::processThinking()
{
	if( getActionStatus(A_COUNCIL_MEMBER_MOVE) )
	{
		setAction(A_COUNCIL_MEMBER_MOVE);
		mp_processState = &CCouncilMember::processWalking;
	}
}




94 95
void CCouncilMember::process()
{
96 97 98
	(this->*mp_processState)();

	if( blockedl )
Gerhard Stein's avatar
Gerhard Stein committed
99
		xDirection = RIGHT;
100
	else if(blockedr)
Gerhard Stein's avatar
Gerhard Stein committed
101
		xDirection = LEFT;
102

103 104
	if(!processActionRoutine())
			exists = false;
105 106
}

107 108 109



110
void CCouncilMember::getTouchedBy(CSpriteObject &theObject)
111
{
112 113 114
	if(rescued)
		return;

Gerstrong's avatar
Gerstrong committed
115
	// When Keen touches the Council Member exit the level and add one to the council list
Gerhard Stein's avatar
Gerhard Stein committed
116
	//if( typeid(theObject) == typeid(CPlayerLevel) )
Gerhard Stein's avatar
Gerhard Stein committed
117
	if( CPlayerBase *player = dynamic_cast<CPlayerBase*>(&theObject) )
118
	{
Gerhard Stein's avatar
Gerhard Stein committed
119
		int &rescuedelders = player->m_Inventory.Item.m_special.ep4.elders;
120

Gerstrong's avatar
Gerstrong committed
121
		CEventContainer& EventContainer = g_pBehaviorEngine->m_EventList;
122

Gerstrong's avatar
Gerstrong committed
123
		// TODO: In this part we have to check which level we are and send the proper messages
124

Gerstrong's avatar
Gerstrong committed
125 126
		g_pSound->playSound(SOUND_RESCUE_COUNCIL_MEMBER, PLAY_PAUSEALL);
		EventContainer.add( new EventPlayTrack(5) );
127

Gerstrong's avatar
Gerstrong committed
128
		std::string elder_text[2];
129

Gerhard Stein's avatar
Gerhard Stein committed
130
		if( mp_Map->getLevel() == 17 ) // Under water the text is a bit different
131 132 133 134 135 136 137 138 139 140 141
		{
			elder_text[0] = g_pBehaviorEngine->getString("ELDERS_UNDERWATER_TEXT");
			elder_text[1] = "";
		}
		else
		{
			elder_text[0] = g_pBehaviorEngine->getString("ELDERS_TEXT");
			elder_text[1] = g_pBehaviorEngine->getString(answermap[rescuedelders]);
		}


142 143
		std::vector< SmartPointer<EventSendBitmapDialogMsg> > msgs;

144 145
		msgs.push_back( new EventSendBitmapDialogMsg(g_pGfxEngine->getBitmap(104), elder_text[0], LEFT) );
		msgs.push_back( new EventSendBitmapDialogMsg(*g_pGfxEngine->getBitmap("KEENTHUMBSUP"), elder_text[1], RIGHT) );
146

147

Gerstrong's avatar
Gerstrong committed
148
		if(rescuedelders == 7)
149
			msgs.push_back( new EventSendBitmapDialogMsg(*g_pGfxEngine->getBitmap("KEENTHUMBSUP"), g_pBehaviorEngine->getString(answermap[8]), RIGHT) );
150 151 152


		EventContainer.add( new EventSendBitmapDialogMessages(msgs) );
153

Gerstrong's avatar
Gerstrong committed
154 155
		EventContainer.add( new EventExitLevel(mp_Map->getLevel(), true) );
		rescuedelders++;
156

Gerstrong's avatar
Gerstrong committed
157
		rescued = true;
158 159 160
	}
}

161
}