static int equal_action(Action ac1, Action ac2) { if (ACTION_TYPE(ac1) == ACTION_TYPE(ac2) && equal_vector(ACTION_SPEED(ac1), ACTION_SPEED(ac2)) && ACTION_DSPEED(ac1) == ACTION_DSPEED(ac2)) return 1; else return 0; }
static int i_kick_ball(struct Player *pp) { if (ACTION_TYPE(pp->action) == TY_KICK && match.ball.kicked == 1 && match.ball.last_toucher->id == pp->id) return 1; else return 0; }
static int action_interruptable(Action ac) { int ac_type = ACTION_TYPE(ac); if (ac_type == TY_POUNCE || ac_type == TY_TUMBLE || ac_type == TY_KICK || ac_type == TY_SHOVEL) return 0; else return 1; }
static int i_hold_ball(struct Player *pp) { float dis = distance(pp->pos, match.ball.pos); Speed still = {0.0, 0.0, 0.0}; if (ACTION_TYPE(pp->action) == TY_HOLD && dis <= HOLD_DISTANCE && equal_vector(match.ball.spd, still)) return 1; else return 0; }
//-------------------------------------------------------------------------------------------- int randomize_action( int action, int slot ) { /// @details BB@> this function actually determines whether the action fillows the /// pattern of ACTION_?A, ACTION_?B, ACTION_?C, ACTION_?D, with /// A and B being for the left hand, and C and D being for the right hand int diff = 0; // a valid slot? if ( slot < 0 || slot >= SLOT_COUNT ) return action; // a valid action? if ( action < 0 || action >= ACTION_COUNT ) return bfalse; diff = slot * 2; //---- non-randomizable actions if ( ACTION_MG == action ) return action; // MG = Open Chest else if ( ACTION_MH == action ) return action; // MH = Sit else if ( ACTION_MI == action ) return action; // MI = Ride else if ( ACTION_MJ == action ) return action; // MJ = Object Activated else if ( ACTION_MK == action ) return action; // MK = Snoozing else if ( ACTION_ML == action ) return action; // ML = Unlock else if ( ACTION_JA == action ) return action; // JA = Jump else if ( ACTION_RA == action ) return action; // RA = Roll else if ( ACTION_IS_TYPE( action, W ) ) return action; // WA - WD = Walk //---- do a couple of special actions that have left/right else if ( ACTION_EA == action || ACTION_EB == action ) action = ACTION_JB + slot; // EA/EB = Evade left/right else if ( ACTION_JB == action || ACTION_JC == action ) action = ACTION_JB + slot; // JB/JC = Dropped item left/right else if ( ACTION_MA == action || ACTION_MB == action ) action = ACTION_MA + slot; // MA/MB = Drop left/right item else if ( ACTION_MC == action || ACTION_MD == action ) action = ACTION_MC + slot; // MC/MD = Slam left/right else if ( ACTION_ME == action || ACTION_MF == action ) action = ACTION_ME + slot; // ME/MF = Grab item left/right else if ( ACTION_MM == action || ACTION_MN == action ) action = ACTION_MM + slot; // MM/MN = Held left/right //---- actions that can be randomized, but are not left/right sensitive // D = dance else if ( ACTION_IS_TYPE( action, D ) ) action = ACTION_TYPE( D ) + generate_randmask( 0, 3 ); //---- handle all the normal attack/defense animations // U = unarmed else if ( ACTION_IS_TYPE( action, U ) ) action = ACTION_TYPE( U ) + diff + generate_randmask( 0, 1 ); // T = thrust else if ( ACTION_IS_TYPE( action, T ) ) action = ACTION_TYPE( T ) + diff + generate_randmask( 0, 1 ); // C = chop else if ( ACTION_IS_TYPE( action, C ) ) action = ACTION_TYPE( C ) + diff + generate_randmask( 0, 1 ); // S = slice else if ( ACTION_IS_TYPE( action, S ) ) action = ACTION_TYPE( S ) + diff + generate_randmask( 0, 1 ); // B = bash else if ( ACTION_IS_TYPE( action, B ) ) action = ACTION_TYPE( B ) + diff + generate_randmask( 0, 1 ); // L = longbow else if ( ACTION_IS_TYPE( action, L ) ) action = ACTION_TYPE( L ) + diff + generate_randmask( 0, 1 ); // X = crossbow else if ( ACTION_IS_TYPE( action, X ) ) action = ACTION_TYPE( X ) + diff + generate_randmask( 0, 1 ); // F = fling else if ( ACTION_IS_TYPE( action, F ) ) action = ACTION_TYPE( F ) + diff + generate_randmask( 0, 1 ); // P = parry/block else if ( ACTION_IS_TYPE( action, P ) ) action = ACTION_TYPE( P ) + diff + generate_randmask( 0, 1 ); // Z = zap else if ( ACTION_IS_TYPE( action, Z ) ) action = ACTION_TYPE( Z ) + diff + generate_randmask( 0, 1 ); //---- these are passive actions // H = hurt else if ( ACTION_IS_TYPE( action, H ) ) action = ACTION_TYPE( H ) + generate_randmask( 0, 3 ); // K = killed else if ( ACTION_IS_TYPE( action, K ) ) action = ACTION_TYPE( K ) + generate_randmask( 0, 3 ); return action; }
static int next_frame(struct Player *pp, Action ac, int frame) { int nframe; static float inner_timers[22]; int ac_type = ACTION_TYPE(ac); float *my_timer = &inner_timers[pp->id]; switch (ac_type) { case TY_RUN: if (timer - *my_timer >= FT_RUN) { nframe = frame - 1; if (nframe < 0) nframe = FR_RUN; } else nframe = frame; break; case TY_KICK: if (timer - *my_timer >= FT_KICK) { nframe = frame - 1; if (nframe < 0) nframe = FR_KICK; } else nframe = frame; break; case TY_STAY: if (timer - *my_timer >= FT_STAY) { nframe = frame - 1; if (nframe < 0) nframe = FR_STAY; } else nframe = frame; break; case TY_HOLD: if (timer - *my_timer >= FT_HOLD) { nframe = frame - 1; if (nframe < 0) nframe = FR_HOLD; } else nframe = frame; break; case TY_POUNCE: if (timer - *my_timer >= FT_POUNCE) { nframe = frame - 1; if (nframe < 0) nframe = FR_POUNCE; } else nframe = frame; break; case TY_KEEP: if (timer - *my_timer >= FT_KEEP) { nframe = frame - 1; if (nframe < 0) nframe = FR_KEEP; } else nframe = frame; break; case TY_SHOVEL: if (timer - *my_timer >= FT_SHOVEL) { nframe = frame - 1; if (nframe < 0) nframe = FR_SHOVEL; } else nframe = frame; break; case TY_DRIBBLE: if (timer - *my_timer >= FT_DRIBBLE) { nframe = frame - 1; if (nframe < 0) nframe = FR_DRIBBLE; } else nframe = frame; break; case TY_TUMBLE: if (timer - *my_timer >= FT_TUMBLE) { nframe = frame - 1; if (nframe < 0) nframe = FR_TUMBLE; } else nframe = frame; break; } if (nframe != frame) *my_timer = timer; return nframe; }
static void complete_action(struct Player *pp) { float dis; int frame = ACTION_FRAME(pp->action); Speed bspd = ACTION_BALLSPEED(pp->action); switch (ACTION_TYPE(pp->action)) { case TY_RUN: break; case TY_KICK: if (frame == 5) { dis = distance(pp->pos, match.ball.pos); if (dis <= HOLD_DISTANCE) { change_ball_speed(bspd, (struct Vector)bspd, -0.2); match.ball.kicked = 1; match.ball.last_toucher = pp; } } break; case TY_SHOVEL: dis = distance(pp->pos, match.ball.pos); if (dis <= HOLD_DISTANCE) { change_ball_speed(bspd, (struct Vector)bspd, -0.2); match.ball.kicked = 1; match.ball.last_toucher = pp; } break; case TY_STAY: break; case TY_HOLD: dis = distance(pp->pos, match.ball.pos); if (dis <= HOLD_DISTANCE) { change_ball_speed(counter_vector(match.ball.spd), direct2vector(pp->direct, 1), -0.1); match.ball.last_toucher = pp; } break; case TY_KEEP: dis = distance(pp->pos, match.ball.pos); if (dis <= HOLD_DISTANCE) { change_ball_speed(counter_vector(match.ball.spd), direct2vector(pp->direct, 1), -0.1); match.ball.keeped = 1; match.ball.last_toucher = pp; } break; case TY_POUNCE: dis = distance(pp->pos, match.ball.pos); if (dis <= HOLD_DISTANCE) // set spd of ball before that of pp! { change_ball_speed(pp->action.spd, direct2vector(pp->direct, 1), -0.1); match.ball.keeped = 1; match.ball.last_toucher = pp; } break; case TY_TUMBLE: break; case TY_DRIBBLE: dis = distance(pp->pos, match.ball.pos); if (dis <= HOLD_DISTANCE) { change_ball_speed(bspd, (struct Vector)bspd, -0.1); match.ball.kicked = 1; match.ball.last_toucher = pp; } break; default: return; } }