2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
6 ///////////////////////////////////////////////////////////////////////////////
7 // $Header: r:/t2repos/thief2/src/shock/shkaigra.cpp,v 1.5 1999/06/16 16:47:00 JON Exp $
31 // Must be last header
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()
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
)
94 ///////////////////////////////////////
96 STDMETHODIMP_(BOOL
) cAIGrubCombat::Load(ITagFile
* pTagFile
)
102 ///////////////////////////////////////
104 void cAIGrubCombat::SetState(eAIGrubCombatState state
)
108 case kAIGrubCombatCharge
:
109 SetNotifications(kAICN_Collision
);
113 ClearNotifications(kAICN_Collision
);
119 ///////////////////////////////////////
121 STDMETHODIMP_(void) cAIGrubCombat::OnGoalChange(const cAIGoal
* pPrevious
, const cAIGoal
* pGoal
)
123 cAICombat::OnGoalChange(pPrevious
, pGoal
);
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())
138 SetState(kAIGrubCombatCharge
);
141 if (((cAIChargeAction
*)pAction
)->ToObject())
143 // decide whether or not to leap
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
);
153 SetState(kAIGrubCombatCharge
);
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)
169 SetState(kAIGrubCombatRandom
);
173 ////////////////////////////////////////////////
175 STDMETHODIMP
cAIGrubCombat::SuggestActions(cAIGoal
* pGoal
, const cAIActions
& previous
, cAIActions
* pNew
)
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
);
190 case kAIGrubCombatRandom
:
192 cAIChargeAction
* pChargeAction
= new cAIChargeAction(this, 0);
193 if (pChargeAction
!= NULL
)
195 const mxs_vector
& aiLoc
= *m_pAIState
->GetLocation();
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
);
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
);