convert line ends
[canaan.git] / prj / cam / src / shock / shkaisho.cpp
blobf04e66e4c94615943ae9fb5f9c5fa4e801e16ec0
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 ///////////////////////////////////////////////////////////////////////////////
7 // $Header: r:/t2repos/thief2/src/shock/shkaisho.cpp,v 1.2 2000/02/19 12:36:31 toml Exp $
8 //
9 //
12 #include <shkaisho.h>
14 #include <shkaicha.h>
15 #include <shkaiexp.h>
17 #include <appagg.h>
19 #include <autolink.h>
20 #include <speech.h>
21 #include <traitman.h>
23 #include <property.h>
24 #include <propbase.h>
25 #include <propface.h>
27 #include <aiactloc.h>
28 #include <aiactmot.h>
29 #include <aiactseq.h>
30 #include <aiactinv.h>
31 #include <aiapisnd.h>
32 #include <aiprops.h>
33 #include <aisndtyp.h>
34 #include <memall.h>
35 #include <dbmem.h> // must be last header!
37 ///////////////////////////////////////////////////////////////////////////////
39 IFloatProperty * g_pAIShodanExplodeRangeProperty;
41 static sPropertyDesc g_AIShodanExplodeRangePropertyDesc =
43 "ShodanExpl",
45 NULL, 0, 0,
46 { AI_ABILITY_CAT, "Shodan: Explode range" },
49 #define AIGetShodanExplodeRange(obj) AIGetProperty(g_pAIShodanExplodeRangeProperty, (obj), (float)5.0)
51 ///////////////////////////////////////
53 void ShockAIInitShodan()
55 g_pAIShodanExplodeRangeProperty = CreateFloatProperty(&g_AIShodanExplodeRangePropertyDesc, kPropertyImplVerySparse);
58 ///////////////////////////////////////
60 void ShockAITermShodan()
62 SafeRelease(g_pAIShodanExplodeRangeProperty);
65 ///////////////////////////////////////////////////////////////////////////////
67 // CLASS: cAIShodanCombat
70 cAIShodanCombat::cAIShodanCombat()
72 SetMode(kAIShodanClosing);
75 ///////////////////////////////////////
77 void cAIShodanCombat::SetMode(eAIShodanCombatMode mode)
79 m_mode = mode;
82 ///////////////////////////////////////
84 STDMETHODIMP_(const char *) cAIShodanCombat::GetName()
86 return "Shodan combat";
89 ///////////////////////////////////////
91 void cAIShodanCombat::TestTarget(void)
93 ObjID target = GetTarget();
94 if (target)
96 float rangeSq = AIGetShodanExplodeRange(GetID());
97 rangeSq *= rangeSq;
98 float targDistSq = m_pAIState->DistSq(*GetObjLocation(target));
100 if (targDistSq < rangeSq)
102 SetMode(kAIShodanStartExplode);
103 SignalAction();
108 //////////////////////////////////////
110 STDMETHODIMP_(void) cAIShodanCombat::OnActionProgress(IAIAction * pAction)
112 cAICombat::OnActionProgress(pAction);
114 if (IsOwn(pAction) && pAction->GetResult() >= kAIR_Success)
116 SetMode(kAIShodanClosing);
117 SignalAction();
118 TestTarget();
120 else if (IsOwn(pAction) && (m_mode == kAIShodanClosing) && pAction->GetResult() >= kAIR_NoResult)
121 TestTarget();
124 ///////////////////////////////////////
126 STDMETHODIMP cAIShodanCombat::SuggestActions(cAIGoal * pGoal, const cAIActions & previous, cAIActions * pNew)
128 ObjID target = GetTarget();
130 if (target == OBJ_NULL)
131 return S_OK;
133 if (m_mode == kAIShodanStartExplode)
135 ObjID projID;
136 sAIProjectileRel* pProjData;
138 if (GetProjectile(&projID, &pProjData))
140 cAIExplodeAction* pAction = new cAIExplodeAction(this);
141 pAction->Set(projID);
142 SetMode(kAIShodanExploding);
143 pNew->Append(pAction);
145 else
147 Warning(("No projectile link for shodan creature %d\n", m_pAIState->GetID()));
148 SetMode(kAIShodanClosing);
151 if (m_mode == kAIShodanClosing)
153 m_pAI->AccessSoundEnactor()->RequestConcept(kAISC_CombatAttack);
154 cAIChargeAction* pAction = new cAIChargeAction(this, 0);
155 pAction->Set(target, kAIT_1Sec);
156 pNew->Append(pAction);
158 return S_OK;
161 ///////////////////////////////////////////////////////////////////////////////
163 BOOL cAIShodanCombat::GetProjectile(ObjID* pProjectileID, sAIProjectileRel** ppProjData)
165 AutoAppIPtr(TraitManager);
166 cAutoLinkQuery query(g_pAIProjectileRelation, pTraitManager->GetArchetype(m_pAIState->GetID()), LINKOBJ_WILDCARD);
167 if (!query->Done())
169 *pProjectileID = query.GetDest();
170 *ppProjData = (sAIProjectileRel*)(query->Data());
171 return TRUE;
173 return FALSE;