HLDS_DLLEXPORT void SV_MoveToOrigin_I(edict_t *ent, const vec3_t pflGoal, float dist, int iMoveType) { vec3_t var_c_temp; var_c_temp[0] = pflGoal[0]; var_c_temp[1] = pflGoal[1]; var_c_temp[2] = pflGoal[2]; if(ent->v.flags & (FL_FLY | FL_SWIM | FL_ONGROUND)) { if(iMoveType == MOVE_NORMAL) { if(SV_StepDirection(ent, ent->v.ideal_yaw, dist) == 0) { SV_NewChaseDir2(ent, var_c_temp, dist); } } else { var_c_temp[0] -= ent->v.origin[0]; var_c_temp[1] -= ent->v.origin[1]; if(ent->v.flags & (FL_FLY | FL_SWIM)) { var_c_temp[2] -= ent->v.origin[2]; } else { //If on ground, I guess we just don't worry about the third axis. Sorta makes sense. var_c_temp[2] = 0; } VectorNormalize(var_c_temp); VectorScale(var_c_temp, dist, var_c_temp); SV_FlyDirection(ent, var_c_temp); } } }
// NOTE: pos should be the final goal, because monster will stop moving after reaching it! void M_MoveToPosition (edict_t *ent, vec3_t pos, float dist) { vec3_t v; // stay in-place for medic healing if (ent->holdtime > level.time) return; // need to be touching the ground if (!ent->groundentity && !(ent->flags & (FL_FLY|FL_SWIM)) && !ent->waterlevel) { //gi.dprintf("not touching ground\n"); return; } // we are close enough if (distance(ent->s.origin, pos) < 32) { //gi.dprintf("close enough %.0f\n", distance(ent->s.origin, pos)); // look at the final position VectorSubtract(pos, ent->s.origin, v); VectorNormalize(v); ent->ideal_yaw = vectoyaw(v); M_ChangeYaw(ent); return; } // dont move so fast in the water if (!(ent->flags & (FL_FLY|FL_SWIM)) && (ent->waterlevel > 1)) dist *= 0.5; // if we can't take a step, try moving in another direction if (!SV_StepDirection (ent, ent->ideal_yaw, dist, true)) { //gi.dprintf("couldn't step\n"); // if the monster hasn't moved much, then increment // the number of frames it has been stuck if (distance(ent->s.origin, ent->monsterinfo.stuck_org) < 64) ent->monsterinfo.stuck_frames++; else ent->monsterinfo.stuck_frames = 0; // record current position for comparison VectorCopy(ent->s.origin, ent->monsterinfo.stuck_org); // attempt a course-correction if (ent->inuse && (level.time > ent->monsterinfo.bump_delay)) { //gi.dprintf("tried course correction\n"); //SV_NewChaseDir (ent, goal, dist); SV_NewChaseDir2(ent, pos, dist); ent->monsterinfo.bump_delay = level.time + FRAMETIME*GetRandom(3, 9); return; } } //else //gi.dprintf("step OK\n"); }