Crossfire Server, Trunk  1.75.0
info.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2014 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
14 #include "global.h"
15 #include "assets.h"
16 #include "AssetsManager.h"
17 
18 #include <stdlib.h>
19 
35 static void bitstostring(long bits, int num) {
36  if (num > 32)
37  num = 32;
38 
39  for (int i = 0; i < num; i++) {
40  if (bits&1)
41  putchar('1');
42  else
43  putchar('0');
44  putchar(',');
45  bits >>= 1;
46  }
47 }
48 
52 void dump_abilities(void) {
53  getManager()->archetypes()->each([] (const auto at) {
54  const char *gen_name = "";
55  archetype *gen;
56 
57  if (!QUERY_FLAG(&at->clone, FLAG_MONSTER))
58  return;
59 
60  /* Get rid of e.g. multiple black puddings */
61  if (QUERY_FLAG(&at->clone, FLAG_CHANGING))
62  return;
63 
64  /* Dont print a row for each piece of a multipart object
65  * Doing so confounds the documentation generators that use the -m2 flag.
66  */
67  if (HEAD(&at->clone) != &at->clone)
68  return;
69 
70  gen = getManager()->archetypes()->first([&at] (const auto gen) {
71  return gen->clone.other_arch && gen->clone.other_arch == at;
72  });
73  if (gen) {
74  gen_name = gen->name;
75  }
76 
77  char *name = stringbuffer_finish(describe_item(&at->clone, NULL, 0, NULL));
78  printf("%-16s|%6" FMT64 "|%4d|%3d|%s|%s|%s\n", at->clone.name, at->clone.stats.exp,
79  at->clone.stats.hp, at->clone.stats.ac, name, at->name, gen_name);
80  free(name);
81  });
82 }
83 
87 void print_monsters(void) {
88  // Generate CSV header
89  printf("monster,hp,dam,ac,wc,");
90  for (int i = 0; i < NROFATTACKS; i++) {
91  printf("%s,", attacktype_desc[i]);
92  }
93  for (int i = 0; i < NROFATTACKS; i++) {
94  printf("%s,", resist_plus[i]);
95  }
96  printf("exp,new exp\n");
97 
98  // Monster data
99  getManager()->archetypes()->each([] (const auto at) {
100  object *op = arch_to_object(at);
101  if (QUERY_FLAG(op, FLAG_MONSTER)) {
102  printf("%s,%d,%d,%d,%d,",
103  op->arch->name, op->stats.maxhp, op->stats.dam, op->stats.ac,
104  op->stats.wc);
105  bitstostring((long)op->attacktype, NROFATTACKS);
106  for (int i = 0; i < NROFATTACKS; i++)
107  printf("%d,", op->resist[i]);
108  printf("%" FMT64 ",%" FMT64 "\n", op->stats.exp, new_exp(op));
109  }
111  });
112 }
living::exp
int64_t exp
Experience.
Definition: living.h:47
global.h
living::maxhp
int16_t maxhp
Max hit points.
Definition: living.h:41
new_exp
int64_t new_exp(const object *ob)
Alternative way to calculate experience based on the ability of a monster.
Definition: exp.cpp:100
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:371
AssetsManager.h
object::arch
struct archetype * arch
Pointer to archetype.
Definition: object.h:424
if
if(!(yy_init))
Definition: loader.cpp:36440
archetypes
in that case they will be relative to whatever the PWD of the crossfire server process is You probably shouldn though Notes on Specific and settings file datadir Usually usr share crossfire Contains data that the server does not need to modify while such as the archetypes
Definition: server-directories.txt:45
NROFATTACKS
#define NROFATTACKS
Definition: attack.h:15
getManager
AssetsManager * getManager()
Definition: assets.cpp:309
object::resist
int16_t resist[NROFATTACKS]
Resistance adjustments for attacks.
Definition: object.h:351
name
Plugin animator file specs[Config] name
Definition: animfiles.txt:4
stringbuffer_finish
char * stringbuffer_finish(StringBuffer *sb)
Deallocate the string buffer instance and return the string.
Definition: stringbuffer.cpp:76
object_free_drop_inventory
void object_free_drop_inventory(object *ob)
Frees everything allocated by an object, removes it from the list of used objects,...
Definition: object.cpp:1545
FMT64
#define FMT64
Definition: compat.h:16
archetype::clone
object clone
An object from which to do object_copy()
Definition: object.h:487
FLAG_MONSTER
#define FLAG_MONSTER
Will attack players.
Definition: define.h:232
HEAD
#define HEAD(op)
Returns the head part of an object.
Definition: object.h:607
living::dam
int16_t dam
How much damage this object does when hitting.
Definition: living.h:46
FLAG_CHANGING
#define FLAG_CHANGING
Changes to other_arch when anim is done.
Definition: define.h:250
bitstostring
static void bitstostring(long bits, int num)
Writes num ones and zeros to standard output based on the bits variable.
Definition: info.cpp:35
archetype
The archetype structure is a set of rules on how to generate and manipulate objects which point to ar...
Definition: object.h:483
AssetsCollection::each
void each(std::function< void(T *)> op)
Apply a function to each asset.
Definition: AssetsCollection.h:158
dump_abilities
void dump_abilities(void)
Dump to standard out the abilities of all monsters.
Definition: info.cpp:52
object::other_arch
struct archetype * other_arch
Pointer used for various things - mostly used for what this objects turns into or what this object cr...
Definition: object.h:425
AssetsManager::archetypes
Archetypes * archetypes()
Get archetypes.
Definition: AssetsManager.h:44
resist_plus
const char *const resist_plus[NROFATTACKS]
Attack types to show to the player.
Definition: init.cpp:49
describe_item
StringBuffer * describe_item(const object *op, const object *owner, int use_media_tags, StringBuffer *buf)
Describes an item, in all its details.
Definition: item.cpp:953
living::wc
int8_t wc
Weapon Class, lower WC increases probability of hitting.
Definition: living.h:37
attacktype_desc
const char *const attacktype_desc[NROFATTACKS]
Short description of names of the attacktypes.
Definition: init.cpp:40
print_monsters
void print_monsters(void)
As dump_abilities(), but with an alternative way of output.
Definition: info.cpp:87
assets.h
living::ac
int8_t ac
Armor Class, lower AC increases probability of not getting hit.
Definition: living.h:38
arch_to_object
object * arch_to_object(archetype *at)
Creates and returns a new object which is a copy of the given archetype.
Definition: arch.cpp:227
archetype::name
sstring name
More definite name, like "generate_kobold".
Definition: object.h:484
object::stats
living stats
Str, Con, Dex, etc.
Definition: object.h:378
object::attacktype
uint32_t attacktype
Bitmask of attacks this object does.
Definition: object.h:352