 |
Crossfire Server, Trunk
1.75.0
|
Go to the documentation of this file.
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) {
396 zone->
zones.push_back(z);
400 if (strcmp(
line,
"point") == 0) {
408 zone->
points.push_back(p);
412 if (strcmp(
line,
"arch") == 0) {
441 for (
auto map :
maps) {
#define GET_MAP_OB(M, X, Y)
Gets the bottom object on a map.
object * object_find_by_type_subtype(const object *who, int type, int subtype)
Find object in inventory.
void citylife_init(Settings *, ServerSettings *serverSettings)
#define FLAG_STAND_STILL
NPC will not (ever) move.
size_t bufferreader_current_line(BufferReader *br)
Return the index of the last line returned by bufferreader_next_line().
@ llevError
Error, serious thing.
static std::unordered_map< std::string, mapzone * > maps
All defined maps, with the path as key.
@ EVENT_CONNECTOR
Lauwenmark: an invisible object holding a plugin event hook.
int population
Maximum of NPCs to add at load time.
void LOG(LogLevel logLevel, const char *format,...)
Logs a message to stderr, or to file.
#define FLAG_UNDEAD
Monster is undead.
object * inv
Pointer to the first object in the inventory.
mapstruct * has_been_loaded(const char *name)
Checks whether map has been loaded.
static int eventListener(int *type,...)
static event_registration c
void events_unregister_object_handler(const char *id)
Remove an object event handler.
static void add_npc_to_point(const mapzone *zone, mapstruct *map)
Add an NPC somewhere at a spawn point.
#define FLAG_UNIQUE
Item is really unique (UNIQUE_ITEMS)
struct mapstruct * map
Pointer to the map in which this object is present.
std::vector< spawn_point > points
Points to spawn from when there is a player on the map.
static const mapzone * get_zone_for_map(mapstruct *map)
Finds if a map has a zone defined.
sstring title
Of foo, etc.
char path[HUGE_BUF]
Filename of the map.
#define CITYLIFE_NAME
Module name for the event system.
object * object_insert_in_ob(object *op, object *where)
This function inserts the object op in the linked list inside the object environment.
object * above
Pointer to the object stacked above this one.
static const house_zone_struct zones[]
Maps we work on.
event_registration events_register_global_handler(int eventcode, f_plug_event hook)
Register a global event handler.
int16_t y
Position in the map for this object.
static event_registration m
void events_register_object_handler(const char *id, f_plug_event handler)
Register an object event handler.
std::vector< char * > disabled_plugins
List of disabled plugins, 'All' means all.
#define MAP_IN_MEMORY
Map is fully loaded.
void object_free_drop_inventory(object *ob)
Frees everything allocated by an object, removes it from the list of used objects,...
uint8_t subtype
Subtype of object.
static void load_citylife(BufferReader *reader, const char *filename)
Read a .citylife file.
int move_ob(object *op, int dir, object *originator)
Op is trying to move in direction dir.
void assets_add_collector_hook(const char *name, collectorHook hook)
void events_unregister_global_handler(int eventcode, event_registration id)
Remove a global event handler.
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.
sstring add_string(const char *str)
This will add 'str' to the hash table.
static void check_zone(const mapzone *zone, const char *path)
Check if the zone has valid parameters, LOG() when invalid ones.
object * below
Pointer to the object stacked below this one.
std::vector< spawn_zone > zones
Zones where to spawn at load time.
uint8_t type
PLAYER, BULLET, etc.
#define EVENT_CLOCK
Global time event.
void object_free(object *ob, int flags)
Frees everything allocated by an object, removes it from the list of used objects,...
static void add_npcs_to_map(mapstruct *map)
Add some NPCs to the map, based on the zone definition.
The archetype structure is a set of rules on how to generate and manipulate objects which point to ar...
#define EVENT_TIME
Triggered each time the object can react/move.
#define FLAG_NO_DROP
Object can't be dropped.
std::vector< std::string > available_archetypes
What archetypes can we chose from for an NPC?
static void add_npc_to_zone(const mapzone *zone, mapstruct *map)
Add an NPC somewhere in a spawn zone.
#define FLAG_RANDOM_MOVE
NPC will move randomly.
Point from which a NPC can come when the map is loaded.
#define P_OUT_OF_MAP
This space is outside 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...
sstring slaying
Which race to do double damage to.
static int citylife_globalEventListener(int *type,...)
sstring name
The name of the object, obviously...
unsigned long event_registration
Registration identifier type.
ServerSettings serverSettings
static void add_npc_to_random_map(void)
Find a suitable map loaded and add an NPC to it.
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_.
Zone in which to add NPCs when the map was just loaded.
sstring object_get_value(const object *op, const char *const key)
Get an extra value by key.
#define CLEAR_FLAG(xyz, p)
Structure used to build up dialog information when a player says something.
object * arch_to_object(archetype *at)
Creates and returns a new object which is a copy of the given archetype.
void object_remove(object *op)
This function removes the object op from the linked list of objects which it is currently tied to.
archetype * try_find_archetype(const char *name)
#define EVENT_MAPLOAD
A map is loaded (pristine state)
#define EVENT_ATTACKED
Object attacked, with weapon or spell.
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.
Crossfire Architecture the general intention is to enhance the enjoyability and playability of CF In this code
static object * get_npc(const mapzone *zone)
Creates a NPC for the specified zone, and do needed initialization.
static std::vector< std::string > split(const std::string &field, const std::string &by)
How to Install a Crossfire Server on you must install a python script engine on your computer Python is the default script engine of Crossfire You can find the python engine you have only to install them The VisualC Crossfire settings are for but you habe then to change the pathes in the VC settings Go in Settings C and Settings Link and change the optional include and libs path to the new python installation path o except the maps ! You must download a map package and install them the share folder Its must look like doubleclick on crossfire32 dsw There are projects in your libcross lib and plugin_python You need to compile all Easiest way is to select the plugin_python ReleaseLog as active this will compile all others too Then in Visual C press< F7 > to compile If you don t have an appropriate compiler you can try to get the the VC copies the crossfire32 exe in the crossfire folder and the plugin_python dll in the crossfire share plugins folder we will remove it when we get time for it o Last showing lots of weird write to the Crossfire mailing list
int object_set_value(object *op, const char *key, const char *value, int add_key)
Updates the key in op to value.
#define FIRST_MOVE_KEY
Key to contain whether it's the first move of the NPC or not.
@ llevDebug
Only for debugging purposes.
char * bufferreader_next_line(BufferReader *br)
Return the next line in the buffer, as separated by a newline.