Linux makefiles
[canaan.git] / prj / cam / src / shock / shkaigra.cpp
blob3e28d4151faf3d34e8daf6a69b12c309be8fd0a4
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 ///////////////////////////////////////////////////////////////////////////////
7 // $Header: r:/t2repos/thief2/src/shock/shkaigra.cpp,v 1.5 1999/06/16 16:47:00 JON Exp $
8 //
10 #include <lg.h>
12 #include <aiactloc.h>
13 #include <aiapiiai.h>
14 #include <aiapipth.h>
15 #include <aidebug.h>
16 #include <aipathdb.h>
17 #include <aiutils.h>
19 #include <appagg.h>
20 #include <dmgmodel.h>
21 #include <iobjsys.h>
22 #include <phlisbas.h>
23 #include <physapi.h>
24 #include <speech.h>
26 #include <shkaibit.h>
27 #include <shkaicha.h>
28 #include <shkaigra.h>
29 #include <shkaipr.h>
31 // Must be last header
32 #include <dbmem.h>
34 //////////////////////////////////////////////////////////////////////////////
36 void ShockAIInitGrubCombatAbility(void)
40 void ShockAITermGrubCombatAbility(void)
44 ///////////////////////////////////////////////////////////////////////////////
46 // CLASS: cAIGrubCombat
49 cAIGrubCombat::cAIGrubCombat():
50 m_leapTimer(1000, 2000)
54 ///////////////////////////////////////
56 cAIGrubCombat::~cAIGrubCombat()
58 ClearNotifications(kAICN_Collision);
61 ///////////////////////////////////////
62 STDMETHODIMP_(void) cAIGrubCombat::Init()
64 cAICombat::Init();
67 ///////////////////////////////////////
69 STDMETHODIMP_(void) cAIGrubCombat::OnSimStart()
71 sAIGrubCombatParams* pParams = ShockAIGetGrubCombatParams(GetID());
72 m_leapTimer.Set(pParams->m_minLeapTime, pParams->m_maxLeapTime);
73 m_state = kAIGrubCombatNothing;
74 m_biteDist = pParams->m_biteDist;
75 m_leapDist = pParams->m_leapDist;
76 cAICombat::OnSimStart();
79 ///////////////////////////////////////
81 STDMETHODIMP_(const char *) cAIGrubCombat::GetName()
83 return "GrubCombat Ability";
86 ///////////////////////////////////////
88 STDMETHODIMP_(BOOL) cAIGrubCombat::Save(ITagFile * pTagFile)
90 // @TODO:
91 return TRUE;
94 ///////////////////////////////////////
96 STDMETHODIMP_(BOOL) cAIGrubCombat::Load(ITagFile * pTagFile)
98 // @TODO:
99 return TRUE;
102 ///////////////////////////////////////
104 void cAIGrubCombat::SetState(eAIGrubCombatState state)
106 switch (state)
108 case kAIGrubCombatCharge:
109 SetNotifications(kAICN_Collision);
110 m_leapTimer.Reset();
111 break;
112 default:
113 ClearNotifications(kAICN_Collision);
115 SignalAction();
116 m_state = state;
119 ///////////////////////////////////////
121 STDMETHODIMP_(void) cAIGrubCombat::OnGoalChange(const cAIGoal * pPrevious, const cAIGoal * pGoal)
123 cAICombat::OnGoalChange(pPrevious, pGoal);
124 if (InControl())
125 SetState(kAIGrubCombatCharge);
128 ///////////////////////////////////////
130 STDMETHODIMP_(void) cAIGrubCombat::OnActionProgress(IAIAction * pAction)
132 cAICombat::OnActionProgress(pAction);
133 if (IsOwn(pAction) && (pAction->GetResult()>=kAIR_Success))
135 switch (pAction->GetType())
137 case kAIAT_Bite:
138 SetState(kAIGrubCombatCharge);
139 break;
140 case kAIAT_Charge:
141 if (((cAIChargeAction*)pAction)->ToObject())
143 // decide whether or not to leap
144 cMxsVector dest;
145 float targDistSq;
147 GetObjLocation(GetTarget(), &dest);
148 targDistSq = m_pAIState->DistSq(dest);
149 if (PhysObjOnGround(m_pAIState->GetID()) && (m_leapTimer.Expired() && (targDistSq<=(m_leapDist*m_leapDist))))
150 SetState(kAIGrubCombatLeap);
152 else
153 SetState(kAIGrubCombatCharge);
154 break;
155 default:
156 Warning(("cAIGrubCombat: unexpected action type %d\n", pAction->GetType()));
161 ////////////////////////////////////////////////
163 STDMETHODIMP_(void) cAIGrubCombat::OnCollision(const sPhysListenMsg* pMsg)
165 if (m_state == kAIGrubCombatCharge)
167 if (pMsg->collNormal.z == 1)
168 return;
169 SetState(kAIGrubCombatRandom);
173 ////////////////////////////////////////////////
175 STDMETHODIMP cAIGrubCombat::SuggestActions(cAIGoal * pGoal, const cAIActions & previous, cAIActions * pNew)
177 switch (m_state)
179 case kAIGrubCombatCharge:
181 cAIChargeAction* pChargeAction = new cAIChargeAction(this, 0);
182 if (pChargeAction != NULL)
184 // @TODO: propertize re-path period
185 pChargeAction->Set(GetTarget(), kAIT_1Sec);
186 pNew->Append(pChargeAction);
189 break;
190 case kAIGrubCombatRandom:
192 cAIChargeAction* pChargeAction = new cAIChargeAction(this, 0);
193 if (pChargeAction != NULL)
195 const mxs_vector& aiLoc = *m_pAIState->GetLocation();
196 floatang angle;
197 mxs_vector target;
199 angle.value = DEGREES(AIRandom(0, 360));
200 ProjectFromLocationOnZPlane(aiLoc, 3, angle, &target);
201 // @TODO: propertize re-path period
202 pChargeAction->Set(target, kAIT_2Sec);
203 pNew->Append(pChargeAction);
206 break;
207 case kAIGrubCombatLeap:
209 cAIBiteAction * pBiteAction = new cAIBiteAction(this, 0);
210 if (pBiteAction != NULL)
212 AutoAppIPtr(ObjectSystem);
213 sAIGrubCombatParams* pParams = ShockAIGetGrubCombatParams(GetID());
214 pBiteAction->Set(GetTarget(), pParams->m_biteDist, pObjectSystem->GetObjectNamed(pParams->m_stimulus), pParams->m_intensity,
215 pParams->m_leapSpeedX, pParams->m_leapSpeedZ);
216 pNew->Append(pBiteAction);
219 break;
221 return S_OK;