47 #include <unordered_map> 57 #define CITYLIFE_NAME "citylife" 60 #define FIRST_MOVE_KEY "citylife_first_move" 84 std::vector<spawn_point>
points;
91 static std::unordered_map<std::string, mapzone *>
maps;
104 return find ==
maps.end() ? nullptr : find->second;
212 for (
auto map =
maps.cbegin(); map !=
maps.cend() && count < 50; map++) {
214 zones[count] = map->second;
221 int selected =
RANDOM() % count;
231 va_start(args, type);
232 code = va_arg(args,
int);
251 object *ground, *who, *event;
254 va_start(args, type);
256 who = va_arg(args,
object *);
257 va_arg(args,
object *);
258 va_arg(args,
object *);
259 va_arg(args,
char *);
261 event = va_arg(args,
object *);
269 LOG(
llevInfo,
"citylife: %s attacked, reverting to default behaviour\n", who->
name);
287 LOG(
llevInfo,
"citylife: removing event from object %s which we didn't generate\n", who->
name);
292 if (strcmp(value,
"1") == 0) {
296 for (
object *inv = who->
inv; inv; inv = inv->
below)
300 else if (
RANDOM()%100 < 30) {
301 int16_t sx = who->
x, sy = who->
y;
304 for (ground =
GET_MAP_OB(map, sx, sy); ground; ground = ground->
above) {
327 LOG(
llevError,
"zone for %s has population of 0!\n", path);
330 LOG(
llevError,
"zone for %s has no archetype!\n", path);
332 if (zone->
zones.empty()) {
335 if (zone->
points.empty()) {
336 LOG(
llevError,
"zone for %s has no spawn point!\n", path);
352 if (line[0] ==
'\0' || line[0] ==
'#') {
356 char *space = strchr(line,
' ');
364 if (strcmp(line,
"map") == 0) {
369 auto existing =
maps.find(path);
370 if (existing ==
maps.end()) {
374 zone = existing->second;
382 if (strcmp(line,
"population") == 0) {
386 if (strcmp(line,
"zone") == 0) {
392 z.
sx = atoi(split[0]);
393 z.
sy = atoi(split[1]);
394 z.
ex = atoi(split[2]);
395 z.
ey = atoi(split[3]);
396 zone->
zones.push_back(z);
400 if (strcmp(line,
"point") == 0) {
406 p.
x = atoi(split[0]);
407 p.
y = atoi(split[1]);
408 zone->
points.push_back(p);
412 if (strcmp(line,
"arch") == 0) {
441 for (
auto map :
maps) {
static void load_citylife(BufferReader *reader, const char *filename)
Read a .citylife file.
static event_registration c
static int citylife_globalEventListener(int *type,...)
#define FLAG_NO_DROP
Object can't be dropped.
void events_register_object_handler(const char *id, f_plug_event handler)
Register an object event handler.
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
#define FLAG_STAND_STILL
NPC will not (ever) move.
static std::vector< std::string > split(const std::string &field, const std::string &by)
void assets_add_collector_hook(const char *name, collectorHook hook)
void object_remove(object *op)
This function removes the object op from the linked list of objects which it is currently tied to...
static const house_zone_struct zones[]
Maps we work on.
object * below
Pointer to the object stacked below this one.
sstring slaying
Which race to do double damage to.
sstring add_string(const char *str)
Share a string.
object * above
Pointer to the object stacked above this one.
int object_teleport(object *op, mapstruct *map, int x, int y)
Move the specified object in a free spot around the map's x & y.
size_t bufferreader_current_line(BufferReader *br)
Return the index of the last line returned by bufferreader_next_line().
#define FLAG_RANDOM_MOVE
NPC will move randomly.
int16_t y
Position in the map for this object.
Point from which a NPC can come when the map is loaded.
Global type definitions and header inclusions.
#define FIRST_MOVE_KEY
Key to contain whether it's the first move of the NPC or not.
archetype * try_find_archetype(const char *name)
#define EVENT_ATTACKED
Object attacked, with weapon or spell.
#define FLAG_UNDEAD
Monster is undead.
#define MAP_IN_MEMORY
Map is fully loaded.
void object_free(object *ob, int flags)
Frees everything allocated by an object, removes it from the list of used objects, and puts it on the list of free objects.
size_t split_string(char *str, char *array[], size_t array_size, char sep)
Splits a string delimited by passed in sep value into characters into an array of strings...
object * object_find_by_type_subtype(const object *who, int type, int subtype)
Find object in inventory.
unsigned long event_registration
Registration identifier type.
The archetype structure is a set of rules on how to generate and manipulate objects which point to ar...
static void add_npc_to_random_map(void)
Find a suitable map loaded and add an NPC to it.
Zone in which to add NPCs when the map was just loaded.
object * arch_to_object(archetype *at)
Creates and returns a new object which is a copy of the given archetype.
Structure used to build up dialog information when a player says something.
char path[HUGE_BUF]
Filename of the map.
object * create_archetype(const char *name)
Finds which archetype matches the given name, and returns a new object containing a copy of the arche...
std::vector< std::string > disabled_plugins
List of disabled plugins, 'All' means all.
void object_free_drop_inventory(object *ob)
Frees everything allocated by an object, removes it from the list of used objects, and puts it on the list of free objects.
#define EVENT_CLOCK
Global time event.
ServerSettings serverSettings
static const mapzone * get_zone_for_map(mapstruct *map)
Finds if a map has a zone defined.
sstring object_get_value(const object *op, const char *const key)
Get an extra value by key.
#define P_OUT_OF_MAP
This space is outside the map.
int move_ob(object *op, int dir, object *originator)
Op is trying to move in direction dir.
static void add_npc_to_zone(const mapzone *zone, mapstruct *map)
Add an NPC somewhere in a spawn zone.
static void check_zone(const mapzone *zone, const char *path)
Check if the zone has valid parameters, LOG() when invalid ones.
struct mapstruct * map
Pointer to the map in which this object is present.
uint32_t in_memory
Combination of IN_MEMORY_xxx flags.
std::vector< spawn_zone > zones
Zones where to spawn at load time.
static void add_npc_to_point(const mapzone *zone, mapstruct *map)
Add an NPC somewhere at a spawn point.
Object structure, the core of Crossfire.
static event_registration m
sstring name
The name of the object, obviously...
sstring title
Of foo, etc.
Only for debugging purposes.
int get_map_flags(mapstruct *oldmap, mapstruct **newmap, int16_t x, int16_t y, int16_t *nx, int16_t *ny)
This rolls up wall, blocks_magic, blocks_view, etc, all into one function that just returns a P_...
#define CITYLIFE_NAME
Module name for the event system.
#define CLEAR_FLAG(xyz, p)
uint8_t type
PLAYER, BULLET, etc.
static int eventListener(int *type,...)
void events_unregister_global_handler(int eventcode, event_registration id)
Remove a global event handler.
int object_set_value(object *op, const char *key, const char *value, int add_key)
Updates the key in op to value.
object * inv
Pointer to the first object in the inventory.
#define EVENT_TIME
Triggered each time the object can react/move.
Lauwenmark: an invisible object holding a plugin event hook.
#define GET_MAP_OB(M, X, Y)
Gets the bottom object on a map.
#define EVENT_MAPLOAD
A map is loaded (pristine state)
C function wrappers to interact with assets.
void events_unregister_object_handler(const char *id)
Remove an object event handler.
event_registration events_register_global_handler(int eventcode, f_plug_event hook)
Register a global event handler.
mapstruct * has_been_loaded(const char *name)
Checks whether map has been loaded.
static void add_npcs_to_map(mapstruct *map)
Add some NPCs to the map, based on the zone definition.
std::vector< spawn_point > points
Points to spawn from when there is a player on the map.
char * bufferreader_next_line(BufferReader *br)
Return the next line in the buffer, as separated by a newline.
uint8_t subtype
Subtype of object.
object * object_insert_in_ob(object *op, object *where)
This function inserts the object op in the linked list inside the object environment.
#define FLAG_UNIQUE
Item is really unique (UNIQUE_ITEMS)
static std::unordered_map< std::string, mapzone * > maps
All defined maps, with the path as key.
int population
Maximum of NPCs to add at load time.
static object * get_npc(const mapzone *zone)
Creates a NPC for the specified zone, and do needed initialization.
std::vector< std::string > available_archetypes
What archetypes can we chose from for an NPC?
void citylife_init(Settings *, ServerSettings *serverSettings)