Debian Codegraph @

common/info.c

raw symbols SCIP
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 <[email protected]>.
12 */
13
14 #include "global.h"
15
16 #include <stdlib.h>
17
18 /**
19 * @file
20 * The functions in this file are purely mean to generate information
21 * in differently formatted output, mainly about monsters.
22 */
23
24 /**
25 * Writes num ones and zeros to the given string based on the
26 * bits variable.
27 *
28 * @param bits
29 * variable to convert to binary string
30 * @param num
31 * number of bits to dump. Values above 32 will be ignored.
32 * @param str
33 * string to write to. Must be long enough.
34 *
35 * @note
36 * no check is done whether str has enough space to write or not.
37 * Final \\0 is appended to str.
38 */
39 static void bitstostring(long bits, int num, char *str) {
40 int i, j = 0;
41
42 if (num > 32)
43 num = 32;
44
45 for (i = 0; i < num; i++) {
46 if (i && (i%3) == 0) {
47 str[i+j] = ' ';
48 j++;
49 }
50 if (bits&1)
51 str[i+j] = '1';
52 else
53 str[i+j] = '0';
54 bits >>= 1;
55 }
56 str[i+j] = '\0';
57 return;
58 }
59
60 /**
61 * Dump to standard out the abilities of all monsters.
62 */
63 void dump_abilities(void) {
64 archetype *at;
65 char *name;
66
67 for (at = first_archetype; at; at = at->next) {
68 const char *gen_name = "";
69 archetype *gen;
70
71 if (!QUERY_FLAG(&at->clone, FLAG_MONSTER))
72 continue;
73
74 /* Get rid of e.g. multiple black puddings */
75 if (QUERY_FLAG(&at->clone, FLAG_CHANGING))
76 continue;
77
78 for (gen = first_archetype; gen; gen = gen->next) {
79 if (gen->clone.other_arch && gen->clone.other_arch == at) {
80 gen_name = gen->name;
81 break;
82 }
83 }
84
85 name = stringbuffer_finish(describe_item(&at->clone, NULL, 0, NULL));
86 printf("%-16s|%6"FMT64"|%4d|%3d|%s|%s|%s\n", at->clone.name, at->clone.stats.exp,
87 at->clone.stats.hp, at->clone.stats.ac, name, at->name, gen_name);
88 free(name);
89 }
90 }
91
92 /**
93 * As dump_abilities(), but with an alternative way of output.
94 */
95 void print_monsters(void) {
96 archetype *at;
97 object *op;
98 char attbuf[34];
99 int i;
100
101 printf(" | | | | | attack | resistances |\n");
102 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");
103 printf("---------------------------------------------------------------------------------------------------------------------------------------------------\n");
104 for (at = first_archetype; at != NULL; at = at->next) {
105 op = arch_to_object(at);
106 if (QUERY_FLAG(op, FLAG_MONSTER)) {
107 bitstostring((long)op->attacktype, NROFATTACKS, attbuf);
108 printf("%-15s|%5d|%3d|%4d|%4d|%s|",
109 op->arch->name, op->stats.maxhp, op->stats.dam, op->stats.ac,
110 op->stats.wc, attbuf);
111 for (i = 0; i < NROFATTACKS; i++)
112 printf("%4d", op->resist[i]);
113 printf("|%8"FMT64"|%9"FMT64"|\n", op->stats.exp, new_exp(op));
114 }
115 object_free_drop_inventory(op);
116 }
117 }