ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/holy.C
Revision: 1.8
Committed: Mon Apr 16 06:23:39 2007 UTC (17 years, 2 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.7: +2 -3 lines
Log Message:
VERY EXPERIMENTAL

- change the way archetypes and treasurelists are being loaded:
  - referring to a nonexisting treasurelist will create an empty one
  - referring to a nonexisting archetype will create an empty one
  - archetypes/treasurelists will overwrite any existing object
    of the same name.

- net effect should be to allow reloading of archetypes and treasurelists
  at runtime at a later stage.

File Contents

# Content
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 LOG (llevDebug, "Initialising gods...\n");
32
33 for (archetype *at = first_archetype; at; at = at->next)
34 if (at->clone.type == GOD)
35 add_god_to_list (at);
36
37 LOG (llevDebug, "done.\n");
38 }
39
40 /* add_god_to_list()- called only from init_gods */
41 void
42 add_god_to_list (archetype *god_arch)
43 {
44 godlink *god;
45
46 if (!god_arch)
47 {
48 LOG (llevError, "ERROR: Tried to add null god to list!\n");
49 return;
50 }
51
52 god = init_godslist ();
53
54 god->arch = god_arch;
55 god->name = god_arch->clone.name;
56 if (!first_god)
57 god->id = 1;
58 else
59 {
60 god->id = first_god->id + 1;
61 god->next = first_god;
62 }
63 first_god = god;
64
65 #ifdef DEBUG_GODS
66 LOG (llevDebug, "Adding god %s (%d) to list\n", &god->name, god->id);
67 #endif
68 }
69
70 /* baptize_altar() - (cosmetically) change the name to that of the
71 * god in question, then set the title for later use. -b.t.
72 */
73
74 int
75 baptize_altar (object *op)
76 {
77 char buf[MAX_BUF];
78
79 /* if the title field is pre-set, then that altar is
80 * already dedicated. */
81 if (!op->title)
82 {
83 godlink *god = get_rand_god ();
84
85 if (!god || !god->name)
86 {
87 LOG (llevError, "baptise_altar(): bizarre nameless god!\n");
88 return 0;
89 }
90 /* if the object name hasnt' been changed, we tack on the gods name */
91 if (!strcmp (op->name, op->arch->clone.name))
92 {
93 sprintf (buf, "%s of %s", &op->name, &god->name);
94 op->name = buf;
95 }
96 op->title = god->name;
97 return 1;
98 }
99 return 0;
100 }
101
102 godlink *
103 get_rand_god (void)
104 {
105 godlink *god = first_god;
106 int i;
107
108 if (god)
109 for (i = rndm (god->id) + 1; god; god = god->next)
110 if (god->id == i)
111 break;
112
113 if (!god)
114 LOG (llevError, "get_rand_god(): can't find a random god!\n");
115
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 }