ACR Creature Events
Posted: Tue Sep 18, 2007 11:53 pm
Noticed the ACR_CreatureOnHeartbeat() event grew some with a recent update, looks like some kind of manual handling of Perception coded in for when the creature is a PC (PC Events don't exist, so I'm not sure when this code would even be invoked).
Does this serve some purpose, or would it better be handled in the OnPerception() event?
Found it while searching for the probable cause for the CPU cycle buildup on the OAS2, but that problem predated the recent acr_creature_i.nss update.
Does this serve some purpose, or would it better be handled in the OnPerception() event?
Code: Select all
241 // if this is a pc, check if they perceive any creatures
242 if (GetIsPC(OBJECT_SELF))
243 {
244 // ignore DMs
245 if (GetIsDM(OBJECT_SELF) || GetIsDMPossessed(OBJECT_SELF)) { return; }
246
247 // do the math - calculate an coordinate offset based on orientation angle
248
249 vector vPosition = GetPositionFromLocation(GetLocation(OBJECT_SELF));
250 float fX, fY, fLength = RADIUS_SIZE_VAST, fRatio = fLength/90.0, fFacing = GetFacing(OBJECT_SELF);
251 int nNumIncrements = FloatToInt(fFacing) % 90;
252
253 // handle angle rollovers
254 if (fFacing == 360.0) { fFacing = 0.0; }
255
256 // compute the target x and y coordinates based on the orientation quadrant
257 if (fFacing < 90.0 && fFacing >= 0.0)
258 {
259 fX = vPosition.x + fLength - (nNumIncrements * fRatio); fY = vPosition.y + (nNumIncrements * fRatio);
260 }
261 else if (fFacing < 180.0 && fFacing >= 90.0)
262 {
263 fX = vPosition.x - (nNumIncrements * fRatio); fY = vPosition.y + fLength - (nNumIncrements * fRatio);
264 }
265 else if (fFacing < 270.0 && fFacing >= 180.0)
266 {
267 fX = vPosition.x - fLength + (nNumIncrements * fRatio); fY = vPosition.y - (nNumIncrements * fRatio);
268 }
269 else if (fFacing < 360.0 && fFacing >= 270.0)
270 {
271 fX = vPosition.x + (nNumIncrements * fRatio); fY = vPosition.y - fLength + (nNumIncrements * fRatio);
272 }
273
274 // generate the location marking the endpoint of the cone
275 location lLocation = Location(GetArea(OBJECT_SELF), Vector(fX, fY, vPosition.z), fFacing);
276
277 // find objects within their viewing range
278 object oTarget = GetFirstObjectInShape(SHAPE_SPELLCONE, fLength, lLocation, TRUE);
279
280 // loop through the matching creature objects and check if the pc identifies any he sees
281 while(GetIsObjectValid(oTarget))
282 {
283 if (GetObjectSeen(oTarget)) { ACR_CreatureIdentify(OBJECT_SELF, oTarget); }
284 oTarget = GetNextObjectInShape(SHAPE_SPELLCONE, fLength, lLocation, TRUE);
285 }
286 }
287 else
288 {
289 // apply any effects on the creature
290 ACR_VFXOnHeartBeat(OBJECT_SELF);
291
292 // still call the Obsidian script for AI for now.
293 ExecuteScript("nw_c2_default1", OBJECT_SELF);
294 }