+/* get tomatoes near our goals (12,5 and 12,3) */
+uint8_t get_opp_oranges(void)
+{
+ int16_t x, y;
+ uint8_t i, j;
+ uint8_t err;
+
+ DEBUG(E_USER_STRAT, "%s()", __FUNCTION__);
+
+ /* only if oranges are present */
+ if (strat_db.opp_oranges_count == 0)
+ return END_TRAJ;
+
+ strat_db.opp_oranges_count = 0;
+ x = position_get_x_s16(&mainboard.pos);
+ y = position_get_y_s16(&mainboard.pos);
+
+ if (xycoord_to_ijcoord_not_corn(&x, &y, &i, &j) < 0)
+ return END_ERROR;
+
+ /* not on eject point */
+ if (i != 11 || j != 6)
+ return END_ERROR;
+
+ strat_want_pack = 1;
+ strat_set_speed(SPEED_DIST_FAST, SPEED_ANGLE_FAST);
+
+ /* turn in the correct direction */
+ trajectory_a_abs(&mainboard.traj, COLOR_A(-90));
+ err = wait_traj_end(TRAJ_FLAGS_NO_NEAR);
+ if (!TRAJ_SUCCESS(err))
+ goto fail;
+
+ trajectory_goto_forward_xy_abs(&mainboard.traj, 2625, COLOR_Y(597));
+ err = wait_traj_end(TRAJ_FLAGS_STD);
+ if (!TRAJ_SUCCESS(err))
+ goto fail;
+
+ strat_set_speed(SPEED_DIST_SLOW, SPEED_ANGLE_SLOW);
+ trajectory_goto_forward_xy_abs(&mainboard.traj, 2750, COLOR_Y(250));
+ err = wait_traj_end(TRAJ_FLAGS_NO_NEAR);
+ if (!TRAJ_SUCCESS(err))
+ goto fail;
+
+ err = run_to_the_hills(get_opponent_color());
+
+ fail:
+ strat_want_pack = 0;
+ return err;
+}
+
+/* get tomatoes near our goals (12,5 and 12,3) */
+uint8_t get_orphan_tomatoes(void)
+{
+#define CLITOID_TOMATO_RADIUS 100.
+#define TOMATO_BACK_X 2760
+#define TOMATO_BACK_LEN 200
+
+ int16_t x, y, a;
+ uint8_t i, j;
+ uint8_t err;
+ int8_t ret;
+
+ DEBUG(E_USER_STRAT, "%s()", __FUNCTION__);
+
+ /* only go if both tomatoes are present */
+ if (!strat_db.wp_table[12][5].present ||
+ !strat_db.wp_table[12][3].present) {
+ return END_TRAJ;
+ }
+
+ x = position_get_x_s16(&mainboard.pos);
+ y = position_get_y_s16(&mainboard.pos);
+
+ if (xycoord_to_ijcoord_not_corn(&x, &y, &i, &j) < 0)
+ return END_ERROR;
+
+ /* not on eject point */
+ if (i != 11 || j != 6)
+ return END_ERROR;
+
+ strat_want_pack = 1;
+ strat_set_speed(SPEED_CLITOID_FAST, SPEED_ANGLE_SLOW);
+
+ /* turn in the correct direction */
+ trajectory_a_abs(&mainboard.traj, COLOR_A(-90));
+ err = wait_traj_end(TRAJ_FLAGS_NO_NEAR);
+
+ /* clitoid to turn and take the first ball */
+ ret = trajectory_clitoid(&mainboard.traj, 2625, COLOR_Y(1847),
+ COLOR_A(-90), 150., COLOR_A(90), 0,
+ CLITOID_TOMATO_RADIUS, 3*125);
+ if (ret < 0) {
+ err = END_ERROR;
+ goto fail;
+ }
+
+ err = wait_traj_end(TRAJ_FLAGS_NO_NEAR);
+ if (!TRAJ_SUCCESS(err))
+ goto fail;
+
+ strat_set_speed(SPEED_CLITOID_SLOW, SPEED_ANGLE_SLOW);
+ err = strat_calib(300, END_TRAJ|END_BLOCKING);
+ a = position_get_a_deg_s16(&mainboard.pos);
+ if (ABS(a) < 10)
+ strat_reset_pos(AREA_X - ROBOT_HALF_LENGTH_FRONT,
+ DO_NOT_SET_POS,
+ COLOR_A(0));
+
+ strat_set_speed(SPEED_CLITOID_FAST, SPEED_ANGLE_FAST);
+ trajectory_d_rel(&mainboard.traj, -250);
+ err = WAIT_COND_OR_TRAJ_END(!x_is_more_than(TOMATO_BACK_X),
+ TRAJ_FLAGS_NO_NEAR);
+
+ if (err != 0 && !TRAJ_SUCCESS(err))
+ goto fail;
+
+ trajectory_d_a_rel(&mainboard.traj, -TOMATO_BACK_LEN, COLOR_A(-90));
+ err = wait_traj_end(TRAJ_FLAGS_NO_NEAR);
+
+ /* next ball */
+
+ /* clitoid to turn and take the first ball */
+ strat_set_speed(SPEED_CLITOID_FAST, SPEED_ANGLE_SLOW);
+ ret = trajectory_clitoid(&mainboard.traj, 2625, COLOR_Y(1847),
+ COLOR_A(-90), 150., COLOR_A(90), 0,
+ CLITOID_TOMATO_RADIUS, 7*125);
+ if (ret < 0) {
+ err = END_ERROR;
+ goto fail;
+ }
+ err = wait_traj_end(TRAJ_FLAGS_NO_NEAR);
+ if (!TRAJ_SUCCESS(err))
+ goto fail;
+
+ strat_hardstop();
+ strat_set_speed(SPEED_CLITOID_FAST, SPEED_ANGLE_FAST);
+ trajectory_d_rel(&mainboard.traj, -250);
+ err = WAIT_COND_OR_TRAJ_END(!x_is_more_than(TOMATO_BACK_X),
+ TRAJ_FLAGS_NO_NEAR);
+ trajectory_d_a_rel(&mainboard.traj, -TOMATO_BACK_LEN, COLOR_A(-90));
+ err = wait_traj_end(TRAJ_FLAGS_NO_NEAR);
+
+fail:
+ strat_want_pack = 0;
+ return err;
+}
+
+
+#define HILL_LEN 1000
+
+#define HILL_ANGLE 0
+#define HILL_POSY_YELLOW 310
+#define HILL_POSY_BLUE 190
+
+#define HILL_POSX_BALLS_DOWN1 830
+#define HILL_POSX_BALLS_DOWN2 920
+#define HILL_POSX_BALLS_DOWN3 730
+#define HILL_START_POSX 580
+
+uint8_t prepare_hill(uint8_t orange_color, int16_t posx)
+{
+ int16_t startx, starty;
+ uint8_t our_color = get_color();
+ uint8_t err;
+
+ if (orange_color == I2C_COLOR_YELLOW)
+ starty = HILL_POSY_YELLOW;
+ else
+ starty = HILL_POSY_BLUE;
+ if (orange_color == our_color)
+ startx = posx;
+ else
+ startx = AREA_X - posx;
+ trajectory_goto_forward_xy_abs(&mainboard.traj, startx, COLOR_Y(starty));
+ err = wait_traj_end(TRAJ_FLAGS_SMALL_DIST);
+ if (!TRAJ_SUCCESS(err))
+ return err;
+
+ /* turn to the hills */
+ if (orange_color == our_color)
+ trajectory_a_abs(&mainboard.traj, COLOR_A(HILL_ANGLE));
+ else
+ trajectory_a_abs(&mainboard.traj, COLOR_A(-180+HILL_ANGLE));
+ err = wait_traj_end(TRAJ_FLAGS_SMALL_DIST);
+ if (!TRAJ_SUCCESS(err))
+ return err;
+
+ return END_TRAJ;
+}
+
+/* get oranges, must be called near game area */
+uint8_t run_to_the_hills(uint8_t orange_color)