MCPcopy Create free account
hub / github.com/assaultcube/AC / CreateBot

Method CreateBot

source/src/bot/botmanager.cpp:872–922  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

870}
871
872botent *CBotManager::CreateBot(const char *team, const char *skill, const char *name)
873{
874 if (m_bInit)
875 {
876 Init();
877 m_bInit = false;
878 }
879
880 botent *m = newbotent();
881 if (!m) return NULL;
882 loopi(NUMGUNS) m->ammo[i] = m->mag[i] = 0;
883 m->lifesequence = 0;
884 m->pBot = new CACBot;
885 m->type = ENT_BOT;
886 m->pBot->m_pMyEnt = m;
887 m->pBot->m_iLastBotUpdate = 0;
888 m->pBot->m_bSendC2SInit = false;
889
890 if (name && *name) copystring(m->name, name, 16);
891 else copystring(m->name, BotManager.GetBotName(), 16);
892
893 updateclientname((playerent *)m);
894
895 const char *tempteam = team && *team && strcmp(team, "random") ? team : BotManager.GetBotTeam();
896 m->team = team_base(teamatoi(tempteam));
897 setskin(m, m->team == TEAM_CLA ? rnd(4) : rnd(6), m->team);
898
899 if (skill && *skill && strcmp(skill, "random"))
900 {
901 if (!strcasecmp(skill, "best")) m->pBot->m_sSkillNr = 0;
902 else if (!strcasecmp(skill, "good")) m->pBot->m_sSkillNr = 1;
903 else if (!strcasecmp(skill, "medium")) m->pBot->m_sSkillNr = 2;
904 else if (!strcasecmp(skill, "worse")) m->pBot->m_sSkillNr = 3;
905 else if (!strcasecmp(skill, "bad")) m->pBot->m_sSkillNr = 4;
906 else
907 {
908 conoutf("Wrong skill specified. Should be best, good, medium, "
909 "worse or bad");
910 conoutf("Using default skill instead...");
911 m->pBot->m_sSkillNr = BotManager.m_sBotSkill;
912 }
913 }
914 else // No skill specified, use default
915 m->pBot->m_sSkillNr = BotManager.m_sBotSkill;
916 m->pBot->m_pBotSkill = &BotManager.m_BotSkills[m->pBot->m_sSkillNr];
917 // Sync waypoints
918 m->pBot->SyncWaypoints();
919 m->pBot->Spawn();
920 bots.add(m);
921 return m;
922}
923
924bool botmode()
925{

Callers 1

addbotFunction · 0.80

Calls 12

newbotentFunction · 0.85
copystringFunction · 0.85
updateclientnameFunction · 0.85
teamatoiFunction · 0.85
setskinFunction · 0.85
GetBotNameMethod · 0.80
GetBotTeamMethod · 0.80
SyncWaypointsMethod · 0.80
loopiFunction · 0.70
conoutfFunction · 0.50
SpawnMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected