|
3 | 3 | #include <algorithm>
|
4 | 4 | #include <cmath>
|
5 | 5 | #include <cstdint>
|
6 |
| - |
7 | 6 | #include <glm/glm.hpp>
|
8 | 7 | #include <glm/gtx/norm.hpp>
|
9 | 8 | #include <glm/gtx/quaternion.hpp>
|
10 | 9 | #include <glm/gtx/transform.hpp>
|
| 10 | +#include <string> |
11 | 11 |
|
12 | 12 | #include "ai/AIGraph.hpp"
|
13 | 13 | #include "ai/AIGraphNode.hpp"
|
@@ -93,6 +93,19 @@ void TrafficDirector::setDensity(ai::NodeType type, float density) {
|
93 | 93 | }
|
94 | 94 | }
|
95 | 95 |
|
| 96 | +uint16_t TrafficDirector::assignDriver(const std::string &vehiclename) { |
| 97 | + enum ped_types { COP = 1, MEDIC = 5, FIREMAN = 6 }; |
| 98 | + if (vehiclename == "POLICAR") { |
| 99 | + return COP; |
| 100 | + } else if (vehiclename == "AMBULAN") { |
| 101 | + return MEDIC; |
| 102 | + } else if (vehiclename == "FIRETRUK") { |
| 103 | + return FIREMAN; |
| 104 | + } else { |
| 105 | + return 0; |
| 106 | + } |
| 107 | +} |
| 108 | + |
96 | 109 | std::vector<GameObject*> TrafficDirector::populateNearby(
|
97 | 110 | const ViewCamera& camera, float radius, int maxSpawn) {
|
98 | 111 |
|
@@ -133,6 +146,7 @@ std::vector<GameObject*> TrafficDirector::populateNearby(
|
133 | 146 |
|
134 | 147 | // Hardcoded cop Pedestrian
|
135 | 148 | std::vector<uint16_t> peds = {1};
|
| 149 | + uint16_t pedId; |
136 | 150 |
|
137 | 151 | // Determine which zone the viewpoint is in
|
138 | 152 | auto zone = world->data->findZoneAt(camera.position);
|
@@ -170,8 +184,7 @@ std::vector<GameObject*> TrafficDirector::populateNearby(
|
170 | 184 | counter--;
|
171 | 185 |
|
172 | 186 | // Spawn a pedestrian from the available pool
|
173 |
| - const auto pedId = |
174 |
| - peds.at(world->getRandomNumber(0u, peds.size() - 1)); |
| 187 | + pedId = peds.at(world->getRandomNumber(0u, peds.size() - 1)); |
175 | 188 | auto ped = world->createPedestrian(pedId, spawn->position);
|
176 | 189 | ped->applyOffset();
|
177 | 190 | ped->setLifetime(GameObject::TrafficLifetime);
|
@@ -244,9 +257,14 @@ std::vector<GameObject*> TrafficDirector::populateNearby(
|
244 | 257 | vehicle->setHandbraking(false);
|
245 | 258 |
|
246 | 259 | // 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()); |
| 260 | + pedId = TrafficDirector::assignDriver( |
| 261 | + vehicle->getVehicle()->vehiclename_); |
| 262 | + if (pedId == 0) { |
| 263 | + // not an special car, random person in |
| 264 | + pedId = peds.at(world->getRandomNumber(0u, peds.size() - 1)); |
| 265 | + } |
| 266 | + CharacterObject* character = |
| 267 | + world->createPedestrian(pedId, vehicle->getPosition()); |
250 | 268 | character->setLifetime(GameObject::TrafficLifetime);
|
251 | 269 | character->setCurrentVehicle(vehicle, 0);
|
252 | 270 | character->controller->setGoal(CharacterController::TrafficDriver);
|
|
0 commit comments