00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "revolt.h"
00018 #include "main.h"
00019 #include "geom.h"
00020 #include "particle.h"
00021 #include "model.h"
00022 #include "aerial.h"
00023 #include "newcoll.h"
00024 #include "body.h"
00025 #include "car.h"
00026 #include "ctrlread.h"
00027 #include "object.h"
00028 #include "player.h"
00029 #include "aizone.h"
00030 #include "ai.h"
00031 #include "ai_init.h"
00032 #include "ai_car.h"
00033
00034
00035
00036
00037
00038 CAI_SKILLS s_Skills[MAX_SKILL_TYPES] = {
00039 {
00040 15,
00041 15,
00042 15,
00043 15,
00044 },
00045 };
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 void CAI_CarHelper(PLAYER *Player);
00058 void CAI_ResetCar(PLAYER *Player);
00059 bool CAI_IsCarStuck(PLAYER *Player);
00060 bool CAI_IsCarInZone(PLAYER *Player);
00061 bool CAI_IsCarOnTrack(PLAYER *Player);
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 void CAI_InitCarAI(PLAYER *Player, long Skill)
00072 {
00073 Player->CarAI.ZoneID = 0;
00074 Player->CarAI.LastValidZone = 0;
00075 CAI_IsCarInZone(Player);
00076
00077 Player->CarAI.PriChoice = 1;
00078 Player->CarAI.RouteChoice = 0;
00079 Player->CarAI.CurNode = AIN_GetForwardNode(Player, 0, (REAL *)&Player->CarAI.NodeDist);
00080 Player->CarAI.LastNode = Player->CarAI.CurNode;
00081
00082 Player->CarAI.AIState = CAI_S_RACE;
00083 Player->CarAI.TrackMode = CAI_T_FORWARD;
00084 Player->CarAI.Skills = s_Skills[Skill];
00085
00086 Player->CarAI.ResetCnt = 0;
00087 Player->CarAI.StuckCnt = 0;
00088
00089 Player->CarAI.FinishDistNode = AiStartNode;
00090 Player->CarAI.FinishDist = 0.0f;
00091 Player->CarAI.FinishDistPanel = 0.0f;
00092 }
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 void CAI_CarHelper(PLAYER *Player)
00104 {
00105 Player->CarAI.IsInZone = CAI_IsCarInZone(Player);
00106 Player->CarAI.IsOnTrack = CAI_IsCarOnTrack(Player);
00107
00108 if ((!Player->CarAI.IsInZone) || (!Player->CarAI.IsOnTrack))
00109 {
00110 Player->CarAI.ResetCnt++;
00111 if (Player->CarAI.ResetCnt == MAX_RESET_CNT)
00112 {
00113 CAI_ResetCar(Player);
00114 }
00115 }
00116 else
00117 {
00118 Player->CarAI.ResetCnt = 0;
00119 }
00120
00121 if (CAI_IsCarStuck(Player))
00122 {
00123 Player->CarAI.StuckCnt += TimeStep;
00124 if (Player->CarAI.StuckCnt > MAX_STUCK_CNT)
00125 {
00126 CAI_ResetCar(Player);
00127 }
00128 }
00129 else
00130 {
00131 Player->CarAI.StuckCnt = ZERO;
00132 }
00133 }
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 void CAI_ResetCar(PLAYER *Player)
00144 {
00145 CAR *car;
00146
00147 car = &Player->car;
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 bool CAI_IsCarStuck(PLAYER *Player)
00160 {
00161 CAR *car;
00162
00163 car = &Player->car;
00164
00165 if (car->NWheelFloorContacts == 0) {
00166 if ((car->Body->NWorldContacts != 0) || (car->Body->NoContactTime < 0.05) || (car->NWheelColls > 0)) {
00167 return TRUE;
00168 }
00169 }
00170
00171 return(FALSE);
00172 }
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 bool CAI_IsCarInZone(PLAYER *Player)
00184 {
00185 long ii, jj, kk;
00186 long flag;
00187 float dist;
00188 AIZONE *zone;
00189 CAR *car;
00190
00191 car = &Player->car;
00192
00193 if (!AiZones) { return(FALSE); }
00194
00195 for (ii = 0; ii < AiZoneNumID; ii++)
00196 {
00197 for (jj = 0; jj < AiZoneHeaders[ii].Count; jj++)
00198 {
00199 zone = AiZoneHeaders[ii].Zones + jj;
00200 flag = 0;
00201 for (kk = 0; kk < 3; kk++)
00202 {
00203 dist = PlaneDist(&zone->Plane[kk], &car->Body->Centre.Pos);
00204 if (dist < -zone->Size[kk] || dist > zone->Size[kk])
00205 {
00206 flag = 1;
00207 break;
00208 }
00209 }
00210 if (!flag)
00211 {
00212 Player->CarAI.LastValidZone = Player->CarAI.CurZone;
00213 Player->CarAI.CurZone = ii;
00214 Player->CarAI.CurZoneBBox = jj;
00215 return(TRUE);
00216 }
00217 }
00218 }
00219 return(FALSE);
00220 }
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230 bool CAI_IsCarOnTrack(PLAYER *Player)
00231 {
00232 CAR *car;
00233
00234 car = &Player->car;
00235
00236 return(TRUE);
00237 }
00238
00239
00240
00241
00242
00243 void CAI_TriggerAiHome(PLAYER *Player, long flag, long n, VEC *vec)
00244 {
00245 CAR *car;
00246
00247 car = &Player->car;
00248 }
00249
00250