Skip to content

Commit ca6e808

Browse files
committed
TrafficDirector: put correct drivers into special cars
Police cars are driven by cops. Ambulances by medics. Firetrucks by firefigters. Signed-off-by: David Heidelberg <[email protected]>
1 parent f10a5a8 commit ca6e808

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

rwengine/src/ai/TrafficDirector.cpp

+29-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <algorithm>
44
#include <cmath>
55
#include <cstdint>
6+
#include <string>
67

78
#include <glm/glm.hpp>
89
#include <glm/gtx/norm.hpp>
@@ -93,6 +94,23 @@ void TrafficDirector::setDensity(ai::NodeType type, float density) {
9394
}
9495
}
9596

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+
96114
std::vector<GameObject*> TrafficDirector::populateNearby(
97115
const ViewCamera& camera, float radius, int maxSpawn) {
98116

@@ -133,6 +151,7 @@ std::vector<GameObject*> TrafficDirector::populateNearby(
133151

134152
// Hardcoded cop Pedestrian
135153
std::vector<uint16_t> peds = {1};
154+
uint16_t pedId;
136155

137156
// Determine which zone the viewpoint is in
138157
auto zone = world->data->findZoneAt(camera.position);
@@ -170,7 +189,7 @@ std::vector<GameObject*> TrafficDirector::populateNearby(
170189
counter--;
171190

172191
// Spawn a pedestrian from the available pool
173-
const auto pedId =
192+
pedId =
174193
peds.at(world->getRandomNumber(0u, peds.size() - 1));
175194
auto ped = world->createPedestrian(pedId, spawn->position);
176195
ped->applyOffset();
@@ -244,9 +263,15 @@ std::vector<GameObject*> TrafficDirector::populateNearby(
244263
vehicle->setHandbraking(false);
245264

246265
// 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());
250275
character->setLifetime(GameObject::TrafficLifetime);
251276
character->setCurrentVehicle(vehicle, 0);
252277
character->controller->setGoal(CharacterController::TrafficDriver);

rwengine/src/ai/TrafficDirector.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include <vector>
55
#include <cstddef>
6+
#include <cstdint>
7+
#include <string>
68

79
class GameWorld;
810
class GameObject;
@@ -24,6 +26,11 @@ class TrafficDirector {
2426

2527
void setDensity(NodeType type, float density);
2628

29+
/**
30+
* Put the right pedestrian inside the car
31+
*/
32+
uint16_t assignDriver(std::string vehiclename);
33+
2734
/**
2835
* Creates new traffic at available locations.
2936
* @param camera The camera to spawn around

0 commit comments

Comments
 (0)