Crossfire Server, Trunk  R20608
City life plugin
+ Collaboration diagram for City life plugin:

Modules

 Scorn parameters
 
 darcap parameters
 
 Navar parameters
 
 Port Joseph parameters
 
 stoneville parameters
 
 Wolfsburg parameters
 
 Santo Dominion 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)
 

Variables

CF_PLUGIN char SvnRevPlugin [] = SVN_REV
 
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 int citylife_globalEventListener (int *type,...)
 
CF_PLUGIN int postInitPlugin (void)
 
CF_PLUGIN int 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 110 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 630 of file citylife.c.

References cf_object_free_drop_inventory(), cf_object_teleport(), mapzone::count_points, get_npc(), mapzone::points, RANDOM, 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 663 of file citylife.c.

References add_npc_to_point(), cf_map_has_been_loaded(), mapzone::count_points, MAP_IN_MEMORY, RANDOM, 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 611 of file citylife.c.

References cf_object_free_drop_inventory(), cf_object_teleport(), mapzone::count_zones, spawn_zone::ex, spawn_zone::ey, get_npc(), RANDOM, 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 645 of file citylife.c.

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

Referenced by citylife_globalEventListener().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 682 of file citylife.c.

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

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

References cf_log(), llevDebug, and PLUGIN_VERSION.

+ Here is the call graph for this function:

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

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

Parameters
typeignored.
Returns
0.

Unused.

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

Definition at line 736 of file citylife.c.

References cf_map_get_object_at(), cf_object_free_drop_inventory(), 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, obj::map, RANDOM, 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 580 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, RANDOM, 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 563 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 79 of file citylife.c.

References PLUGIN_NAME, PLUGIN_VERSION, and snprintf.

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 71 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 706 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 },
{ darcap_points, 19, darcap_zones, 3, 4, "/world/world_116_102", darcap_archs, 12},
{ navar_nw_points, 8, navar_nw_zones, 4, 2, "/world/world_121_116", navar_archs, 15 },
{ navar_ne_points, 6, navar_ne_zones, 3, 5, "/world/world_122_116", navar_archs, 15 },
{ navar_sw_points, 3, navar_sw_zones, 2, 3, "/world/world_121_117", navar_archs, 15 },
{ navar_se_points, 8, navar_se_zones, 4, 5, "/world/world_122_117", navar_archs, 15 },
{ port_joseph_points, 6, port_joseph_zones, 1, 3, "/world/world_101_114", port_joseph_archs, 8 },
{ stoneville_points, 5, stoneville_zones, 1, 2, "/world/world_103_127", stoneville_archs, 8 },
{ wolfsburg_points, 8, wolfsburg_zones, 1, 4, "/world/world_128_109", wolfsburg_archs, 8 },
{ santo_dominion_points, 8, santo_dominion_zones, 2, 3, "/world/world_102_108", santo_dominion_archs, 8 },
{ NULL, -1, NULL, -1, 1, "", NULL, 0 },
}
static const spawn_point scorn_se_points[]
Definition: citylife.c:196
static const spawn_zone scorn_nw_zones[]
Definition: citylife.c:151
static const spawn_zone navar_nw_zones[]
Definition: citylife.c:286
static const spawn_zone port_joseph_zones[]
Definition: citylife.c:385
static const char *const wolfsburg_archs[]
Definition: citylife.c:477
static const spawn_point scorn_nw_points[]
Definition: citylife.c:156
static const spawn_point scorn_ne_points[]
Definition: citylife.c:170
static const char *const darcap_archs[]
Definition: citylife.c:260
static const spawn_point navar_nw_points[]
Definition: citylife.c:294
static const char *const navar_archs[]
Definition: citylife.c:356
static const spawn_zone navar_se_zones[]
Definition: citylife.c:336
static const spawn_point scorn_sw_points[]
Definition: citylife.c:184
static const spawn_point stoneville_points[]
Definition: citylife.c:427
static const char *const santo_dominion_archs[]
Definition: citylife.c:519
static const spawn_zone stoneville_zones[]
Definition: citylife.c:422
static const char *const stoneville_archs[]
Definition: citylife.c:437
static const spawn_zone navar_sw_zones[]
Definition: citylife.c:323
static const spawn_point navar_sw_points[]
Definition: citylife.c:329
static const spawn_zone darcap_zones[]
Definition: citylife.c:229
static const spawn_zone scorn_ne_zones[]
Definition: citylife.c:165
static const spawn_zone scorn_se_zones[]
Definition: citylife.c:191
static const spawn_zone navar_ne_zones[]
Definition: citylife.c:306
static const spawn_point port_joseph_points[]
Definition: citylife.c:390
static const spawn_zone scorn_sw_zones[]
Definition: citylife.c:179
static const spawn_point wolfsburg_points[]
Definition: citylife.c:464
static const spawn_point santo_dominion_points[]
Definition: citylife.c:506
static const spawn_point navar_se_points[]
Definition: citylife.c:344
static const char *const scorn_archs[]
Definition: citylife.c:204
static const char *const port_joseph_archs[]
Definition: citylife.c:401
static const spawn_point navar_ne_points[]
Definition: citylife.c:313
static const spawn_zone santo_dominion_zones[]
Definition: citylife.c:500
static const spawn_point darcap_points[]
Definition: citylife.c:236
static const spawn_zone wolfsburg_zones[]
Definition: citylife.c:459

All maps we work on.

Definition at line 538 of file citylife.c.

CF_PLUGIN char SvnRevPlugin[] = SVN_REV

Definition at line 69 of file citylife.c.