📄 field.c
字号:
} for_each( M_referees.begin(), M_referees.end(), &Referee::doAnalyse ); } else if (mode != PM_BeforeKickOff && mode != PM_TimeOver) { motable._inc ( mode ) ; if( mode == PM_KickOff_Right || mode == PM_KickIn_Right || mode == PM_FreeKick_Right ) //|| mode == PM_CornerKick_Right || // mode == PM_GoalKick_Right ) { clearPlayersFromBall( LEFT );// if (drop_ball_time > -1)// drop_ball_time--;// if (drop_ball_time == 0)// drop_ball(); } if( mode == PM_KickOff_Left || mode == PM_KickIn_Left || mode == PM_FreeKick_Left ) //|| // mode == PM_CornerKick_Left || mode == PM_GoalKick_Left) { clearPlayersFromBall( RIGHT );// if (drop_ball_time > -1)// drop_ball_time--;// if (drop_ball_time == 0)// drop_ball(); } if (ServerParam::instance().useoffside) offside_check() ; time++ ; referee_step() ; for_each( M_referees.begin(), M_referees.end(), &Referee::doAnalyse ); /* pfr - moved next line before if */ prev_ball_pos = ball->pos ; if( M_caught_ball && mode != PM_BeforeKickOff ) { move_caught_ball() ; } /* pfr 7/26/2000 */ //printf("time: %d\t2ht: %d\n", time, 2*ServerParam::instance().half_time); if (time > 0 && ServerParam::instance().nr_normal_halfs > 0 && time % (ServerParam::instance().nr_normal_halfs*ServerParam::instance().halfTime() ) == 0 ){ //printf("Giving coachs more messages\n"); //every game time cycles, give the online coach more messages if (olcoach[0]->freeform_messages_allowed > 0) olcoach[0]->freeform_messages_allowed += ServerParam::instance().say_cnt_max; if (olcoach[1]->freeform_messages_allowed > 0) olcoach[1]->freeform_messages_allowed += ServerParam::instance().say_cnt_max; } dinfo.body.show.time = htons(time) ; dinfo2.body.show.time = htons(time) ; } for( i = 0 ; i < MAX_PLAYER * 2; i++ ) { if( player[i]->alive == DISABLE ) continue ; if( player[i]->stamina <= ( ServerParam::instance().recover_dthr * ServerParam::instance().stamina_max ) ) { if( player[i]->recovery > ServerParam::instance().recover_min ) player[i]->recovery -= ServerParam::instance().recover_dec; if( player[i]->recovery < ServerParam::instance().recover_min ) player[i]->recovery = ServerParam::instance().recover_min; } if( player[i]->stamina <= ( ServerParam::instance().effort_dthr * ServerParam::instance().stamina_max ) ) { if( player[i]->effort > player[i]->player_type->effortMin () ) player[i]->effort -= ServerParam::instance().effort_dec ; if( player[i]->effort < player[i]->player_type->effortMin () ) player[i]->effort = player[i]->player_type->effortMin () ; } if( player[i]->stamina >= ( ServerParam::instance().effort_ithr * ServerParam::instance().stamina_max ) ) { if( player[i]->effort < player[i]->player_type->effortMax () ) { player[i]->effort += ServerParam::instance().effort_inc ; if( player[i]->effort > player[i]->player_type->effortMax () ) player[i]->effort = player[i]->player_type->effortMax () ; } } player[i]->stamina += ( player[i]->recovery * player[i]->player_type->staminaIncMax () ); if( player[i]->stamina > ServerParam::instance().stamina_max ) player[i]->stamina = ServerParam::instance().stamina_max ; player[i]->hear_capacity_from_teammate += ServerParam::instance().hearInc() ; if(player[i]->hear_capacity_from_teammate > (int)ServerParam::instance().hearMax() ) player[i]->hear_capacity_from_teammate = ServerParam::instance().hearMax(); player[i]->hear_capacity_from_opponent += ServerParam::instance().hearInc(); if (player[i]->hear_capacity_from_opponent > (int)ServerParam::instance().hearMax() ) player[i]->hear_capacity_from_opponent = ServerParam::instance().hearMax(); if (player[i]->goalie_catch_ban) player[i]->goalie_catch_ban-- ; } /* send to displays */ dinfo.body.show.pos[0].x = htons((short)rint((ball->pos.x * SHOWINFO_SCALE))) ; dinfo.body.show.pos[0].y = htons((short)rint((ball->pos.y * SHOWINFO_SCALE))) ; dinfo2.body.show.ball.x = htonl((long)rint((ball->pos.x * SHOWINFO_SCALE2))) ; dinfo2.body.show.ball.y = htonl((long)rint((ball->pos.y * SHOWINFO_SCALE2))) ; dinfo2.body.show.ball.deltax = htonl((long)rint((ball->vel.x * SHOWINFO_SCALE2))) ; dinfo2.body.show.ball.deltay = htonl((long)rint((ball->vel.y * SHOWINFO_SCALE2))) ; for (i = 0 ; i < MAX_PLAYER * 2 ; i++) { dinfo.body.show.pos[i+1].enable = htons(player[i]->alive) ; //player[i]->alive &= (STAND | GOALIE | DISCARD) ; dinfo.body.show.pos[i+1].x = htons((short)rint((player[i]->pos.x * SHOWINFO_SCALE))) ; dinfo.body.show.pos[i+1].y = htons((short)rint((player[i]->pos.y * SHOWINFO_SCALE))) ; dinfo.body.show.pos[i+1].angle = htons((short)Rad2IDegRound(player[i]->angle)) ; dinfo.body.show.pos[i+1].side = htons(player[i]->team->side) ; dinfo.body.show.pos[i+1].unum = htons(player[i]->unum) ; dinfo2.body.show.pos[i].mode = htons(player[i]->alive) ; dinfo2.body.show.pos[i].type = htons(player[i]->player_type_id); //player[i]->alive &= (STAND | GOALIE | DISCARD) ; dinfo2.body.show.pos[i].x = htonl((long)rint((player[i]->pos.x * SHOWINFO_SCALE2))) ; dinfo2.body.show.pos[i].y = htonl((long)rint((player[i]->pos.y * SHOWINFO_SCALE2))) ; dinfo2.body.show.pos[i].deltax = htonl((long)rint((player[i]->vel.x * SHOWINFO_SCALE2))) ; dinfo2.body.show.pos[i].deltay = htonl((long)rint((player[i]->vel.y * SHOWINFO_SCALE2))) ; dinfo2.body.show.pos[i].body_angle = htonl((long)rint((player[i]->angle * SHOWINFO_SCALE2))) ; dinfo2.body.show.pos[i].head_angle = htonl((long)rint((player[i]->angle_neck_committed * SHOWINFO_SCALE2))) ; dinfo2.body.show.pos[i].view_width = htonl((long)rint((player[i]->vis_angle * SHOWINFO_SCALE2)) ); dinfo2.body.show.pos[i].view_quality = htons((short)rint((player[i]->highquality))) ; dinfo2.body.show.pos[i].stamina = htonl((long)rint((player[i]->stamina * SHOWINFO_SCALE2))) ; dinfo2.body.show.pos[i].effort = htonl((long)rint((player[i]->effort * SHOWINFO_SCALE2))) ; dinfo2.body.show.pos[i].recovery = htonl((long)rint((player[i]->recovery * SHOWINFO_SCALE2))) ; dinfo2.body.show.pos[i].kick_count = htons(player[i]->count_kick) ; dinfo2.body.show.pos[i].dash_count = htons(player[i]->count_dash) ; dinfo2.body.show.pos[i].turn_count = htons(player[i]->count_turn) ; dinfo2.body.show.pos[i].say_count = htons(player[i]->count_say) ; dinfo2.body.show.pos[i].tneck_count = htons(player[i]->count_turn_neck) ; dinfo2.body.show.pos[i].catch_count = htons(player[i]->count_catch) ; dinfo2.body.show.pos[i].move_count = htons(player[i]->count_move) ; dinfo2.body.show.pos[i].chg_view_count = htons(player[i]->count_change_view) ; if( player[i]->getTackleCycles() > 0 ) player[i]->alive &= (STAND | GOALIE | DISCARD | TACKLE | TACKLE_FAULT ) ; else player[i]->alive &= (STAND | GOALIE | DISCARD) ; } if (team_l->name != NULLCHAR) { strncpy(dinfo.body.show.team[0].name, team_l->name, 16) ; dinfo.body.show.team[0].score = htons(team_l->point) ; strncpy(dinfo2.body.show.team[0].name, team_l->name, 16) ; dinfo2.body.show.team[0].score = htons(team_l->point) ; } else { strncpy(dinfo2.body.show.team[0].name, "", 16) ; dinfo2.body.show.team[0].score = htons(0) ; } if (team_r->name != NULLCHAR) { strncpy(dinfo.body.show.team[1].name, team_r->name, 16) ; dinfo.body.show.team[1].score = htons(team_r->point) ; strncpy(dinfo2.body.show.team[1].name, team_r->name, 16) ; dinfo2.body.show.team[1].score = htons(team_r->point) ; } else { strncpy(dinfo2.body.show.team[1].name, "", 16) ; dinfo2.body.show.team[1].score = htons(0) ; } for ( MonitorCont::iterator i = M_monitors.begin (); i != M_monitors.end (); ++i ) { if ( (*i)->getVersion () == 1.0 ) (*i)->RemoteClient::send ( (char *)&dinfo, sizeof ( dispinfo_t ) ); else (*i)->RemoteClient::send ( (char *)&dinfo2, sizeof ( dispinfo_t2 ) ); } /* TH - 2-NOV-2000 */ static bool wrote_final_cycle = false; if ( game_log_open () ) { if (mode != PM_BeforeKickOff && mode != PM_TimeOver) { if (ServerParam::instance().gameLogVersion () == REC_OLD_VERSION || ServerParam::instance().gameLogVersion () == REC_VERSION_2) WriteLog(&dinfo) ; else WriteLog(&dinfo2) ; } else if (mode == PM_TimeOver && !wrote_final_cycle) { if (ServerParam::instance().gameLogVersion () == REC_OLD_VERSION || ServerParam::instance().gameLogVersion () == REC_VERSION_2 ) WriteLog(&dinfo) ; else WriteLog(&dinfo2) ; wrote_final_cycle = true; } }}/* *=================================================================== *Part: Field *=================================================================== */void Field::assign(Stadium *){ goal_l.name = GOAL_L_NAME ; goal_r.name = GOAL_R_NAME ; line_l.name = LINE_L_NAME ; line_r.name = LINE_R_NAME ; line_t.name = LINE_T_NAME ; line_b.name = LINE_B_NAME ; goal_l.short_name = GOAL_L_NAME_SHORT ; goal_r.short_name = GOAL_R_NAME_SHORT ; line_l.short_name = LINE_L_NAME_SHORT ; line_r.short_name = LINE_R_NAME_SHORT ; line_t.short_name = LINE_T_NAME_SHORT ; line_b.short_name = LINE_B_NAME_SHORT ; line_l.setSubName ( "l" ) ; line_r.setSubName ( "r" ) ; line_t.setSubName ( "t" ) ; line_b.setSubName ( "b" ) ; goal_l.Set(PVector(-PITCH_LENGTH/2.0,0.0),ServerParam::instance().gwidth) ; goal_r.Set(PVector(PITCH_LENGTH/2.0,0.0),ServerParam::instance().gwidth) ; line_l.Set(PVector(-PITCH_LENGTH/2.0,0.0),1.0) ; line_r.Set(PVector(PITCH_LENGTH/2.0,0.0),1.0) ; line_t.Set(PVector(-PITCH_WIDTH/2.0,0.0),1.0) ; line_b.Set(PVector(PITCH_WIDTH/2.0,0.0),1.0) ;}/* *=================================================================== *Part: Referee *=================================================================== */void Stadium::referee_step(){ /* if a value of half_time is negative, then ignore time. */ if(ServerParam::instance().halfTime() > 0) { /* check for penalty shoot-outs, half_time and extra_time. */ if( time >= ServerParam::instance().halfTime() * ( ServerParam::instance().nr_normal_halfs + ServerParam::instance().nr_extra_halfs ) ) { if( ServerParam::instance().penalty_shoot_outs == true && team_l->point == team_r->point ) return ; // handled by PenaltyRef else { say("time_up") ; change_play_mode(PM_TimeOver); return ; } } else if( time >= ServerParam::instance().halfTime() * ServerParam::instance().nr_normal_halfs ) { if (!team_l || !team_r) { say("time_up_without_a_team"); change_play_mode(PM_TimeOver); } else if (team_l->point != team_r->point ) { say("time_up") ; change_play_mode(PM_TimeOver); return ; } else if (time >= ServerParam::instance().halfTime() * ( startp + 1 ) ) { startp++; M_caught_ball = NULL; say("time_extended") ; if ( startp % 2 == 0 ) set_ball(PVector(0.0,0.0),LEFT) ; else set_ball(PVector(0.0,0.0),RIGHT) ; set_players() ; change_play_mode(PM_BeforeKickOff) ; time = ServerParam::instance().halfTime() * startp ; weather.wind_vector.x *= -1 ; weather.wind_vector.y *= -1 ; //startp = FALSE ; return ; } } // if not in overtime, check whether halfTime() cycles have been passed else if( time >= ServerParam::instance().halfTime() * ( startp + 1 ) ) { M_caught_ball = NULL; say("half_time") ; set_ball(PVector(0.0,0.0),RIGHT) ; set_players() ; change_play_mode(PM_BeforeKickOff) ; startp++; time = ServerParam::instance().halfTime() * startp; weather.wind_vector.x *= -1 ; weather.wind_vector.y *= -1 ; return ; } } if(!ServerParam::instance().CoachMode) { check_mode() ;// check_goal() ; check_ball_in_pitch() ; check_player_in_field() ; return ; } if(!coach->assignedp) { check_mode() ;// check_goal() ; check_ball_in_pitch() ; } else if(check_ball_pos() != BPI_InField) ball->vel = PVector(0.0,0.0) ; check_player_in_field() ;}void Stadium::check_mode(){ if (mode == PM_GoalKick_Right || mode == PM_GoalKick_Left) { check_field_before_goalkick() ; check_player_in_field() ; } else if (mode != PM_PlayOn) if(ball->vel.x != 0.0 || ball->vel.y != 0.0){ check_player_in_field() ; change_play_mode(PM_PlayOn) ; }}void Stadium::set_ball(PVector p,Side s, PVector vel){ ball->acc = PVector(0.0,0.0) ; ball->vel = vel ; ball->pos = p ; kick_off_side = s ;}void Stadium::set_ball(PVector p,Side s,Angle ang, PVector vel){ ball->angle = ang ; set_ball(p, s, vel) ;}void Stadium::check_players_move(){ static RArea fld_l(PVector(-PITCH_LENGTH/4,0.0), PVector(PITCH_LENGTH/2, PITCH_WIDTH)) ; static RArea fld_r(PVector(PITCH_LENGTH/4,0.0), PVector(PITCH_LENGTH/2, PITCH_WIDTH)) ; static CArea c(PVector(0.0,0.0),KICK_OFF_CLEAR_DISTANCE) ; int i ; for (i = 0 ; i < MAX_PLAYER * 2 ; i++) { if (player[i]->alive == DISABLE) continue ; switch (player[i]->team->side) { case LEFT: if(player[i]->pos.x > 0) player[i]->pos = fld_l.randomize() ; break ; case RIGHT: if(player[i]->pos.x < 0) player[i]->pos = fld_r.randomize() ; break ; } if(player[i]->team->side != kick_off_side) if(c.inArea(player[i]->pos)) player[i]->pos = c.nearestEdge(player[i]->pos) ; }}void Stadium::check_player_after_offside(){ CArea c(offside_pos, ServerParam::instance().offside_area) ; int offsideside ; PVector ce, si ; if (mode == PM_OffSide_Right) { ce += PVector(PITCH_LENGTH/4 + offside_pos.x/2,0.0) ; si += PVector(PITCH_LENGTH/2 - offside_pos.x, PITCH_WIDTH) ; offsideside = RIGHT ; } else { ce += PVector(-PITCH_LENGTH/4 + offside_pos.x/2,0.0) ; si += PVector(PITCH_LENGTH/2 + offside_pos.x, PITCH_WIDTH) ; offsideside = LEFT ; } RArea fld(ce, si) ; int i ; for (i = 0 ; i < MAX_PLAYER * 2 ; i++) { if (player[i]->alive == DISABLE) continue ; if (player[i]->team->side == offsideside) { if (c.inArea(player[i]->pos)) player[i]->pos = c.nearestEdge(player[i]->pos) ; if (!fld.inArea(player[i]->pos)) if(mode == PM_OffSide_Right) player[i]->pos = fld.nearestVEdge(player[i]->pos) + PVector(ServerParam::instance().offside_kick_margin,0) ; else player[i]->pos = fld.nearestVEdge(player[i]->pos) - PVector(ServerParam::instance().offside_kick_margin,0) ; } }}void Stadium::check_goalie_while_catch(Player *){ // not longer used. Instead the ref awards an infringement if the goalie moves the ball outside of the penalty area// RArea pta(PVector((-PITCH_LENGTH/2+PENALTY_AREA_LENGTH/2.0) * goalie->team->side, 0.0),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -