Crossfire Server, Trunk
City life module

This module adds random NPCs to town, and makes them enter houses, spawns new ones. More...

Files

file  citylife.cpp
 

Data Structures

struct  mapzone
 
struct  spawn_point
 
struct  spawn_zone
 

Macros

#define CITYLIFE_NAME   "citylife"
 
#define FIRST_MOVE_KEY   "citylife_first_move"
 

Functions

static void add_npc_to_point (const mapzone *zone, mapstruct *map)
 
static void add_npc_to_random_map (void)
 
static void add_npc_to_zone (const mapzone *zone, mapstruct *map)
 
static void add_npcs_to_map (mapstruct *map)
 
static void check_zone (const mapzone *zone, const char *path)
 
void citylife_close ()
 
static int citylife_globalEventListener (int *type,...)
 
void citylife_init (Settings *settings)
 
static int eventListener (int *type,...)
 
static objectget_npc (const mapzone *zone)
 
static const mapzoneget_zone_for_map (mapstruct *map)
 
static void load_citylife (BufferReader *reader, const char *filename)
 
 mapzone::mapzone ()
 

Variables

std::vector< std::string > mapzone::available_archetypes
 
static event_registration c
 
int spawn_zone::ex
 
int spawn_zone::ey
 
static event_registration m
 
static std::unordered_map< std::string, mapzone * > maps
 
std::vector< spawn_pointmapzone::points
 
int mapzone::population
 
int spawn_zone::sx
 
int spawn_zone::sy
 
int spawn_point::x
 
int spawn_point::y
 
std::vector< spawn_zonemapzone::zones
 

Detailed Description

This module adds random NPCs to town, and makes them enter houses, spawns new ones.

When a map is loaded, NPCs are randomly added so they appear already. During the course of the server, some will enter houses (disappear), others will exit from houses (appear on a house).

For each map to be processed, two things are defined:

NPCs use a key/value to prevent them from immediately entering the building they exited.

Todo:
  • define spawn points/zones for other towns
  • vary NPCs based on time of day
  • define "objectives" to go to
  • make NPCs pause when player talks to them

Macro Definition Documentation

◆ CITYLIFE_NAME

#define CITYLIFE_NAME   "citylife"

Module name for the event system.

Definition at line 58 of file citylife.cpp.

◆ FIRST_MOVE_KEY

#define FIRST_MOVE_KEY   "citylife_first_move"

Key to contain whether it's the first move of the NPC or not.

Definition at line 61 of file citylife.cpp.

Function Documentation

◆ add_npc_to_point()

static void add_npc_to_point ( const mapzone zone,
mapstruct map 
)
static

Add an NPC somewhere at a spawn point.

Parameters
zonemap zone definition from which to get a spawn point.
mapmap to insert into.

Definition at line 174 of file citylife.cpp.

References get_npc(), disinfect::map, npc_dialog::npc, object_free_drop_inventory(), object_teleport(), mapzone::points, and RANDOM.

Referenced by add_npc_to_random_map().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ add_npc_to_random_map()

static void add_npc_to_random_map ( void  )
static

Find a suitable map loaded and add an NPC to it.

Definition at line 207 of file citylife.cpp.

References add_npc_to_point(), disinfect::count, has_been_loaded(), guildoracle::list, disinfect::map, MAP_IN_MEMORY, maps, RANDOM, and zones.

Referenced by citylife_globalEventListener().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ add_npc_to_zone()

static void add_npc_to_zone ( const mapzone zone,
mapstruct map 
)
static

Add an NPC somewhere in a spawn zone.

Parameters
zonemap zone definition from which to get a spawn zone.
mapmap to insert into.

Definition at line 155 of file citylife.cpp.

References get_npc(), disinfect::map, npc_dialog::npc, object_free_drop_inventory(), object_teleport(), RANDOM, and mapzone::zones.

Referenced by add_npcs_to_map().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ add_npcs_to_map()

static void add_npcs_to_map ( mapstruct map)
static

Add some NPCs to the map, based on the zone definition.

Parameters
mapmap to add to.

Definition at line 189 of file citylife.cpp.

References add_npc_to_zone(), CITYLIFE_NAME, get_zone_for_map(), llevDebug, LOG(), disinfect::map, mapzone::population, and RANDOM.

Referenced by citylife_globalEventListener().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check_zone()

static void check_zone ( const mapzone zone,
const char *  path 
)
static

Check if the zone has valid parameters, LOG() when invalid ones.

Parameters
zonezone to check.
pathzone path in case of error.

Definition at line 326 of file citylife.cpp.

References mapzone::available_archetypes, llevError, LOG(), python_init::path, mapzone::points, mapzone::population, and mapzone::zones.

Referenced by load_citylife().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ citylife_close()

void citylife_close ( )

Definition at line 438 of file citylife.cpp.

References c, CITYLIFE_NAME, EVENT_CLOCK, EVENT_MAPLOAD, events_unregister_global_handler(), events_unregister_object_handler(), m, disinfect::map, and maps.

+ Here is the call graph for this function:

◆ citylife_globalEventListener()

static int citylife_globalEventListener ( int *  type,
  ... 
)
static

Definition at line 226 of file citylife.cpp.

References add_npc_to_random_map(), add_npcs_to_map(), make_face_from_files::args, EVENT_CLOCK, EVENT_MAPLOAD, disinfect::map, RANDOM, and is_valid_types_gen::type.

Referenced by citylife_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ citylife_init()

◆ eventListener()

static int eventListener ( int *  type,
  ... 
)
static

If the key doesn't exist, it means 'who' wasn't created by us, since we do set the key each time. So play it safe and totally remove the event.

Definition at line 250 of file citylife.cpp.

References object::above, make_face_from_files::args, CLEAR_FLAG, animate::event, EVENT_ATTACKED, EVENT_CONNECTOR, EVENT_TIME, EXIT, FIRST_MOVE_KEY, FLAG_NO_DROP, FLAG_RANDOM_MOVE, FLAG_STAND_STILL, get_map_flags(), GET_MAP_OB, commongive::inv, llevInfo, LOG(), disinfect::map, move_ob(), object_find_by_type_subtype(), object_free(), object_free_drop_inventory(), object_get_value(), object_remove(), object_set_value(), P_OUT_OF_MAP, RANDOM, SET_FLAG, is_valid_types_gen::type, object::type, autojail::value, and autojail::who.

Referenced by citylife_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_npc()

static object* get_npc ( const mapzone zone)
static

Creates a NPC for the specified zone, and do needed initialization.

Parameters
zonewhat NPCs to create.
Returns
new NPC, with event handled for time. NULL if invalid archetype in the zone.

Definition at line 115 of file citylife.cpp.

References add_string(), archininventory::arch, arch_to_object(), mapzone::available_archetypes, CITYLIFE_NAME, create_archetype(), roll-o-matic::evt, FIRST_MOVE_KEY, FLAG_RANDOM_MOVE, FLAG_UNDEAD, FLAG_UNIQUE, llevError, LOG(), npc_dialog::npc, object_insert_in_ob(), object_set_value(), RANDOM, SET_FLAG, and try_find_archetype().

Referenced by add_npc_to_point(), and add_npc_to_zone().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_zone_for_map()

static const mapzone* get_zone_for_map ( mapstruct map)
static

Finds if a map has a zone defined.

Parameters
mapcandidat map.
Returns
map zone, NULL if not defined.

Definition at line 103 of file citylife.cpp.

References disinfect::map, and maps.

Referenced by add_npcs_to_map().

+ Here is the caller graph for this function:

◆ load_citylife()

static void load_citylife ( BufferReader reader,
const char *  filename 
)
static

Read a .citylife file.

Parameters
readerfile reader.
filenamefull file path in case of error.

Definition at line 346 of file citylife.cpp.

References mapzone::available_archetypes, bufferreader_current_line(), bufferreader_next_line(), check_zone(), npc_dialog::filename, is_valid_types_gen::found, is_valid_types_gen::line, llevError, LOG(), maps, python_init::path, mapzone::points, mapzone::population, split(), split_string(), spawn_point::x, spawn_point::y, Moving_Fog::z, and mapzone::zones.

Referenced by citylife_init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mapzone()

mapzone::mapzone ( )
inline

Definition at line 83 of file citylife.cpp.

Variable Documentation

◆ available_archetypes

std::vector<std::string> mapzone::available_archetypes

What archetypes can we chose from for an NPC?

Definition at line 88 of file citylife.cpp.

Referenced by check_zone(), get_npc(), and load_citylife().

◆ c

◆ ex

int spawn_zone::ex

Definition at line 76 of file citylife.cpp.

◆ ey

int spawn_zone::ey

Definition at line 76 of file citylife.cpp.

◆ m

Definition at line 425 of file citylife.cpp.

