nanoMMO 0.97.8
Building an MMO: The Engineering Series
Loading...
Searching...
No Matches
npcs.cc
Go to the documentation of this file.
1#include "server/npcs.h"
2
3#include <iostream>
4
5#include "terrain/lands.h"
6
7namespace nanommo {
8
9void SpawnNpcs(World& land, int index, const NpcTable& table) {
10 for (const npcs::Spawn& spawn : table.spawns) {
11 if (LandNamed(spawn.land()) != index) {
12 continue;
13 }
14 const npcs::Kind& kind = table.kinds.at(spawn.kind());
15 // A seed of its own can put the sea or a tree where the table says.
16 if (!land.terrain().Walkable(spawn.x(), spawn.z())) {
17 std::cerr << "no " << kind.name() << " at " << spawn.x() << ", "
18 << spawn.z() << ": the ground isn't walkable there\n";
19 continue;
20 }
21 land.Spawn(Npc{.name = kind.name(),
22 .kind = kind.id(),
23 .x = spawn.x(),
24 .z = spawn.z(),
25 .yaw = spawn.yaw(),
26 .talks = kind.talks(),
27 .teaches = {kind.teaches().begin(), kind.teaches().end()}});
28 }
29}
30
31} // namespace nanommo
bool Walkable(float x, float z) const
Definition terrain.cc:123
const Terrain & terrain() const
Definition world.h:516
uint32_t Spawn(Monster monster)
Definition world.cc:685
Definition chat.cc:9
int LandNamed(std::string_view name)
Its place in the list, or the first land's for a name that isn't there.
Definition lands.cc:10
void SpawnNpcs(World &land, int index, const NpcTable &table)
Definition npcs.cc:9
The kinds of NPC, by id, and where each NPC stands.
Definition npcs.h:20
std::vector< npcs::Spawn > spawns
Definition npcs.h:22
std::map< uint32_t, npcs::Kind > kinds
Definition npcs.h:21