/* returns whether we are in the right place or not */ Bool go_to_static_ball(float kick_ang, float dash_pow) { Line l; LogAction6(50, "go_to_static_ball: ball at (%.1f, %.1f) for kick angle %.2f, dash_pow %.2f", Mem->BallX(), Mem->BallY(), kick_ang, dash_pow); if (!Mem->BallPositionValid()) my_error("go_to_static_ball: lost ball"); /* we can be pretty tolerant of angle errors, but distance errors start to matter real quickly */ Vector targ_pt = get_static_ball_pos(Mem->BallAbsolutePosition(), kick_ang); /* we want to try and face the ball at all times */ turn_neck(Mem->LimitTurnNeckAngle(Mem->BallAngleFromNeck())); if (Mem->MySpeed() == 0 && Mem->DistanceTo(targ_pt) <= Mem->CP_static_kick_dist_err) { LogAction3(60, "go_to_static_ball: I am done %.2f", Mem->DistanceTo(targ_pt)); return TRUE; } /* if we are real far from the ball, just use the regular go_to_point */ if (Mem->BallDistance() > 2 * Mem->My_kickable_area()) { LogAction2(60, "go_to_static_ball: far away, using go_to_point"); if (go_to_point(targ_pt, 0 /* no buffer */, dash_pow) != AQ_ActionQueued) my_error("go_to_static_ball: far away, why didn't go_to_point do anything?"); return FALSE; } /* make sure that we go around the ball */ l.LineFromTwoPoints(Mem->MyPos(), targ_pt); Vector proj_ball_pt = l.ProjectPoint(Mem->BallAbsolutePosition()); if (proj_ball_pt.dist(Mem->BallAbsolutePosition()) <= Mem->My_size() + Mem->SP_ball_size + Mem->CP_collision_buffer && l.InBetween(proj_ball_pt, Mem->MyPos(), targ_pt)) { /* we'll do a 90 degree dodge -we always go right */ Vector dodge_pt = Mem->MyPos() + Polar2Vector(Mem->My_size(), Mem->BallAngleFromBody() + Mem->MyBodyAng() + 90); LogAction2(60, "go_to_static_ball: dodging the ball"); if (go_to_point(dodge_pt, 0 /* no buffer */, dash_pow) != AQ_ActionQueued) my_error("go_to_static_ball: dodging, why didn't go_to_point do anything?"); return FALSE; } /* now we need to get to the target_point */ /* first see if we need to turn */ l.LineFromRay(Mem->MyPos(), Mem->MyBodyAng()); float ang = Mem->AngleToFromBody(targ_pt); if (fabs(ang) > 90 || (l.dist(targ_pt) > Mem->CP_static_kick_dist_err && ang > Mem->CP_static_kick_ang_err)) { LogAction2(60, "go_to_static_ball: turning to target_point"); turn(Mem->AngleToFromBody(targ_pt)); return FALSE; } /* now calculate the speed we should be going to land right on the point */ float targ_speed = SolveForFirstTermInfGeomSeries(Mem->My_decay(), Mem->DistanceTo(targ_pt)); float dash_pow_to_use = MinMax(-dash_pow / 2, (targ_speed - Mem->MySpeed()) / Mem->My_dash_power_rate(), dash_pow); LogAction5(60, "go_to_static_ball: targ_speed: %.2f\tMySpeed: %.2f\tdash_pow: %.2f", targ_speed, Mem->MySpeed(), dash_pow_to_use); if (fabs(dash_pow_to_use) > 1) { LogAction3(70, "go_to_static_ball: dash power is too small %.2f", dash_pow_to_use); dash(Mem->CorrectDashPowerForStamina(dash_pow_to_use)); return FALSE; } return TRUE; }
int umain (void) { // int i_init = current_territory(); // printf("i_init %i\n", i_init); // for(int i = i_init; i <= i_init + 1; i++) { // printf("target i %i\n", i % 6); // go_to_territory(i % 6, false); // } // printf("[1] starting territory is %i\n", current_territory()); // go_to_territory(current_territory() + 5); // pause(300); // go_to_territory(current_territory() + 1); // pause(300); // go_to_point(&pre_gears[current_territory()], false); // capture_gears(); // go_to_point(&pre_gears[current_territory()], false); // capture_gears(); // pause(500); // go_to_point(&territories[current_territory()], false); // go_to_territory(current_territory(), false); // go_to_point(&pre_mines[current_territory()], false); // mine_resources(); // go_to_territory(current_territory(), false); // go_to_point(&pre_gears[current_territory()], false); // capture_gears(); /*for(int i = 0; i < 4; i++) { go_to_point(&pre_gears[current_territory()], false); capture_gears(); }*/ int i_init = current_territory(); printf("i_init %i\n", i_init); for(int i = i_init; i <= i_init + 7; i++) { int active_i = i % 6; printf("active_i %i\n", active_i); go_to_point(&territories[active_i], false); } for (int i = 0; i <3 ; i++) { go_to_point(&pre_gears[current_territory()], false); capture_gears(); } set_wheel_pows(1, -1); pause(6000); set_wheel_pows(0,0); while (true) { rotate_by_gyro((get_time() % 360) - 180); pause((get_time() % 20000) + 500); } set_wheel_pows(0,0); printf("umain done\n"); return 0; }