Crossfire Server, Branch 1.12  R12190
Data Structures | Modules | Files | Defines | Functions
City life plugin

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

Collaboration diagram for City life plugin:

Data Structures

struct  mapzone
 Options for a map. More...
struct  spawn_point
 Point from which a NPC can come when the map is loaded. More...
struct  spawn_zone
 Zone in which to add NPCs when the map was just loaded. More...

Modules

 Scorn parameters
 

Parameters for the City life plugin for Scorn.


Files

file  citylife.c
 

This file is part of the city life plugin.


Defines

#define FIRST_MOVE_KEY   "citylife_first_move"
 Key to contain whether it's the first move of the NPC or not.

Functions

CF_PLUGIN int citylife_runPluginCommand (object *op, char *params)
CF_PLUGIN void * getPluginProperty (int *type,...)
 Gets a plugin property.
CF_PLUGIN int initPlugin (const char *iversion, f_plug_api gethooksptr)
 Plugin initialisation function.
static const mapzone available_zones []
 All maps we work on.
static const mapzoneget_zone_for_map (mapstruct *map)
 Finds if a map has a zone defined.
static object * get_npc (const mapzone *zone)
 Creates a NPC for the specified zone, and do needed initialization.
static void add_npc_to_zone (const mapzone *zone, mapstruct *map)
 Add an NPC somewhere in a spawn zone.
static void add_npc_to_point (const mapzone *zone, mapstruct *map)
 Add an NPC somewhere at a spawn point.
static void add_npcs_to_map (mapstruct *map)
 Add some NPCs to the map, based on the zone definition.
static void add_npc_to_random_map (void)
 Find a suitable map loaded and add an NPC to it.
CF_PLUGIN void * citylife_globalEventListener (int *type,...)
CF_PLUGIN int postInitPlugin (void)
 Plugin was initialized, now to finish.
CF_PLUGIN void * eventListener (int *type,...)
 Handles an object-related event.
CF_PLUGIN int closePlugin (void)
 Close the plugin.

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

Define 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.

Close the 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.

Handles an object-related event.

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, and PLUGIN_NAME.

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, and PLUGIN_NAME.

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.
Gets a plugin property.
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

Plugin initialisation function.

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

Plugin initialisation function.

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 was initialized, now to finish.

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 },
}

All maps we work on.

Definition at line 221 of file citylife.c.