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 
41 static void bitstostring(long bits, int num, char *str) {
42  int i, j = 0;
43 
44  if (num > 32)
45  num = 32;
46 
47  for (i = 0; i < num; i++) {
48  if (i && (i%3) == 0) {
49  str[i+j] = ' ';
50  j++;
51  }
52  if (bits&1)
53  str[i+j] = '1';
54  else
55  str[i+j] = '0';
56  bits >>= 1;
57  }
58  str[i+j] = '\0';
59  return;
60 }
61 
65 void dump_abilities(void) {
66  getManager()->archetypes()->each([] (const auto at) {
67  const char *gen_name = "";
68  archetype *gen;
69 
70  if (!QUERY_FLAG(&at->clone, FLAG_MONSTER))
71  return;
72 
73  /* Get rid of e.g. multiple black puddings */
74  if (QUERY_FLAG(&at->clone, FLAG_CHANGING))
75  return;
76 
77  /* Dont print a row for each piece of a multipart object
78  * Doing so confounds the documentation generators that use the -m2 flag.
79  */
80  if (HEAD(&at->clone) != &at->clone)
81  return;
82 
83  gen = getManager()->archetypes()->first([&at] (const auto gen) {
84  return gen->clone.other_arch && gen->clone.other_arch == at;
85  });
86  if (gen) {
87  gen_name = gen->name;
88  }
89 
90  char *name = stringbuffer_finish(describe_item(&at->clone, NULL, 0, NULL));
91  printf("%-16s|%6" FMT64 "|%4d|%3d|%s|%s|%s\n", at->clone.name, at->clone.stats.exp,
92  at->clone.stats.hp, at->clone.stats.ac, name, at->name, gen_name);
93  free(name);
94  });
95 }
96 
100 void print_monsters(void) {
101 
102  printf(" | | | | | attack | resistances |\n");
103  printf("monster | hp |dam| ac | wc |pmf ecw adw gpd ptf|phy mag fir ele cld cfs acd drn wmg ght poi slo par tud fer cnc dep dth chs csp gpw hwd bln int | exp | new exp |\n");
104  printf("---------------------------------------------------------------------------------------------------------------------------------------------------\n");
105  getManager()->archetypes()->each([] (const auto at) {
106  char attbuf[34];
107  object *op = arch_to_object(at);
108  if (QUERY_FLAG(op, FLAG_MONSTER)) {
109  bitstostring((long)op->attacktype, NROFATTACKS, attbuf);
110  printf("%-15s|%5d|%3d|%4d|%4d|%s|",
111  op->arch->name, op->stats.maxhp, op->stats.dam, op->stats.ac,
112  op->stats.wc, attbuf);
113  for (int i = 0; i < NROFATTACKS; i++)
114  printf("%4d", op->resist[i]);
115  printf("|%8" FMT64 "|%9" FMT64 "|\n", op->stats.exp, new_exp(op));
116  }
118  });
119 }
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
make_face_from_files.str
str
Definition: make_face_from_files.py:30
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:65
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
describe_item
StringBuffer * describe_item(const object *op, const object *owner, int use_media_tags, StringBuffer *buf)
Definition: item.cpp:951
give.op
op
Definition: give.py:33
print_monsters
void print_monsters(void)
Definition: info.cpp:100
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
bitstostring
static void bitstostring(long bits, int num, char *str)
Definition: info.cpp:41
give.name
name
Definition: give.py:27