Referenced by allocate_map(), animate_weapon(), apply_auto_fix(), attempt_jump(), auto_apply_fix_inventory(), blocked_link(), calculate_difficulty(), can_see_monsterP(), cast_cause_disease(), cast_cone(), cast_create_obj(), cast_destruction(), cast_detection(), cast_earth_to_dust(), cast_light(), cast_polymorph(), cast_raise_dead_spell(), cast_transfer(), cf_map_change_light(), cf_map_get_object_at(), cf_map_insert_object_there(), cf_map_message(), cf_object_change_map(), cfapi_map_get_map(), cfpython_init_types(), change_map_light(), check_bullet(), check_pick(), CREMapInformationManager::checkItem(), citylife_close(), citylife_init(), clean_tmp_files(), clean_tmp_map(), command_reset(), command_swap(), common_process_projectile(), counterspell(), create_bomb(), create_map_in_quest_array(), create_maps_array(), current_map_info(), dawn_to_dusk(), decay_objects(), delete_map(), delete_unique_items(), dimension_door(), dispel_rune(), do_auto_apply(), do_skill_ident(), do_throw(), draw_client_map(), draw_client_map2(), dump_all_maps(), dump_map(), expand_lighted_sight(), explosion(), fill_json(), find_spot_for_submap(), find_target_for_friendly_spell(), find_traps(), fire_arch_from_position(), fire_bow(), flee_player(), flush_old_maps(), forklightning(), free_all_objects(), free_map(), nlohmann::detail::from_json(), get_empty_map(), get_map_from_coord(), get_name_of_region_for_map(), get_rangevector_from_mapcoord(), get_region_by_map(), nlohmann::detail::dtoa_impl::grisu2_digit_gen(), initcjson_shared(), initPlugin(), legacy_monster_stand_in_light(), link_multipart_objects(), load_map_header(), load_objects(), load_overlay_map(), load_temporary_map(), load_unique_objects(), look_at(), magic_wall(), main(), malloc_info(), map_find_by_archetype(), map_find_by_type(), map_info(), map_reset_swap(), map_size(), map_space(), mapfile_load(), mapfile_load_lowlevel(), mapsave_test(), monster_check_doors(), monster_check_earthwalls(), monster_find_nearest_enemy(), monster_move(), monster_npc_call_help(), monster_stand_in_light_internal(), mood_change(), move_aura(), move_ball_spell(), move_bolt(), move_bullet(), move_ob(), move_player_attack(), move_player_mover(), move_swarm_spell(), ob_blocked(), object_check_move_on(), object_find_first_free_spot(), object_find_free_spot(), Object_GetMap(), object_insert_in_map(), object_insert_in_map_at(), object_remove(), ok_to_put_more(), out_of_map(), path_to_player(), pets_move(), pets_move_golem(), pick_arrow_target(), place_alchemy_objects(), players_on_map(), polymorph_item(), print_shop_string(), probe(), CREMapInformationManager::process(), process_map(), push_ob(), PyInit_cjson(), PyInit_Crossfire(), ready_map_name(), reflwall(), remove_adjacent_doors(), remove_trap(), roll_ob(), save_map(), save_objects(), save_throw_object(), send_map_info(), set_darkness_map(), singing(), skill_attack(), spell_find_dir(), stand_near_hostile(), steal(), teleport(), test_stand_in_light(), try_fit(), update_buttons(), update_position(), use_oratory(), wall_blocked(), wildcard_match(), write_rune(), and writeMethods().

◆ maps

◆ points

std::vector<spawn_point> mapzone::points

Points to spawn from when there is a player on the map.

Definition at line 83 of file citylife.cpp.

Referenced by add_npc_to_point(), check_zone(), and load_citylife().

◆ population

int mapzone::population

Maximum of NPCs to add at load time.

Definition at line 87 of file citylife.cpp.

Referenced by add_npcs_to_map(), check_zone(), and load_citylife().

◆ sx

int spawn_zone::sx

Definition at line 76 of file citylife.cpp.

◆ sy

int spawn_zone::sy

Definition at line 76 of file citylife.cpp.

◆ x

int spawn_point::x

Definition at line 67 of file citylife.cpp.

Referenced by load_citylife().

◆ y

int spawn_point::y

Definition at line 68 of file citylife.cpp.

Referenced by load_citylife().

◆ zones

std::vector<spawn_zone> mapzone::zones

Zones where to spawn at load time.

Definition at line 86 of file citylife.cpp.

Referenced by add_npc_to_zone(), check_zone(), and load_citylife().