Crossfire Server, Branches 1.12  R18729
City life plugin
+ Collaboration diagram for City life plugin:

Modules

 Scorn parameters
 

Files

file  citylife.c
 

Data Structures

struct  mapzone
 
struct  spawn_point
 
struct  spawn_zone
 

Macros

#define FIRST_MOVE_KEY   "citylife_first_move"
 

Functions

CF_PLUGIN int citylife_runPluginCommand (object *op, char *params)
 
CF_PLUGIN void * getPluginProperty (int *type,...)
 
CF_PLUGIN int initPlugin (const char *iversion, f_plug_api gethooksptr)
 
static const mapzone available_zones []
 
static const mapzoneget_zone_for_map (mapstruct *map)
 
static objectget_npc (const mapzone *zone)
 
static void add_npc_to_zone (const mapzone *zone, mapstruct *map)
 
static void add_npc_to_point (const mapzone *zone, mapstruct *map)
 
static void add_npcs_to_map (mapstruct *map)
 
static void add_npc_to_random_map (void)
 
CF_PLUGIN void * citylife_globalEventListener (int *type,...)
 
CF_PLUGIN int postInitPlugin (void)
 
CF_PLUGIN void * eventListener (int *type,...)
 
CF_PLUGIN int closePlugin (void)
 

Detailed Description

This plugin 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

#define FIRST_MOVE_KEY   "citylife_first_move"

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

Definition at line 106 of file citylife.c.

Referenced by eventListener(), and get_npc().

Function Documentation

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 304 of file citylife.c.

References cf_object_free(), cf_object_teleport(), mapzone::count_points, get_npc(), mapzone::points, spawn_point::x, and spawn_point::y.

Referenced by add_npc_to_random_map().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void add_npc_to_random_map ( void  )
static

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

Definition at line 337 of file citylife.c.

References add_npc_to_point(), cf_log(), cf_map_has_been_loaded(), mapzone::count_points, llevDebug, MAP_IN_MEMORY, PLUGIN_NAME, and zones.

Referenced by citylife_globalEventListener().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 285 of file citylife.c.

References cf_object_free(), cf_object_teleport(), mapzone::count_zones, spawn_zone::ex, spawn_zone::ey, get_npc(), spawn_zone::sx, spawn_zone::sy, 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:

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 319 of file citylife.c.

References add_npc_to_zone(), cf_log(), get_zone_for_map(), llevDebug, mapdef::path, PLUGIN_NAME, and mapzone::population.

Referenced by citylife_globalEventListener().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

CF_PLUGIN void* citylife_globalEventListener ( int *  type,
  ... 
)

Definition at line 358 of file citylife.c.

References add_npc_to_random_map(), add_npcs_to_map(), EVENT_CLOCK, and EVENT_MAPLOAD.

Referenced by postInitPlugin().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

CF_PLUGIN int citylife_runPluginCommand ( object op,
char *  params 
)

Definition at line 101 of file citylife.c.

CF_PLUGIN int closePlugin ( void  )

Close the plugin.

Closes the sqlite database.

Returns
0.

Unloading of plugin.

Returns
0.

Definition at line 462 of file citylife.c.

References cf_log(), llevDebug, and PLUGIN_VERSION.

+ Here is the call graph for this function:

CF_PLUGIN void* eventListener ( int *  type,
  ... 
)

Handles an object-related event. Doesn't do anything.

Parameters
typeignored.
Returns
pointer to an int containing 0.

Unused.

Parameters
typeunused.
Returns
NULL.
Todo:
build from current map's path, probably

Definition at line 414 of file citylife.c.

References cf_log(), cf_map_get_object_at(), cf_object_free(), cf_object_get_key(), cf_object_get_object_property(), cf_object_move(), cf_object_remove(), cf_object_set_flag(), cf_object_set_key(), CFAPI_OBJECT_PROP_INVENTORY, CFAPI_OBJECT_PROP_OB_ABOVE, CFAPI_OBJECT_PROP_OB_BELOW, EXIT, FIRST_MOVE_KEY, FLAG_NO_DROP, llevDebug, obj::map, PLUGIN_NAME, obj::type, obj::x, and obj::y.

