summaryrefslogtreecommitdiff
path: root/src/gods.cc
blob: 7da62d7a93b376bcbba37134ec95d7203e33ca8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
 * Copyright (c) 2002 DarkGod
 *
 * This software may be copied and distributed for educational, research, and
 * not for profit purposes provided that this copyright and statement are
 * included in all such copies.
 */
#include "gods.hpp"

#include "player_type.hpp"
#include "skills.hpp"
#include "skill_type.hpp"
#include "stats.hpp"
#include "util.hpp"
#include "util.h"
#include "variable.h"
#include "variable.hpp"
#include "xtra2.hpp"

#include <cassert>

/*
 * Add amt piety is god is god
 */
void inc_piety(int god, s32b amt)
{
	s32b old = p_ptr->grace;

	if ((god == GOD_ALL) || (god == p_ptr->pgod))
	{
		set_grace(p_ptr->grace + amt);
	
		if(amt > 0 && p_ptr->grace <= old)
			set_grace(300000);

		if(amt < 0 && p_ptr->grace >= old)
			set_grace(-300000);
	}
}

/*
 * Renounce to religion
 */
void abandon_god(int god)
{
	if ((god == GOD_ALL) || (god == p_ptr->pgod))
	{
		p_ptr->pgod = GOD_NONE;
		set_grace(0);
	}
}

/*
 * Check if god may be followed by player
 */
static bool_ may_follow_god(int god)
{
	if (god == GOD_MELKOR)
	{
		int i;

		/* Check if player has wielded The One Ring */
		for (i = INVEN_WIELD; i < INVEN_TOTAL; i++)
		{
			if (p_ptr->inventory[i].name1 == ART_POWER)
			{
				msg_print("The One Ring has corrupted "
					  "you, and you are rejected.");
				return FALSE;
			}
		}
	}
	/* Default is to allow */
	return TRUE;
}

/*
 * Get a religion
 */
void follow_god(int god, bool_ silent)
{
	/* Poor unbelievers, i'm so mean ... BOUHAHAHA */
	if (get_skill(SKILL_ANTIMAGIC))
	{
		msg_print("Don't be silly; you don't believe in gods.");
		return;
	}

	/* Are we allowed ? */
	if (!may_follow_god(god))
		return;

	if (p_ptr->pgod == GOD_NONE)
	{
		p_ptr->pgod = god;

		/* Melkor offer Udun magic */
		if (p_ptr->pgod == GOD_MELKOR)
		{
			s_info[SKILL_UDUN].hidden = false;
			if (!silent)
			{
				msg_print("You feel the dark powers of Melkor in you.  You can now use the Udun skill.");
			}
		}
	}
}

/*
 * Show religious info.
 */
bool_ show_god_info()
{
	int pgod = p_ptr->pgod;

	deity_type *d_ptr;

	if (pgod < 0)
	{
		msg_print("You don't worship anyone.");
		msg_print(NULL);
		return FALSE;
	}
	else
	{
		int i;

		d_ptr = &deity_info[pgod];

		msg_print(NULL);

		character_icky = TRUE;
		Term_save();

		text_out(format("You worship %s. ", d_ptr->name));
		for (i = 0; (i < 10) && (strcmp(d_ptr->desc[i], "")); i++)
			text_out(d_ptr->desc[i]);
		text_out("\n");

		inkey();

		Term_load();
		character_icky = FALSE;
	}

	return TRUE;
}

/*
 * Rescale the wisdom value to a 0 <-> max range
 */
int wisdom_scale(int max)
{
	int i = p_ptr->stat_ind[A_WIS];

	return (i * max) / 37;
}

/*
 * Get deity info for a given god index.
 * Returns NULL for the "atheist" god.
 */
deity_type *god_at(byte god_idx)
{
	assert(god_idx < MAX_GODS);

	if (god_idx == 0)
	{
		return NULL;
	}

	return &deity_info[god_idx];
}

/*
 * Check if god is enabled for the current module
 */
bool_ god_enabled(struct deity_type *deity)
{
	int i;

	for (i = 0; deity->modules[i] != -1; i++)
	{
		if (deity->modules[i] == game_module_idx)
		{
			return TRUE;
		}
	}
	/* Not enabled */
	return FALSE;
}

/* Find a god by name */
int find_god(cptr name)
{
	int i;

	for (i = 0; i < MAX_GODS; i++)
	{
		/* The name matches and god is "enabled" for the
		   current module. */
		if (god_enabled(&deity_info[i]) &&
		    streq(deity_info[i].name, name))
		{
			return (i);
		}
	}
	return -1;
}

bool praying_to(int god)
{
	return (p_ptr->pgod == god) && p_ptr->praying;
}