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

# User Rev Content
1 root 1.5
2 elmex 1.1 /* Started file Sept 1996 - initialization of gods in form of a
3     * linked list -b.t.
4 root 1.5 */
5 elmex 1.1
6     #include <global.h>
7     #include <living.h>
8     #include <spells.h>
9    
10 root 1.4 //TODO: make a constructor
11 root 1.5 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 root 1.4
22 root 1.5 return gl;
23 elmex 1.1 }
24 root 1.5
25 elmex 1.1 /* init_gods() - this takes a look at all of the archetypes to find
26     * the objects which correspond to the GODS (type GOD) */
27 root 1.5
28     void
29     init_gods (void)
30     {
31 root 1.8 LOG (llevDebug, "Initialising gods...\n");
32 root 1.5
33 root 1.8 for (archetype *at = first_archetype; at; at = at->next)
34 root 1.5 if (at->clone.type == GOD)
35     add_god_to_list (at);
36    
37     LOG (llevDebug, "done.\n");
38 elmex 1.1 }
39 root 1.5
40 elmex 1.1 /* add_god_to_list()- called only from init_gods */
41 root 1.5 void
42     add_god_to_list (archetype *god_arch)
43     {
44 elmex 1.1 godlink *god;
45 root 1.5
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 elmex 1.1 god->arch = god_arch;
55 root 1.4 god->name = god_arch->clone.name;
56 root 1.5 if (!first_god)
57 elmex 1.1 god->id = 1;
58 root 1.5 else
59     {
60     god->id = first_god->id + 1;
61     god->next = first_god;
62     }
63 elmex 1.1 first_god = god;
64 root 1.5
65     #ifdef DEBUG_GODS
66     LOG (llevDebug, "Adding god %s (%d) to list\n", &god->name, god->id);
67 elmex 1.1 #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 root 1.5
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 elmex 1.1 int i;
107 root 1.5
108     if (god)
109 root 1.7 for (i = rndm (god->id) + 1; god; god = god->next)
110 root 1.5 if (god->id == i)
111     break;
112    
113     if (!god)
114     LOG (llevError, "get_rand_god(): can't find a random god!\n");
115 root 1.7
116 elmex 1.1 return god;
117     }
118 root 1.5
119 elmex 1.1 /* 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 root 1.5 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 elmex 1.1 return god;
131     }
132    
133 root 1.5 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 elmex 1.1 }
144     }