1 |
|
2 |
/* Started file Sept 1996 - initialization of gods in form of a |
3 |
* linked list -b.t. |
4 |
*/ |
5 |
|
6 |
#include <global.h> |
7 |
#include <living.h> |
8 |
#include <spells.h> |
9 |
|
10 |
//TODO: make a constructor |
11 |
static godlink * |
12 |
init_godslist (void) |
13 |
{ |
14 |
godlink *gl = new godlink; |
15 |
|
16 |
// name=NULL; /* how to describe the god to the player */ |
17 |
// arch=NULL; /* pointer to the archetype of this god */ |
18 |
// id=0; /* id of the god */ |
19 |
// pantheon=NULL; /* the group to which the god belongs (not implemented) */ |
20 |
// next=NULL; /* next god in this linked list */ |
21 |
|
22 |
return gl; |
23 |
} |
24 |
|
25 |
/* init_gods() - this takes a look at all of the archetypes to find |
26 |
* the objects which correspond to the GODS (type GOD) */ |
27 |
|
28 |
void |
29 |
init_gods (void) |
30 |
{ |
31 |
archetype *at = NULL; |
32 |
|
33 |
LOG (llevDebug, "Initializing gods..."); |
34 |
for (at = first_archetype; at != NULL; at = at->next) |
35 |
if (at->clone.type == GOD) |
36 |
add_god_to_list (at); |
37 |
|
38 |
LOG (llevDebug, "done.\n"); |
39 |
} |
40 |
|
41 |
/* add_god_to_list()- called only from init_gods */ |
42 |
void |
43 |
add_god_to_list (archetype *god_arch) |
44 |
{ |
45 |
godlink *god; |
46 |
|
47 |
if (!god_arch) |
48 |
{ |
49 |
LOG (llevError, "ERROR: Tried to add null god to list!\n"); |
50 |
return; |
51 |
} |
52 |
|
53 |
god = init_godslist (); |
54 |
|
55 |
god->arch = god_arch; |
56 |
god->name = god_arch->clone.name; |
57 |
if (!first_god) |
58 |
god->id = 1; |
59 |
else |
60 |
{ |
61 |
god->id = first_god->id + 1; |
62 |
god->next = first_god; |
63 |
} |
64 |
first_god = god; |
65 |
|
66 |
#ifdef DEBUG_GODS |
67 |
LOG (llevDebug, "Adding god %s (%d) to list\n", &god->name, god->id); |
68 |
#endif |
69 |
} |
70 |
|
71 |
/* baptize_altar() - (cosmetically) change the name to that of the |
72 |
* god in question, then set the title for later use. -b.t. |
73 |
*/ |
74 |
|
75 |
int |
76 |
baptize_altar (object *op) |
77 |
{ |
78 |
char buf[MAX_BUF]; |
79 |
|
80 |
/* if the title field is pre-set, then that altar is |
81 |
* already dedicated. */ |
82 |
if (!op->title) |
83 |
{ |
84 |
godlink *god = get_rand_god (); |
85 |
|
86 |
if (!god || !god->name) |
87 |
{ |
88 |
LOG (llevError, "baptise_altar(): bizarre nameless god!\n"); |
89 |
return 0; |
90 |
} |
91 |
/* if the object name hasnt' been changed, we tack on the gods name */ |
92 |
if (!strcmp (op->name, op->arch->clone.name)) |
93 |
{ |
94 |
sprintf (buf, "%s of %s", &op->name, &god->name); |
95 |
op->name = buf; |
96 |
} |
97 |
op->title = god->name; |
98 |
return 1; |
99 |
} |
100 |
return 0; |
101 |
} |
102 |
|
103 |
godlink * |
104 |
get_rand_god (void) |
105 |
{ |
106 |
godlink *god = first_god; |
107 |
int i; |
108 |
|
109 |
if (god) |
110 |
for (i = RANDOM () % (god->id) + 1; god; god = god->next) |
111 |
if (god->id == i) |
112 |
break; |
113 |
|
114 |
if (!god) |
115 |
LOG (llevError, "get_rand_god(): can't find a random god!\n"); |
116 |
return god; |
117 |
} |
118 |
|
119 |
/* pntr_to_god_obj() - returns a pointer to the object |
120 |
* We need to be VERY carefull about using this, as we |
121 |
* are returning a pointer to the CLONE object. -b.t. |
122 |
*/ |
123 |
object * |
124 |
pntr_to_god_obj (godlink *godlnk) |
125 |
{ |
126 |
object *god = NULL; |
127 |
|
128 |
if (godlnk && godlnk->arch) |
129 |
god = &godlnk->arch->clone; |
130 |
return god; |
131 |
} |
132 |
|
133 |
void |
134 |
free_all_god (void) |
135 |
{ |
136 |
godlink *god, *godnext; |
137 |
|
138 |
LOG (llevDebug, "Freeing god information\n"); |
139 |
for (god = first_god; god; god = godnext) |
140 |
{ |
141 |
godnext = god->next; |
142 |
delete god; |
143 |
} |
144 |
} |