/** * CAIStateQBRangeAttack::update * @date Modified May 9, 2006 */ void CAIStateQBRangeAttack::update(CAIEntity* poAIEntity, CCharacter* poCharacter) { ((CAnimatedMesh*)poCharacter->getMesh())->setAnimationSetByName("Attack"); // look at the player D3DXVECTOR3 vAtGoal; CAINode* poGoalNode = CAIManager::getInstancePtr()->findBestGoal(poCharacter); D3DXVec3Subtract(&vAtGoal, &poGoalNode->getPosition(), &poCharacter->getPosition()); D3DXVec3Normalize(&vAtGoal, &vAtGoal); poCharacter->setOrientation(vAtGoal); // wait for the animation to play if (poAIEntity->getCurrentStateTime() < ((CAnimatedMesh*)poCharacter->getMesh())->getAnimationLength()) return; // spawn projectile CFootBall* poBall = (CFootBall*)CObjectManager::getInstancePtr()->createObject(OBJ_WEAPONPROJ_FOOTBALL); vAtGoal = poCharacter->getBV().centerPt; vAtGoal.y += 10.0f; poBall->setPosition(vAtGoal); D3DXVec3Subtract(&vAtGoal, &poGoalNode->getPosition(), &vAtGoal); D3DXVec3Normalize(NULL, &vAtGoal, &vAtGoal); poBall->setOrientation(vAtGoal); poBall->setVelocity(*D3DXVec3Scale(&vAtGoal, &vAtGoal, 50.0f)); poBall->setBV(poBall->getPosition(), 2.0f); poBall->setPlayer((CPlayer*)poCharacter); ((CEnemy*)(poCharacter))->setAIState(CAIStateQBMeleeAttack::getInstancePtr()); }
/** * CAIStateAcidicAttack::update * @date Modified May 4, 2006 */ void CAIStateAcidicAttack::update(CAIEntity* poAIEntity, CCharacter* poCharacter) { D3DCOLOR color = poCharacter->getColor(); if (color == 0xff000000) poCharacter->setColor(0xff005555); else poCharacter->setColor(0xff000000); // look at the player D3DXVECTOR3 vAtGoal; CAINode* poGoalNode = CAIManager::getInstancePtr()->findBestGoal(poCharacter); D3DXVec3Subtract(&vAtGoal, &poGoalNode->getPosition(), &poCharacter->getPosition()); D3DXVec3Normalize(&vAtGoal, &vAtGoal); poCharacter->setOrientation(vAtGoal); // wait so we can flash a bit and then throw if (poAIEntity->getCurrentStateTime() < 0.5) return; ((CAnimatedMesh*)poCharacter->getMesh())->setAnimationSetByName("Attack"); // wait for the animation to play if (poAIEntity->getCurrentStateTime() < (((CAnimatedMesh*)poCharacter->getMesh())->getAnimationLength() + 0.5)) return; // spawn projectile CIceCream* poBall = (CIceCream*)CObjectManager::getInstancePtr()->createObject(OBJ_WEAPONPROJ_ACIDICE); vAtGoal = poCharacter->getBV().centerPt; vAtGoal.y += 10.0f; poBall->setPosition(vAtGoal); D3DXVec3Subtract(&vAtGoal, &poGoalNode->getPosition(), &vAtGoal); D3DXVec3Normalize(NULL, &vAtGoal, &vAtGoal); poBall->setOrientation(vAtGoal); poBall->setVelocity(*D3DXVec3Scale(&vAtGoal, &vAtGoal, 50.0f)); poBall->setBV(poBall->getPosition(), 2.0f); poBall->setPlayer((CPlayer*)poCharacter); ((CEnemy*)(poCharacter))->setAIState(CAIStateAcidicFollow::getInstancePtr()); }
/** * CAIGroup::disband * @date Modified April 26, 2006 */ void CAIGroup::disband(bool bDisperse) { std::list<CEnemy*>::iterator oEnemyIter = m_loEnemies.begin(); CAIStatePathPlan* poPlan = CAIStatePathPlan::getInstancePtr(); // for dispersal CAIStateMove* poMove = NULL; D3DXVECTOR3 vFrontBack(0.0f, 0.0f, 0.0f), vLeftRight(0.0f, 0.0f, 0.0f), vTemp(0.0f, 0.0f, 0.0f); CAINode* poGoalNode = NULL; float fDot = 0.0f; // if the enemies are to disperse, this information is needed if (bDisperse) { poMove = CAIStateMove::getInstancePtr(); calculateAvgPos(); poGoalNode = CAIManager::getInstancePtr()->findBestGoal(*oEnemyIter); // calculate vectors to perform a halfspace tests to determine members' position in the group D3DXVec3Subtract(&vFrontBack, &poGoalNode->getPosition(), &m_vAvgPos); D3DXVec3Normalize(NULL, &vFrontBack, &vFrontBack); D3DXVec3Cross(&vLeftRight, &D3DXVECTOR3(0.0f, 1.0f, 0.0f), &vLeftRight); D3DXVec3Normalize(NULL, &vLeftRight, &vLeftRight); } while (oEnemyIter != m_loEnemies.end()) { (*oEnemyIter)->getAI()->setGroup(NULL); if (bDisperse) { if ((*oEnemyIter)->getType() == OBJ_ENEMY_ZOMBIECITIZEN) { D3DXVec3Subtract(&vTemp, &ENEMY_PTR(oEnemyIter)->getBV().centerPt, &m_vAvgPos); D3DXVec3Normalize(NULL, &vTemp, &vTemp); fDot = D3DXVec3Dot(&vTemp, &vFrontBack); // if this enemy is in back send him straight to the goal if (fDot <= 0.0f) { (*oEnemyIter)->setAIState(poPlan); } // if this enemy is in front, make him move forward else { ENEMY_PTR(oEnemyIter)->setOrientation(vTemp); D3DXVec3Scale(&vTemp, &vFrontBack, 10.0f); ENEMY_PTR(oEnemyIter)->setVelocity(vTemp); (*oEnemyIter)->setAIState(poMove); } } else { (*oEnemyIter)->setAIState(poPlan); } } else { (*oEnemyIter)->setAIState(poPlan); } oEnemyIter = m_loEnemies.erase(oEnemyIter); } }