+ Here is the call graph for this function:

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 254 of file citylife.c.

References mapzone::archetypes_count, mapzone::available_archetypes, cf_add_string(), cf_create_object_by_name(), cf_log(), cf_object_insert_object(), cf_object_set_flag(), cf_object_set_key(), FIRST_MOVE_KEY, FLAG_RANDOM_MOVE, FLAG_UNDEAD, llevError, PLUGIN_NAME, obj::slaying, and obj::title.

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:

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 237 of file citylife.c.

References mapzone::count_points, and mapdef::path.

Referenced by add_npcs_to_map().

+ Here is the caller graph for this function:

CF_PLUGIN void* getPluginProperty ( int *  type,
  ... 
)

Gets a plugin property.

Parameters
typeignored.
Returns
  • the name, if asked for 'Identification'.
  • the version, if asked for 'FullName'.
  • NULL else.
Get the plugin identification or full name.
Parameters
typeunused.
Returns
NULL.

Definition at line 75 of file citylife.c.

References PLUGIN_NAME, PLUGIN_VERSION, and snprintf().

+ Here is the call graph for this function:

CF_PLUGIN int initPlugin ( const char *  iversion,
f_plug_api  gethooksptr 
)

Plugin initialisation function.

Parameters
iversionserver version.
gethooksptrfunction to get the hooks.
Returns
0

Main plugin entry point.

Parameters
iversionserver version.
gethooksptrfunction to get hooks from.
Returns
always 0.

Plugin initialization.

Parameters
iversionserver version.
gethooksptrfunction to get hooks.
Returns
0.

Definition at line 67 of file citylife.c.

References cf_init_plugin(), cf_log(), llevDebug, and PLUGIN_VERSION.

+ Here is the call graph for this function:

CF_PLUGIN int postInitPlugin ( void  )

Plugin was initialized, now to finish.

Registers events, initializes the database.

Returns
0.

Plugin initialisation.

Returns
0.

Definition at line 384 of file citylife.c.

References cf_log(), cf_system_register_global_event(), citylife_globalEventListener(), EVENT_CLOCK, EVENT_MAPLOAD, llevDebug, PLUGIN_NAME, and PLUGIN_VERSION.

+ Here is the call graph for this function:

Variable Documentation

const mapzone available_zones[]
static
Initial value:
= {
{ scorn_nw_points, 5, scorn_nw_zones, 1, 2, "/world/world_104_115", scorn_archs, 12 },
{ scorn_ne_points, 1, scorn_ne_zones, 1, 5, "/world/world_105_115", scorn_archs, 12 },
{ scorn_sw_points, 3, scorn_sw_zones, 1, 5, "/world/world_104_116", scorn_archs, 12 },
{ scorn_se_points, 1, scorn_se_zones, 1, 5, "/world/world_105_116", scorn_archs, 12 },
{ NULL, -1, NULL, -1, 1, "", NULL, 0 },
}
static const spawn_point scorn_se_points[]
Definition: citylife.c:192
static const spawn_zone scorn_nw_zones[]
Definition: citylife.c:147
static const spawn_point scorn_nw_points[]
Definition: citylife.c:152
static const spawn_point scorn_ne_points[]
Definition: citylife.c:166
static const spawn_point scorn_sw_points[]
Definition: citylife.c:180
static const spawn_zone scorn_ne_zones[]
Definition: citylife.c:161
static const spawn_zone scorn_se_zones[]
Definition: citylife.c:187
static const spawn_zone scorn_sw_zones[]
Definition: citylife.c:175
static const char *const scorn_archs[]
Definition: citylife.c:200

All maps we work on.

Definition at line 221 of file citylife.c.