#include <gAIBase.h>
Public Member Functions | |
gAITeam (nMessage &m) | |
gAITeam () | |
virtual nDescriptor & | CreatorDescriptor () const |
virtual bool | PlayerMayJoin (const ePlayerNetID *player) const |
virtual bool | BalanceThisTeam () const |
virtual bool | IsHuman () const |
Static Public Member Functions | |
static void | BalanceWithAIs (bool doBalance=balanceWithAIs) |
Definition at line 246 of file gAIBase.h.
gAITeam::gAITeam | ( | nMessage & | m | ) |
Definition at line 194 of file gAIBase.cpp.
00194 : eTeam(m) 00195 { 00196 // teams.Remove( this, listID ); 00197 }
gAITeam::gAITeam | ( | ) |
nDescriptor & gAITeam::CreatorDescriptor | ( | void | ) | const [virtual] |
Reimplemented from eTeam.
Definition at line 206 of file gAIBase.cpp.
References gAITeam_init.
00207 { 00208 return gAITeam_init; 00209 }
void gAITeam::BalanceWithAIs | ( | bool | doBalance = balanceWithAIs |
) | [static] |
Definition at line 212 of file gAIBase.cpp.
References tReferenceHolder< T >::Add(), ai, eTeam::BalanceThisTeam(), BestIQ(), gAIPlayer::character, gAIPlayer::Character(), nNetObject::ClearAllDeleted(), eTeam::EnforceConstraints(), nNetObject::GetRefcount(), gAICharacter::iq, gAIPlayer::IsHuman(), GrowingArrayBase::Len(), eTeam::minPlayers, eTeam::minTeams, gAICharacter::name, NULL, eTeam::NumAIPlayers(), eTeam::NumHumanPlayers(), eTeam::NumPlayers(), eTeam::Player(), tReferenceHolder< T >::Remove(), ePlayerNetID::RemoveFromGame(), ePlayerNetID::SetName(), ePlayerNetID::SetTeam(), st_Breakpoint(), eTeam::teams, tNEW, eTeam::UpdateProperties(), and ePlayerNetID::UpdateTeam().
Referenced by gAIPlayer::SetNumberOfAIs().
00213 { 00214 // set correct team number 00215 EnforceConstraints(); 00216 00217 int numTeams = 0, numTeamsWithPlayers = 0; 00218 00219 // determine the maximum number of human players on a team 00220 int i; 00221 int maxP = eTeam::minPlayers; 00222 for ( i = teams.Len()-1; i>=0; --i ) 00223 { 00224 eTeam *t = teams(i); 00225 00226 t->UpdateProperties(); 00227 00228 if ( t->BalanceThisTeam() ) 00229 numTeams++; 00230 00231 if ( t->NumHumanPlayers() > 0 ) 00232 numTeamsWithPlayers++; 00233 00234 int humans = t->NumHumanPlayers(); 00235 00236 if ( humans > maxP ) 00237 { 00238 maxP = humans; 00239 } 00240 } 00241 00242 // make sure all teams have equal number 00243 for ( i = teams.Len()-1; i>=0; --i ) 00244 { 00245 eTeam *t = teams(i); 00246 00247 if ( t->BalanceThisTeam() ) 00248 { 00249 int wishAIs = maxP - t->NumHumanPlayers(); 00250 00251 // don't add AI players to human team if it is not requested 00252 if ( !balanceWithAIs && t->NumHumanPlayers() > 0 ) 00253 wishAIs = 0; 00254 00255 // don't genereate AI only teams if it is not requested by the min team count 00256 if ( numTeamsWithPlayers >= minTeams && t->NumHumanPlayers() == 0 ) 00257 wishAIs = 0; 00258 00259 // add AI only teams to team count 00260 if ( wishAIs > 0 && t->NumHumanPlayers() == 0 ) 00261 numTeamsWithPlayers++; 00262 00263 int AIs = t->NumAIPlayers(); 00264 00265 while ( AIs > wishAIs ) 00266 { 00267 int j; 00268 gAIPlayer* throwOut = NULL; 00269 for ( j=t->NumPlayers()-1; j>=0; --j ) 00270 { 00271 gAIPlayer* player = dynamic_cast<gAIPlayer*>( t->Player( j ) ); 00272 if ( player && !player->IsHuman() && ( !throwOut || !throwOut->Character() || !player->Character() || throwOut->Character()->iq > player->Character()->iq ) ) 00273 { 00274 throwOut = player; 00275 } 00276 } 00277 00278 if ( throwOut ) 00279 { 00280 throwOut->RemoveFromGame(); 00281 // throwOut->ReleaseOwnership(); 00282 00283 #ifdef DEBUG 00284 if ( throwOut->GetRefcount() > 1 ) 00285 { 00286 st_Breakpoint(); 00287 } 00288 #endif 00289 00290 sg_AIReferences.Remove( throwOut ); 00291 } 00292 00293 --AIs; 00294 } 00295 00296 while ( AIs < wishAIs ) 00297 { 00298 // add the smartest AI player you can get 00299 gAICharacter* best = BestIQ( 1000 ); 00300 00301 if ( best ) 00302 { 00303 gAIPlayer *ai = tNEW( gAIPlayer ) (); 00304 ai->character = best; 00305 ai->SetName( best->name ); 00306 ai->SetTeam( t ); 00307 ai->UpdateTeam(); 00308 00309 sg_AIReferences.Add( ai ); 00310 } 00311 00312 ++AIs; 00313 } 00314 } 00315 } 00316 00317 // get rid of deleted netobjects (teams, mostly) 00318 nNetObject::ClearAllDeleted(); 00319 }
bool gAITeam::PlayerMayJoin | ( | const ePlayerNetID * | player | ) | const [virtual] |
Reimplemented from eTeam.
Definition at line 322 of file gAIBase.cpp.
References ePlayerNetID::IsHuman().
00323 { 00324 return !player->IsHuman(); 00325 }
virtual bool gAITeam::BalanceThisTeam | ( | ) | const [inline, virtual] |
virtual bool gAITeam::IsHuman | ( | ) | const [inline, virtual] |