MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / think

Method think

plugins/serverSideBotSample/serverSideBotSample.cpp:154–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152}
153
154bool SimpleBotHandler::think(void) {
155 // see if we have a target, if so drive to it.
156 if (waypoints.size()) {
157 if (waypoints.begin()->process()) {
158 waypoints.erase(waypoints.begin());
159 }
160 }
161
162 if (!waypoints.size() && bz_anyPlayers()) {
163 // find a random player that is spawned.
164 bz_APIIntList* playerList = bz_getPlayerIndexList();
165 if (playerList) {
166 if (playerList->size()) { // if it's just one, it's just me
167 int dude = rand()&playerList->size();
168 dude = playerList->get(dude);
169
170 if (dude != getPlayerID()) { // chasing myself is stupid
171 bz_BasePlayerRecord* player = bz_getPlayerByIndex(dude);
172 if (player && player->spawned) { // only chase the live ones
173 std::string message;
174 message = bz_format("I see you %s!", player->callsign.c_str());
175 bz_sendTextMessage(playerID, BZ_ALLUSERS, message.c_str());
176
177 // add the point as a waypoint
178 waypoints.push_back(Waypoint(*this, player->currentState.pos));
179 }
180
181 bz_freePlayerRecord(player);
182 }
183 }
184
185 bz_deleteIntList(playerList);
186 }
187 }
188 return false;
189}
190
191void SimpleBotHandler::playerSpawned(int player, float pos[3], float rot) {
192 bz_ServerSidePlayerHandler::playerSpawned(player, pos, rot);

Callers

nothing calls this directly

Calls 14

bz_anyPlayersFunction · 0.85
bz_getPlayerIndexListFunction · 0.85
getPlayerIDFunction · 0.85
bz_formatFunction · 0.85
bz_sendTextMessageFunction · 0.85
WaypointClass · 0.85
bz_freePlayerRecordFunction · 0.85
bz_deleteIntListFunction · 0.85
c_strMethod · 0.80
sizeMethod · 0.45
processMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected