33 aiMobState_Flyer::aiMobState_Flyer(
void)
37 aiMobState_Flyer::~aiMobState_Flyer(
void)
46 fp->readDouble(&_dFlutterRange);
47 fp->readDouble(&_dSwayRange);
48 fp->readDouble(&_dFSSpeed);
55 void aiMobState_Flyer::perceive_active( std::string strID_Old )
60 pMonster->getPivot()-> bSimulateGravitation = M_FALSE;
61 pMonster->move_v( laPoint3(1,0,0) );
63 dY_Initial = pMonster->getPosition().y();
65 pMonster->agressive(M_TRUE);
66 pMonster->enableBattleGUI(M_FALSE);
69 void aiMobState_Flyer::perceive_inactive( std::string strID_New )
87 void aiMobState_Flyer::perceive_InRange(
unsigned state)
95 pMonster->enableBattleGUI(M_TRUE);
97 pMonster->attackInitiate();
101 if( pMonster->attackIsCharged() ) {
102 pMonster->attack(pPlayer);
105 pMonster->attackSelect(M_MATTACK_MAIN + rand()%2);
106 pMonster->attackInitiate();
111 pMonster->enableBattleGUI(M_FALSE);
112 pMonster->attackStop();
117 void aiMobState_Flyer::perceive(
unsigned state, M_BOOL global,
unsigned id, aiPerceptData data)
120 laPivot *pMobPivot = pMonster->getPivot();
122 aiMobState::perceive(state, global,
id, data);
128 laPoint3 dir = laPoint3( pMonster->getMoveDirection(), 0);
129 dir = _update_direction(dir);
130 dir = _chase_player(dir);
131 pMonster->move_v( dir );
139 laPoint3 aiMobState_Flyer::_update_direction(laPoint3 dir)
143 if( _obstacle_infront() )
145 dir[0] = -1 * dir.x();
151 if( !_within_left_range() )
154 if( !_within_right_range() )
161 laPoint3 aiMobState_Flyer::_chase_player(laPoint3 dir)
168 M_BOOL bChase = M_FALSE;
170 if( _within_left_range() && _within_right_range() )
175 if(
M_ABS(pPlayer->getPosition().y() - pMonster->getPosition().y() ) >
M_UNIT )
177 if( pPlayer->getPosition().y() > pMonster->getPosition().y() ) dir[1] = +1;
181 else if( pPlayer->getPosition().y() < pMonster->getPosition().y() +
M_UNIT * 0.8 )
188 if( (!agent()->isPerceiving(P__PLAYER_IN_RANGE))
190 M_ABS(pPlayer->getPosition().x() - pMonster->getPosition().x() ) >
M_UNIT )
192 if( pPlayer->getPosition().x() > pMonster->getPosition().x() ) dir[0] = +1;
199 if(
M_ABS(pPlayer->getPosition().x() - pMonster->getPosition().x() ) <
M_UNIT * 0.8 )
201 if( pMonster->getPosition().x() > pPlayer->getPosition().x() )
203 pMonster->setExplicitFacing(M_TRUE);
204 pMonster->setFaceDirection(-1);
209 pMonster->setExplicitFacing(M_TRUE);
210 pMonster->setFaceDirection(+1);
214 else pMonster->setExplicitFacing(M_FALSE);
218 pPlayer->ctlBattleMode();
222 _select_creature( bChase );
232 if( (!bChase) && (
M_ABS(dY_Initial - pMonster->getPosition().y() ) >= 0.1 *
M_UNIT) )
234 if( dY_Initial > pMonster->getPosition().y() ) dir[1] = +1;
245 void aiMobState_Flyer::_flutter()
248 laPivot *pMobPivot = pMonster->getPivot();
249 double spf = ::laSystemIntegrator::getEnvironment()->getTimer()->delta();
251 double var1 = sin(_ang);
252 double var2 = sin(_ang*2);
253 double var3 = sin(_ang*3);
256 pMobPivot->ptGeometryOffset[0] = var1 *
M_UNIT * _dFlutterRange;
257 pMobPivot->ptGeometryOffset[1] = var2 *
M_UNIT * _dFlutterRange;
258 pMobPivot->ptGeometryOffset[2]= var3 *
M_UNIT * _dFlutterRange;
259 pMobPivot->angleZ = var1 * _dSwayRange - _dSwayRange/2.0;
260 pMobPivot->angleX = var2 * _dSwayRange - _dSwayRange/2.0;
262 _ang += spf * _dFSSpeed;
263 if( _ang > 360 ) _ang -= 360;
266 M_BOOL aiMobState_Flyer::_in_y_range(
double distance)
270 if(
M_ABS(dY_Initial - pMonster->getPosition().y() ) <= distance )
275 M_BOOL aiMobState_Flyer::_obstacle_infront()
278 laPivot *pMobPivot = pMonster->getPivot();
280 int direction = pMonster->getMoveDirection();
281 laPoint3 vTentacle(direction*
M_UNIT*2, 0, 0);
284 vPivot[1] +=
M_UNIT * 0.3;
288 vTentacle = vPivot.projectVector(vTentacle);
290 if( vTentacle.lenght() <= (vPivot.size.x()*0.5 +
M_UNIT*0.15) )
return M_TRUE;
294 M_BOOL aiMobState_Flyer::_obstacle_below()
297 laPivot *pMobPivot = pMonster->getPivot();
299 int direction = pMonster->getMoveDirection();
300 laPoint3 vTentacle(0,
M_UNIT, 0);
304 vTentacle = vPivot.projectVector(vTentacle);
306 if( vTentacle.lenght() <=
M_UNIT*0.8 )
return M_TRUE;
310 M_BOOL aiMobState_Flyer::_obstacle_above()
313 laPivot *pMobPivot = pMonster->getPivot();
315 int direction = pMonster->getMoveDirection();
316 laPoint3 vTentacle(0, -1*
M_UNIT, 0);
320 vTentacle = vPivot.projectVector(vTentacle);
322 if( vTentacle.lenght() <=
M_UNIT*0.8 )
return M_TRUE;
#define M_UNIT
Unit of 1 meter.
#define M_ABS(a)
Return abs(a)
Adds capabilities and percepts specific to monster creatures.