00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00034 #include <stdlib.h>
00035 #include <global.h>
00036 #include <living.h>
00037 #include <spells.h>
00038
00039 static void add_god_to_list(archetype *god_arch);
00040
00047 static godlink *init_godslist(void) {
00048 godlink *gl = (godlink *)malloc(sizeof(godlink));
00049 if (gl == NULL)
00050 fatal(OUT_OF_MEMORY);
00051 gl->name = NULL;
00052 gl->arch = NULL;
00053 gl->id = 0;
00054 gl->next = NULL;
00055
00056 return gl;
00057 }
00058
00063 void init_gods(void) {
00064 archetype *at = NULL;
00065
00066 LOG(llevDebug, "Initializing gods...\n");
00067 for (at = first_archetype; at != NULL; at = at->next)
00068 if (at->clone.type == GOD)
00069 add_god_to_list(at);
00070
00071 LOG(llevDebug, "done.\n");
00072 }
00073
00080 static void add_god_to_list(archetype *god_arch) {
00081 godlink *god;
00082
00083 if (!god_arch) {
00084 LOG(llevError, "ERROR: Tried to add null god to list!\n");
00085 return;
00086 }
00087
00088 god = init_godslist();
00089
00090 god->arch = god_arch;
00091 god->name = add_string(god_arch->clone.name);
00092 if (!first_god)
00093 god->id = 1;
00094 else {
00095 god->id = first_god->id+1;
00096 god->next = first_god;
00097 }
00098 first_god = god;
00099
00100 #ifdef DEBUG_GODS
00101 LOG(llevDebug, "Adding god %s (%d) to list\n", god->name, god->id);
00102 #endif
00103 }
00104
00111 godlink *get_rand_god(void) {
00112 godlink *god = first_god;
00113 int i;
00114
00115 if (god)
00116 for (i = RANDOM()%(god->id)+1; god; god = god->next)
00117 if (god->id == i)
00118 break;
00119
00120 if (!god)
00121 LOG(llevError, "get_rand_god(): can't find a random god!\n");
00122 return god;
00123 }
00124
00133 const object *pntr_to_god_obj(godlink *godlnk) {
00134 if (godlnk && godlnk->arch)
00135 return &godlnk->arch->clone;
00136 return NULL;
00137 }
00138
00142 void free_all_god(void) {
00143 godlink *god, *godnext;
00144
00145 LOG(llevDebug, "Freeing god information\n");
00146 for (god = first_god; god; god = godnext) {
00147 godnext = god->next;
00148 if (god->name)
00149 free_string(god->name);
00150 free(god);
00151 }
00152 first_god = NULL;
00153 }
00154
00161 void dump_gods(void) {
00162 godlink *glist;
00163
00164 fprintf(stderr, "\n");
00165 for (glist = first_god; glist; glist = glist->next) {
00166 const object *god = pntr_to_god_obj(glist);
00167 char tmpbuf[HUGE_BUF];
00168 int tmpvar, gifts = 0;
00169
00170 fprintf(stderr, "GOD: %s\n", god->name);
00171 fprintf(stderr, " avatar stats:\n");
00172 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);
00173 fprintf(stderr, " lvl:%d speed:%4.2f\n", god->level, god->speed);
00174 fprintf(stderr, " wc:%d ac:%d hp:%d dam:%d\n", god->stats.wc, god->stats.ac, god->stats.hp, god->stats.dam);
00175 fprintf(stderr, " enemy: %s\n", god->title ? god->title : "NONE");
00176 if (god->other_arch) {
00177 object *serv = &god->other_arch->clone;
00178 fprintf(stderr, " servant stats: (%s)\n", god->other_arch->name);
00179 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);
00180 fprintf(stderr, " lvl:%d speed:%4.2f\n", serv->level, serv->speed);
00181 fprintf(stderr, " wc:%d ac:%d hp:%d dam:%d\n", serv->stats.wc, serv->stats.ac, serv->stats.hp, serv->stats.dam);
00182 } else
00183 fprintf(stderr, " servant: NONE\n");
00184 fprintf(stderr, " aligned_race(s): %s\n", god->race);
00185 fprintf(stderr, " enemy_race(s): %s\n", (god->slaying ? god->slaying : "none"));
00186 describe_resistance(god, 1, tmpbuf, HUGE_BUF);
00187 fprintf(stderr, "%s", tmpbuf);
00188 snprintf(tmpbuf, sizeof(tmpbuf), " attacktype:");
00189 if ((tmpvar = god->attacktype)) {
00190 strcat(tmpbuf, "\n ");
00191 DESCRIBE_ABILITY(tmpbuf, tmpvar, "Attacks");
00192 }
00193 strcat(tmpbuf, "\n aura:");
00194
00195 strcat(tmpbuf, "\n paths:");
00196 if ((tmpvar = god->path_attuned)) {
00197 strcat(tmpbuf, "\n ");
00198 DESCRIBE_PATH(tmpbuf, tmpvar, "Attuned");
00199 }
00200 if ((tmpvar = god->path_repelled)) {
00201 strcat(tmpbuf, "\n ");
00202 DESCRIBE_PATH(tmpbuf, tmpvar, "Repelled");
00203 }
00204 if ((tmpvar = god->path_denied)) {
00205 strcat(tmpbuf, "\n ");
00206 DESCRIBE_PATH(tmpbuf, tmpvar, "Denied");
00207 }
00208 fprintf(stderr, "%s\n", tmpbuf);
00209 fprintf(stderr, " Desc: %s", god->msg ? god->msg : "---\n");
00210 fprintf(stderr, " Priest gifts/limitations: ");
00211 if (!QUERY_FLAG(god, FLAG_USE_WEAPON)) { gifts = 1; fprintf(stderr, "\n weapon use is forbidden"); }
00212 if (!QUERY_FLAG(god, FLAG_USE_ARMOUR)) { gifts = 1; fprintf(stderr, "\n no armour may be worn"); }
00213 if (QUERY_FLAG(god, FLAG_UNDEAD)) { gifts = 1; fprintf(stderr, "\n is undead"); }
00214 if (QUERY_FLAG(god, FLAG_SEE_IN_DARK)) { gifts = 1; fprintf(stderr, "\n has infravision "); }
00215 if (QUERY_FLAG(god, FLAG_XRAYS)) { gifts = 1; fprintf(stderr, "\n has X-ray vision"); }
00216 if (QUERY_FLAG(god, FLAG_REFL_MISSILE)) { gifts = 1; fprintf(stderr, "\n reflect missiles"); }
00217 if (QUERY_FLAG(god, FLAG_REFL_SPELL)) { gifts = 1; fprintf(stderr, "\n reflect spells"); }
00218 if (QUERY_FLAG(god, FLAG_STEALTH)) { gifts = 1; fprintf(stderr, "\n is stealthy"); }
00219 if (QUERY_FLAG(god, FLAG_MAKE_INVIS)) { gifts = 1; fprintf(stderr, "\n is (permanently) invisible"); }
00220 if (QUERY_FLAG(god, FLAG_BLIND)) { gifts = 1; fprintf(stderr, "\n is blind"); }
00221 if (god->last_heal) { gifts = 1; fprintf(stderr, "\n hp regenerate at %d", god->last_heal); }
00222 if (god->last_sp) { gifts = 1; fprintf(stderr, "\n sp regenerate at %d", god->last_sp); }
00223 if (god->last_eat) { gifts = 1; fprintf(stderr, "\n digestion is %s (%d)", god->last_eat < 0 ? "slowed" : "faster", god->last_eat); }
00224 if (god->last_grace) { gifts = 1; fprintf(stderr, "\n grace regenerates at %d", god->last_grace); }
00225 if (god->stats.luck) { gifts = 1; fprintf(stderr, "\n luck is %d", god->stats.luck); }
00226 if (!gifts) fprintf(stderr, "NONE");
00227 fprintf(stderr, "\n\n");
00228 }
00229 }