int KHero::LuaMoveToTarget(Lua_State* L) { BOOL bRetCode = false; int nDestX = 0; int nDestY = 0; int nDestZ = 0; int nDirection = 0; BOOL bWalk = false; int nTopIndex = 0; nTopIndex = Lua_GetTopIndex(L); KG_PROCESS_ERROR(nTopIndex == 1); bWalk = Lua_ValueToBoolean(L, 1); bRetCode = GetAITargetPos(nDestX, nDestY, nDestZ); KG_PROCESS_ERROR(bRetCode); nDirection = g_GetDirection(m_nX, m_nY, nDestX, nDestY); if (bWalk) bRetCode = WalkTo(nDirection, true); else bRetCode = RunTo(nDirection, true); Exit0: return 0; }
void army::MoveTo(int hexIdx) { if(this->creature.creature_flags & FLYER) { this->targetHex = hexIdx; if(ValidFlight(this->targetHex, 0)) FlyTo(this->targetHex); } else { WalkTo(hexIdx); } }
/** * Run appropriate actor or polygon glitter code. * If none, and it's a WALKTO event, do a walk. */ static void ProcessUserEvent(TINSEL_EVENT uEvent, const Common::Point &coOrds, PLR_EVENT be = PLR_NOEVENT) { int actor; int aniX, aniY; HPOLYGON hPoly; // Prevent activation of 2 events on the same tick if (++g_eCount != 1) return; if ((actor = GetTaggedActor()) != 0) { // Event for a tagged actor if (TinselV2) ActorEvent(Common::nullContext, actor, uEvent, false, 0); else ActorEvent(actor, uEvent, be); } else if ((hPoly = GetTaggedPoly()) != NOPOLY) { // Event for active tagged polygon if (!TinselV2) RunPolyTinselCode(hPoly, uEvent, be, false); else if (uEvent != PROV_WALKTO) PolygonEvent(Common::nullContext, hPoly, uEvent, 0, false, 0); } else { GetCursorXY(&aniX, &aniY, true); // There could be a poly involved which has no tag. if ((hPoly = InPolygon(aniX, aniY, TAG)) != NOPOLY || (!TinselV2 && ((hPoly = InPolygon(aniX, aniY, EXIT)) != NOPOLY))) { if (TinselV2 && (uEvent != PROV_WALKTO)) PolygonEvent(Common::nullContext, hPoly, uEvent, 0, false, 0); else if (!TinselV2) RunPolyTinselCode(hPoly, uEvent, be, false); } else if ((uEvent == PROV_WALKTO) || (uEvent == WALKTO)) { if (TinselV2) ProcessedProvisional(); WalkTo(aniX, aniY); } } }
void OldMonsterThink(Entity *self) { Coord v = {0,0,0}; if(self->state == MS_Dead)return;/*no time to think, we're DEAD!*/ if(self->Acd <= 0) { /*only think if I can act*/ switch(self->state) { case MS_Pathing: if(!MonsterAcquireTarget(self)) { if(self->pathstep >= self->pathlen) { /*I have tracked to the last known location!*/ /*must reacquire target*/ if(self->target == NULL) { self->state = MS_Alert; } else { MonsterPath(self, self->target); } } else { /*continue to follow the path*/ WalkTo(self,self->path[self->pathstep]); if(InRangeOfTile(self,self->path[self->pathstep].x, self->path[self->pathstep].y)) { self->pathstep++; } } } break; case MS_Idle: MonsterAcquireTarget(self); break; case MS_Alert: /*look for trouble if no targets*/ MonsterAcquireTarget(self); break; case MS_Hostile: EntLookAtOther(self,self->target); if(self->Acd <= 0) { if(GetInRange(self)) { if(self->Rcd <= 0) { ApplyStandardDelays(self,1,0); self->state = MS_Attacking; self->attacking = 1; self->attackstart = NOW; self->attackframe = 0; if(self->target != NULL) { v.x = self->target->p.x - self->p.x; v.y = self->target->p.y - self->p.y; VectorNormalize(&v); VectorScale(v,32,v); /*using 32 as the spear length, it will be based on weapon stats*/ self->targetpoint.x = self->p.x + v.x; self->targetpoint.y = self->p.y + v.y; } else { AngleVector2D(&v,self->r.z); VectorScale(v,32,v); /*using 32 as the spear length, it will be based on weapon stats*/ self->targetpoint.x = self->p.x + v.x; self->targetpoint.y = self->p.y + v.y; } } } } break; } } Walk(self); }
/* Can See Target -> Hostile Can't See Target ->Pathing Have no Path ->Alert Default -> idle */ void MonsterThink(Entity *self) { Coord v = {0,0,0}; if((self->state == MS_Dead)||(self->state == MS_Deadbody)) { /*no time to think, we're DEAD!*/ self->think = NULL; return; } if(self->Acd > 0)return; switch(self->state) { case MS_Stunned: self->stun--; if(self->stun <= 0)self->state = MS_Hostile; break; case MS_Idle: MonsterAcquireTarget(self); break; case MS_Pathing: if(self->target == NULL) { self->state = MS_Alert; break; } if(CanSeeTarget(self,self->target)) /*if(CanWalkTo(self->p, self->target->p,self->radius,self))*/ { self->state = MS_Hostile; break; } if(self->pathstep >= self->pathlen) { /*must reacquire target*/ if(self->target == NULL) { self->state = MS_Alert; } else { MonsterPath(self, self->target); } } else { /*continue to follow the path*/ WalkTo(self,self->path[self->pathstep]); if(InRangeOfTile(self,self->path[self->pathstep].x, self->path[self->pathstep].y)) { self->pathstep++; } } break; case MS_Hostile: if(self->target == NULL) { self->state = MS_Alert; break; } if(!CanSeeTarget(self,self->target)) { MonsterPath(self,self->target); break; } EntLookAtOther(self,self->target); if(GetInRange(self)) { if(self->Rcd <= 0) { self->state = MS_Attacking; self->attacking = 1; self->attackstart = NOW; self->attackframe = 0; if(self->target != NULL) { v.x = self->target->p.x - self->p.x; v.y = self->target->p.y - self->p.y; VectorNormalize(&v); VectorScale(v,32,v); /*using 32 as the spear length, it will be based on weapon stats*/ self->targetpoint.x = self->p.x + v.x; self->targetpoint.y = self->p.y + v.y; } else { AngleVector2D(&v,self->r.z); VectorScale(v,32,v); /*using 32 as the spear length, it will be based on weapon stats*/ self->targetpoint.x = self->p.x + v.x; self->targetpoint.y = self->p.y + v.y; } } } break; case MS_Alert: MonsterAcquireTarget(self); break; } Walk(self); }