void main(){ int seed=4; int i; int position = seed; printf("seed: %d\n", seed); for(i=0;i<21;i=i+1){ int step = step_direction(seed); position = position + step; if (position>10) {position = 1;}; if (position<1) {position = 10;}; printf("position: %d\n",position); } }
void Server::move_to_goal(edict_t *ent, edict_t *goal, float dist) { if (!((int)ent->v.flags & (FL_ONGROUND | FL_FLY | FL_SWIM))) { return; } // if the next step hits the enemy, return immediately if (m_progs->prog_to_edict(ent->v.enemy) != m_progs->m_edicts[0] && close_enough(ent, goal, dist)) return; // bump around... if ((rand() & 3) == 1 || !step_direction(ent, ent->v.ideal_yaw, dist)) { new_chase_dir(ent, goal, dist); } }
void Server::new_chase_dir(edict_t *actor, edict_t *enemy, float dist) { float deltax, deltay; float d[3]; float tdir, olddir, turnaround; olddir = anglemod((int)(actor->v.ideal_yaw / 45) * 45); turnaround = anglemod(olddir - 180); deltax = enemy->v.origin[0] - actor->v.origin[0]; deltay = enemy->v.origin[1] - actor->v.origin[1]; if (deltax>10) d[1] = 0; else if (deltax<-10) d[1] = 180; else d[1] = DI_NODIR; if (deltay<-10) d[2] = 270; else if (deltay>10) d[2] = 90; else d[2] = DI_NODIR; // try direct route if (d[1] != DI_NODIR && d[2] != DI_NODIR) { if (d[1] == 0) tdir = d[2] == 90 ? 45 : 315; else tdir = d[2] == 90 ? 135 : 215; if (tdir != turnaround && step_direction(actor, tdir, dist)) return; } // try other directions if (((rand() & 3) & 1) || abs(deltay)>abs(deltax)) { tdir = d[1]; d[1] = d[2]; d[2] = tdir; } if (d[1] != DI_NODIR && d[1] != turnaround && step_direction(actor, d[1], dist)) return; if (d[2] != DI_NODIR && d[2] != turnaround && step_direction(actor, d[2], dist)) return; /* there is no direct path to the player, so pick another direction */ if (olddir != DI_NODIR && step_direction(actor, olddir, dist)) return; if (rand() & 1) /*randomly determine direction of search*/ { for (tdir = 0; tdir <= 315; tdir += 45) if (tdir != turnaround && step_direction(actor, tdir, dist)) return; } else { for (tdir = 315; tdir >= 0; tdir -= 45) if (tdir != turnaround && step_direction(actor, tdir, dist)) return; } if (turnaround != DI_NODIR && step_direction(actor, turnaround, dist)) return; actor->v.ideal_yaw = olddir; // can't move // if a bridge was pulled out from underneath a monster, it may not have // a valid standing position at all if (!check_bottom(actor)) fix_check_bottom(actor); }