| 152 | } |
| 153 | |
| 154 | bool 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 | |
| 191 | void SimpleBotHandler::playerSpawned(int player, float pos[3], float rot) { |
| 192 | bz_ServerSidePlayerHandler::playerSpawned(player, pos, rot); |
nothing calls this directly
no test coverage detected