|
3 | 3 | #include <algorithm> |
4 | 4 | #include <cmath> |
5 | 5 | #include <cstdint> |
| 6 | +#include <string> |
6 | 7 |
|
7 | 8 | #include <glm/glm.hpp> |
8 | 9 | #include <glm/gtx/norm.hpp> |
@@ -93,6 +94,23 @@ void TrafficDirector::setDensity(ai::NodeType type, float density) { |
93 | 94 | } |
94 | 95 | } |
95 | 96 |
|
| 97 | +uint16_t TrafficDirector::assignDriver(std::string vehiclename) { |
| 98 | + enum ped_types { |
| 99 | + COP = 1, |
| 100 | + MEDIC = 5, |
| 101 | + FIREMAN = 6 |
| 102 | + }; |
| 103 | + if (vehiclename == "POLICAR") { |
| 104 | + return COP; |
| 105 | + } else if (vehiclename == "AMBULAN") { |
| 106 | + return MEDIC; |
| 107 | + } else if (vehiclename == "FIRETRUK") { |
| 108 | + return FIREMAN; |
| 109 | + } else { |
| 110 | + return 0; |
| 111 | + } |
| 112 | +} |
| 113 | + |
96 | 114 | std::vector<GameObject*> TrafficDirector::populateNearby( |
97 | 115 | const ViewCamera& camera, float radius, int maxSpawn) { |
98 | 116 |
|
@@ -133,6 +151,7 @@ std::vector<GameObject*> TrafficDirector::populateNearby( |
133 | 151 |
|
134 | 152 | // Hardcoded cop Pedestrian |
135 | 153 | std::vector<uint16_t> peds = {1}; |
| 154 | + uint16_t pedId; |
136 | 155 |
|
137 | 156 | // Determine which zone the viewpoint is in |
138 | 157 | auto zone = world->data->findZoneAt(camera.position); |
@@ -170,7 +189,7 @@ std::vector<GameObject*> TrafficDirector::populateNearby( |
170 | 189 | counter--; |
171 | 190 |
|
172 | 191 | // Spawn a pedestrian from the available pool |
173 | | - const auto pedId = |
| 192 | + pedId = |
174 | 193 | peds.at(world->getRandomNumber(0u, peds.size() - 1)); |
175 | 194 | auto ped = world->createPedestrian(pedId, spawn->position); |
176 | 195 | ped->applyOffset(); |
@@ -244,9 +263,15 @@ std::vector<GameObject*> TrafficDirector::populateNearby( |
244 | 263 | vehicle->setHandbraking(false); |
245 | 264 |
|
246 | 265 | // Spawn a pedestrian and put it into the vehicle |
247 | | - const auto pedId = |
248 | | - peds.at(world->getRandomNumber(0u, peds.size() - 1)); |
249 | | - CharacterObject* character = world->createPedestrian(pedId, vehicle->getPosition()); |
| 266 | + pedId = |
| 267 | + TrafficDirector::assignDriver(vehicle->getVehicle()->vehiclename_); |
| 268 | + if (pedId == 0) { |
| 269 | + // not an special car, random person in |
| 270 | + pedId = peds.at(world->getRandomNumber(0u, peds.size() - 1)); |
| 271 | + } |
| 272 | + CharacterObject* character = world->createPedestrian( |
| 273 | + pedId, |
| 274 | + vehicle->getPosition()); |
250 | 275 | character->setLifetime(GameObject::TrafficLifetime); |
251 | 276 | character->setCurrentVehicle(vehicle, 0); |
252 | 277 | character->controller->setGoal(CharacterController::TrafficDriver); |
|
0 commit comments