Crossfire Server, Trunk
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 }
global.h
new_exp
int64_t new_exp(const object *ob)
Definition: exp.cpp:100
QUERY_FLAG
#define QUERY_FLAG(xyz, p)
Definition: define.h:226
AssetsManager.h
if
if(!(yy_init))
Definition: loader.cpp:36428
NROFATTACKS
#define NROFATTACKS
Definition: attack.h:17
getManager
AssetsManager * getManager()
Definition: assets.cpp:305
stringbuffer_finish
char * stringbuffer_finish(StringBuffer *sb)
Definition: stringbuffer.cpp:76
object_free_drop_inventory
void object_free_drop_inventory(object *ob)
Definition: object.cpp:1560
FMT64
#define FMT64
Definition: compat.h:16
archetype::clone
object clone
Definition: object.h:487
HEAD
#define HEAD(op)
Definition: object.h:607
bitstostring
static void bitstostring(long bits, int num)
Definition: info.cpp:35
archetype
Definition: object.h:483
AssetsCollection::each
void each(std::function< void(T *)> op)
Definition: AssetsCollection.h:158
dump_abilities
void dump_abilities(void)
Definition: info.cpp:52
object::other_arch
struct archetype * other_arch
Definition: object.h:425
FLAG_MONSTER
#define FLAG_MONSTER
Definition: define.h:245
AssetsManager::archetypes
Archetypes * archetypes()
Definition: AssetsManager.h:44
resist_plus
const char *const resist_plus[NROFATTACKS]
Definition: init.cpp:49
describe_item
StringBuffer * describe_item(const object *op, const object *owner, int use_media_tags, StringBuffer *buf)
Definition: item.cpp:951
attacktype_desc
const char *const attacktype_desc[NROFATTACKS]
Definition: init.cpp:40
give.op
op
Definition: give.py:33
print_monsters
void print_monsters(void)
Definition: info.cpp:87
assets.h
arch_to_object
object * arch_to_object(archetype *at)
Definition: arch.cpp:229
archetype::name
sstring name
Definition: object.h:484
FLAG_CHANGING
#define FLAG_CHANGING
Definition: define.h:263
give.name
name
Definition: give.py:27