Crossfire Server, Branches 1.12  R18729
holy.c
Go to the documentation of this file.
1 /*
2  * static char *rcsid_holy_c =
3  * "$Id: holy.c 11578 2009-02-23 22:02:27Z lalo $";
4  */
5 
6 /*
7  CrossFire, A Multiplayer game for X-windows
8 
9  Copyright (C) 2006 Mark Wedel & Crossfire Development Team
10  Copyright (C) 1992 Frank Tore Johansen
11 
12  This program is free software; you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation; either version 2 of the License, or
15  (at your option) any later version.
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program; if not, write to the Free Software
24  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 
26  The authors can be reached via e-mail at crossfire-devel@real-time.com
27 */
28 
34 #include <stdlib.h>
35 #include <global.h>
36 #include <living.h>
37 #include <spells.h>
38 
39 static void add_god_to_list(archetype *god_arch);
40 
47 static godlink *init_godslist(void) {
48  godlink *gl = (godlink *)malloc(sizeof(godlink));
49  if (gl == NULL)
51  gl->name = NULL; /* how to describe the god to the player */
52  gl->arch = NULL; /* pointer to the archetype of this god */
53  gl->id = 0; /* id of the god */
54  gl->next = NULL; /* next god in this linked list */
55 
56  return gl;
57 }
58 
63 void init_gods(void) {
64  archetype *at = NULL;
65 
66  LOG(llevDebug, "Initializing gods...\n");
67  for (at = first_archetype; at != NULL; at = at->next)
68  if (at->clone.type == GOD)
69  add_god_to_list(at);
70 
71  LOG(llevDebug, "done.\n");
72 }
73 
80 static void add_god_to_list(archetype *god_arch) {
81  godlink *god;
82 
83  if (!god_arch) {
84  LOG(llevError, "ERROR: Tried to add null god to list!\n");
85  return;
86  }
87 
88  god = init_godslist();
89 
90  god->arch = god_arch;
91  god->name = add_string(god_arch->clone.name);
92  if (!first_god)
93  god->id = 1;
94  else {
95  god->id = first_god->id+1;
96  god->next = first_god;
97  }
98  first_god = god;
99 
100 #ifdef DEBUG_GODS
101  LOG(llevDebug, "Adding god %s (%d) to list\n", god->name, god->id);
102 #endif
103 }
104 
112  godlink *god = first_god;
113  int i;
114 
115  if (god)
116  for (i = RANDOM()%(god->id)+1; god; god = god->next)
117  if (god->id == i)
118  break;
119 
120  if (!god)
121  LOG(llevError, "get_rand_god(): can't find a random god!\n");
122  return god;
123 }
124 
133 const object *pntr_to_god_obj(godlink *godlnk) {
134  if (godlnk && godlnk->arch)
135  return &godlnk->arch->clone;
136  return NULL;
137 }
138 
142 void free_all_god(void) {
143  godlink *god, *godnext;
144 
145  LOG(llevDebug, "Freeing god information\n");
146  for (god = first_god; god; god = godnext) {
147  godnext = god->next;
148  if (god->name)
149  free_string(god->name);
150  free(god);
151  }
152  first_god = NULL;
153 }
154 
161 void dump_gods(void) {
162  godlink *glist;
163 
164  fprintf(stderr, "\n");
165  for (glist = first_god; glist; glist = glist->next) {
166  const object *god = pntr_to_god_obj(glist);
167  char tmpbuf[HUGE_BUF];
168  int tmpvar, gifts = 0;
169 
170  fprintf(stderr, "GOD: %s\n", god->name);
171  fprintf(stderr, " avatar stats:\n");
172  fprintf(stderr, " S:%d C:%d D:%d I:%d W:%d P:%d\n", god->stats.Str, god->stats.Con, god->stats.Dex, god->stats.Int, god->stats.Wis, god->stats.Pow);
173  fprintf(stderr, " lvl:%d speed:%4.2f\n", god->level, god->speed);
174  fprintf(stderr, " wc:%d ac:%d hp:%d dam:%d\n", god->stats.wc, god->stats.ac, god->stats.hp, god->stats.dam);
175  fprintf(stderr, " enemy: %s\n", god->title ? god->title : "NONE");
176  if (god->other_arch) {
177  object *serv = &god->other_arch->clone;
178  fprintf(stderr, " servant stats: (%s)\n", god->other_arch->name);
179  fprintf(stderr, " S:%d C:%d D:%d I:%d W:%d P:%d\n", serv->stats.Str, serv->stats.Con, serv->stats.Dex, serv->stats.Int, serv->stats.Wis, serv->stats.Pow);
180  fprintf(stderr, " lvl:%d speed:%4.2f\n", serv->level, serv->speed);
181  fprintf(stderr, " wc:%d ac:%d hp:%d dam:%d\n", serv->stats.wc, serv->stats.ac, serv->stats.hp, serv->stats.dam);
182  } else
183  fprintf(stderr, " servant: NONE\n");
184  fprintf(stderr, " aligned_race(s): %s\n", god->race);
185  fprintf(stderr, " enemy_race(s): %s\n", (god->slaying ? god->slaying : "none"));
186  describe_resistance(god, 1, tmpbuf, HUGE_BUF);
187  fprintf(stderr, "%s", tmpbuf);
188  snprintf(tmpbuf, sizeof(tmpbuf), " attacktype:");
189  if ((tmpvar = god->attacktype)) {
190  strcat(tmpbuf, "\n ");
191  DESCRIBE_ABILITY(tmpbuf, tmpvar, "Attacks");
192  }
193  strcat(tmpbuf, "\n aura:");
194 
195  strcat(tmpbuf, "\n paths:");
196  if ((tmpvar = god->path_attuned)) {
197  strcat(tmpbuf, "\n ");
198  DESCRIBE_PATH(tmpbuf, tmpvar, "Attuned");
199  }
200  if ((tmpvar = god->path_repelled)) {
201  strcat(tmpbuf, "\n ");
202  DESCRIBE_PATH(tmpbuf, tmpvar, "Repelled");
203  }
204  if ((tmpvar = god->path_denied)) {
205  strcat(tmpbuf, "\n ");
206  DESCRIBE_PATH(tmpbuf, tmpvar, "Denied");
207  }
208  fprintf(stderr, "%s\n", tmpbuf);
209  fprintf(stderr, " Desc: %s", god->msg ? god->msg : "---\n");
210  fprintf(stderr, " Priest gifts/limitations: ");
211  if (!QUERY_FLAG(god, FLAG_USE_WEAPON)) { gifts = 1; fprintf(stderr, "\n weapon use is forbidden"); }
212  if (!QUERY_FLAG(god, FLAG_USE_ARMOUR)) { gifts = 1; fprintf(stderr, "\n no armour may be worn"); }
213  if (QUERY_FLAG(god, FLAG_UNDEAD)) { gifts = 1; fprintf(stderr, "\n is undead"); }
214  if (QUERY_FLAG(god, FLAG_SEE_IN_DARK)) { gifts = 1; fprintf(stderr, "\n has infravision "); }
215  if (QUERY_FLAG(god, FLAG_XRAYS)) { gifts = 1; fprintf(stderr, "\n has X-ray vision"); }
216  if (QUERY_FLAG(god, FLAG_REFL_MISSILE)) { gifts = 1; fprintf(stderr, "\n reflect missiles"); }
217  if (QUERY_FLAG(god, FLAG_REFL_SPELL)) { gifts = 1; fprintf(stderr, "\n reflect spells"); }
218  if (QUERY_FLAG(god, FLAG_STEALTH)) { gifts = 1; fprintf(stderr, "\n is stealthy"); }
219  if (QUERY_FLAG(god, FLAG_MAKE_INVIS)) { gifts = 1; fprintf(stderr, "\n is (permanently) invisible"); }
220  if (QUERY_FLAG(god, FLAG_BLIND)) { gifts = 1; fprintf(stderr, "\n is blind"); }
221  if (god->last_heal) { gifts = 1; fprintf(stderr, "\n hp regenerate at %d", god->last_heal); }
222  if (god->last_sp) { gifts = 1; fprintf(stderr, "\n sp regenerate at %d", god->last_sp); }
223  if (god->last_eat) { gifts = 1; fprintf(stderr, "\n digestion is %s (%d)", god->last_eat < 0 ? "slowed" : "faster", god->last_eat); }
224  if (god->last_grace) { gifts = 1; fprintf(stderr, "\n grace regenerates at %d", god->last_grace); }
225  if (god->stats.luck) { gifts = 1; fprintf(stderr, "\n luck is %d", god->stats.luck); }
226  if (!gifts) fprintf(stderr, "NONE");
227  fprintf(stderr, "\n\n");
228  }
229 }
sint8 Int
Definition: living.h:78
#define FLAG_SEE_IN_DARK
Definition: define.h:634
sint8 ac
Definition: living.h:79
#define OUT_OF_MEMORY
Definition: define.h:94
const char * race
Definition: object.h:171
#define DESCRIBE_PATH(retbuf, variable, name)
Definition: define.h:971
#define FLAG_USE_ARMOUR
Definition: define.h:592
struct archt * arch
Definition: god.h:14
sint32 last_heal
Definition: object.h:208
void free_string(sstring str)
Definition: shstr.c:272
#define HUGE_BUF
Definition: define.h:83
object clone
Definition: object.h:326
const char * slaying
Definition: object.h:172
sint32 last_sp
Definition: object.h:209
#define FLAG_STEALTH
Definition: define.h:609
Definition: god.h:12
#define FLAG_USE_WEAPON
Definition: define.h:593
void dump_gods(void)
Definition: holy.c:161
const char * name
Definition: god.h:13
uint32 path_attuned
Definition: object.h:194
uint32 path_repelled
Definition: object.h:195
struct archt * other_arch
Definition: object.h:264
Definition: object.h:321
sint8 Con
Definition: living.h:78
sint16 hp
Definition: living.h:81
#define FLAG_UNDEAD
Definition: define.h:566
const char * title
Definition: object.h:170
void describe_resistance(const object *op, int newline, char *buf, size_t size)
Definition: item.c:399
uint32 path_denied
Definition: object.h:196
#define FLAG_REFL_SPELL
Definition: define.h:571
#define DESCRIBE_ABILITY(retbuf, variable, name)
Definition: define.h:956
sint8 Wis
Definition: living.h:78
sint16 dam
Definition: living.h:87
godlink * get_rand_god(void)
Definition: holy.c:111
const char * name
Definition: object.h:167
void fatal(int err)
Definition: glue.c:60
sint16 last_grace
Definition: object.h:210
const object * pntr_to_god_obj(godlink *godlnk)
Definition: holy.c:133
#define GOD
Definition: define.h:172
#define FLAG_XRAYS
Definition: define.h:597
EXTERN godlink * first_god
Definition: global.h:197
sint8 luck
Definition: living.h:80
float speed
Definition: object.h:181
#define QUERY_FLAG(xyz, p)
Definition: define.h:514
static void add_god_to_list(archetype *god_arch)
Definition: holy.c:80
struct glnk * next
Definition: god.h:16
sint32 last_eat
Definition: object.h:207
sint8 wc
Definition: living.h:79
sint8 Str
Definition: living.h:78
int snprintf(char *dest, int max, const char *format,...)
Definition: porting.c:498
uint32 attacktype
Definition: object.h:193
static godlink * init_godslist(void)
Definition: holy.c:47
#define FLAG_BLIND
Definition: define.h:633
living stats
Definition: object.h:219
sint8 Dex
Definition: living.h:78
struct archt * next
Definition: object.h:323
void init_gods(void)
Definition: holy.c:63
const char * msg
Definition: object.h:175
#define FLAG_MAKE_INVIS
Definition: define.h:625
sstring add_string(const char *str)
Definition: shstr.c:116
sint8 Pow
Definition: living.h:78
void LOG(LogLevel logLevel, const char *format,...)
Definition: logger.c:63
void free_all_god(void)
Definition: holy.c:142
#define FLAG_REFL_MISSILE
Definition: define.h:569
sint16 level
Definition: object.h:202
int id
Definition: god.h:15
EXTERN archetype * first_archetype
Definition: global.h:195
const char * name
Definition: object.h:322
uint8 type
Definition: object.h:189