long creature_move_direct_line_backwards(struct Thing *thing, struct Coord3d *nextpos, MoveSpeed speed) { if (creature_turn_to_face_backwards(thing, nextpos) > 0) { // Creature is turning - don't let it move creature_set_speed(thing, 0); return 2; } struct CreatureControl *cctrl; cctrl = creature_control_get_from_thing(thing); creature_set_speed(thing, -speed); cctrl->flgfield_2 |= TF2_Unkn01; if (get_2d_box_distance(&thing->mappos, nextpos) > -2*cctrl->move_speed) { ERRORDBG(3,"The %s index %d tried to reach (%d,%d) from (%d,%d) with excessive backward speed", thing_model_name(thing),(int)thing->index,(int)nextpos->x.stl.num,(int)nextpos->y.stl.num, (int)thing->mappos.x.stl.num,(int)thing->mappos.y.stl.num); cctrl->moveaccel.x.val = distance_with_angle_to_coord_x(cctrl->move_speed, thing->move_angle_xy); cctrl->moveaccel.y.val = distance_with_angle_to_coord_y(cctrl->move_speed, thing->move_angle_xy); cctrl->moveaccel.z.val = 0; return 1; } else { cctrl->moveaccel.x.val = nextpos->x.val - (MapCoordDelta)thing->mappos.x.val; cctrl->moveaccel.y.val = nextpos->y.val - (MapCoordDelta)thing->mappos.y.val; cctrl->moveaccel.z.val = 0; return 0; } }
void make_camera_deviations(struct PlayerInfo *player,struct Dungeon *dungeon) { long x,y; struct Camera *cam; cam = player->acamera; x = cam->mappos.x.val; y = cam->mappos.y.val; if (dungeon->camera_deviate_quake != 0) { x += UNSYNC_RANDOM(80) - 40; y += UNSYNC_RANDOM(80) - 40; } if (dungeon->camera_deviate_jump != 0) { x += distance_with_angle_to_coord_x(dungeon->camera_deviate_jump, cam->orient_a); y += distance_with_angle_to_coord_y(dungeon->camera_deviate_jump, cam->orient_a); } if ((dungeon->camera_deviate_quake != 0) || (dungeon->camera_deviate_jump != 0)) { // bounding position if (x < 0) { x = 0; } else if (x > 65535) { x = 65535; } if (y < 0) { y = 0; } else if (y > 65535) { y = 65535; } // setting deviated position cam->mappos.x.val = x; cam->mappos.y.val = y; } }
long creature_move_to_using_gates(struct Thing *thing, struct Coord3d *pos, MoveSpeed speed, long a4, NaviRouteFlags flags, TbBool backward) { struct Coord3d nextpos; AriadneReturn follow_result; long i; SYNCDBG(18,"Starting to move %s index %d from (%d,%d) to (%d,%d) with speed %d",thing_model_name(thing), (int)thing->index,(int)thing->mappos.x.stl.num,(int)thing->mappos.y.stl.num,(int)pos->x.stl.num,(int)pos->y.stl.num,(int)speed); TRACE_THING(thing); if ( backward ) { // Rotate the creature 180 degrees to trace route with forward move i = (thing->move_angle_xy + LbFPMath_PI); thing->move_angle_xy = i & LbFPMath_AngleMask; } follow_result = creature_follow_route_to_using_gates(thing, pos, &nextpos, speed, flags); SYNCDBG(18,"The %s index %d route result: %d, next pos (%d,%d)",thing_model_name(thing),(int)thing->index,(int)follow_result,(int)nextpos.x.stl.num,(int)nextpos.y.stl.num); if ( backward ) { // Rotate the creature back i = (thing->move_angle_xy + LbFPMath_PI); thing->move_angle_xy = i & LbFPMath_AngleMask; } if ((follow_result == AridRet_PartOK) || (follow_result == AridRet_Val2)) { creature_set_speed(thing, 0); return -1; } if (follow_result == AridRet_FinalOK) { return 1; } struct CreatureControl *cctrl; cctrl = creature_control_get_from_thing(thing); if ( backward ) { if (creature_turn_to_face_backwards(thing, &nextpos) > 0) { // Creature is turning - don't let it move creature_set_speed(thing, 0); } else { creature_set_speed(thing, -speed); cctrl->flgfield_2 |= TF2_Unkn01; if (get_2d_box_distance(&thing->mappos, &nextpos) > -2*cctrl->move_speed) { ERRORDBG(3,"The %s index %d tried to reach (%d,%d) from (%d,%d) with excessive backward speed", thing_model_name(thing),(int)thing->index,(int)nextpos.x.stl.num,(int)nextpos.y.stl.num, (int)thing->mappos.x.stl.num,(int)thing->mappos.y.stl.num); cctrl->moveaccel.x.val = distance_with_angle_to_coord_x(cctrl->move_speed, thing->move_angle_xy); cctrl->moveaccel.y.val = distance_with_angle_to_coord_y(cctrl->move_speed, thing->move_angle_xy); cctrl->moveaccel.z.val = 0; } else { cctrl->moveaccel.x.val = nextpos.x.val - (MapCoordDelta)thing->mappos.x.val; cctrl->moveaccel.y.val = nextpos.y.val - (MapCoordDelta)thing->mappos.y.val; cctrl->moveaccel.z.val = 0; } } SYNCDBG(18,"Backward target set, speed %d, accel (%d,%d)",(int)cctrl->move_speed,(int)cctrl->moveaccel.x.val,(int)cctrl->moveaccel.y.val); } else { if (creature_turn_to_face(thing, &nextpos) > 0) { // Creature is turning - don't let it move creature_set_speed(thing, 0); } else { creature_set_speed(thing, speed); cctrl->flgfield_2 |= TF2_Unkn01; if (get_2d_box_distance(&thing->mappos, &nextpos) > 2*cctrl->move_speed) { ERRORDBG(3,"The %s index %d tried to reach (%d,%d) from (%d,%d) with excessive forward speed", thing_model_name(thing),(int)thing->index,(int)nextpos.x.stl.num,(int)nextpos.y.stl.num, (int)thing->mappos.x.stl.num,(int)thing->mappos.y.stl.num); cctrl->moveaccel.x.val = distance_with_angle_to_coord_x(cctrl->move_speed, thing->move_angle_xy); cctrl->moveaccel.y.val = distance_with_angle_to_coord_y(cctrl->move_speed, thing->move_angle_xy); cctrl->moveaccel.z.val = 0; } else { cctrl->moveaccel.x.val = nextpos.x.val - (MapCoordDelta)thing->mappos.x.val; cctrl->moveaccel.y.val = nextpos.y.val - (MapCoordDelta)thing->mappos.y.val; cctrl->moveaccel.z.val = 0; } } SYNCDBG(18,"Forward target set, speed %d, accel (%d,%d)",(int)cctrl->move_speed,(int)cctrl->moveaccel.x.val,(int)cctrl->moveaccel.y.val); } return 0; }