File: espells.c

package info (click to toggle)
spellcast 1.0-21
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k, jessie, jessie-kfreebsd, lenny, squeeze, wheezy
  • size: 768 kB
  • ctags: 834
  • sloc: ansic: 7,660; makefile: 128; sh: 11
file content (166 lines) | stat: -rw-r--r-- 6,618 bytes parent folder | download | duplicates (3)
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
#include <strings.h>

#include "handwave.h"
#include "internal.h"

#include <libintl.h>
#define _(String) gettext (String)
#define gettext_noop(String) (String)

/* the following are purely for readability */
#define P Gesture_PALM
#define D Gesture_DIGIT
#define F Gesture_FINGERS
#define W Gesture_WAVE
#define C Gesture_CLAPHALF
#define S Gesture_SNAP
#define P2 (Gesture_PALM | Gesture_DOUBLE)
#define D2 (Gesture_DIGIT | Gesture_DOUBLE)
#define F2 (Gesture_FINGERS | Gesture_DOUBLE)
#define W2 (Gesture_WAVE | Gesture_DOUBLE)
#define C2 (Gesture_CLAPHALF | Gesture_DOUBLE)
#define S2 (Gesture_SNAP | Gesture_DOUBLE)

/* Have to put this into a initialization during startup of the program */
struct spelldef spelllist[NUMSPELLS] = {
    {4, {C2, D,  P,  W},	0, 1, gettext_noop("Dispel Magic")},
    {5, {C2, S,  W,  W,  S},	0, 1, gettext_noop("Summon Elemental")},
    {2, {C2, W2},		0, 1, gettext_noop("Magic Mirror")},
    {5, {D,  F,  F,  D,  D},	0, 0, gettext_noop("Lightning Bolt")},
    {4, {D,  F,  P,  W},	0, 1, gettext_noop("Cure Heavy Wounds")},
    {3, {D,  F,  W},		0, 1, gettext_noop("Cure Light Wounds")},
    {3, {D,  P,  P},		1, 0, gettext_noop("Amnesia")},
    {3, {D,  S,  F},		1, 0, gettext_noop("Confusion")},
    {6, {D,  S,  F,  F,  F,  C2},0, 0, gettext_noop("Disease")},
    {5, {D,  W,  F,  F,  D2},	1, 0, gettext_noop("Blindness")},
    {6, {D,  W,  S,  S,  S,  P},0, 1, gettext_noop("Delayed Effect")},
    {6, {D,  W,  W,  F,  W,  C2},0, 1, gettext_noop("Raise Dead")},
    {6, {D,  W,  W,  F,  W,  D},0, 0, gettext_noop("Poison")},
    {3, {F,  F,  F},		1, 0, gettext_noop("Paralysis")},
    {5, {F,  P,  S,  F,  W},	0, 1, gettext_noop("Summon Troll")},
    {5, {F,  S,  S,  D,  D},	0, 0, gettext_noop("Fireball")},
    {1, {P},			0, 1, gettext_noop("Shield")},
    {1, {P2},			0, 0, gettext_noop("SURRENDER")},
    {4, {P,  D,  W,  P},	0, 1, gettext_noop("Remove Enchantment")},
    {4, {P,  P,  W2, S2},	1, 1, gettext_noop("Invisibility")},
    {4, {P,  S,  D,  D},	1, 0, gettext_noop("Charm Monster")},
    {4, {P,  S,  D,  F},	1, 0, gettext_noop("Charm Person")},
    {4, {P,  S,  F,  W},	0, 1, gettext_noop("Summon Ogre")},
    {8, {P,  W,  P,  F,  S,  S,  S,  D},0,0, gettext_noop("Finger of Death")},
    {6, {P,  W,  P,  W,  W,  C2},1, 1, gettext_noop("Haste")},
    {2, {S,  D},		0, 0, gettext_noop("Missile")},
    {3, {S,  F,  W},		0, 1, gettext_noop("Summon Goblin")},
    {3, {S,  P,  F},		0, 0, gettext_noop("Anti-Spell")},
    {7, {S,  P,  F,  P,  S,  D,  W},0,1, gettext_noop("Permanency")},
    {4, {S,  P,  P,  C2},	0, 1, gettext_noop("Time Stop")},
    {4, {S,  S,  F,  P},	1, 1, gettext_noop("Resist Cold")},
    {3, {S,  W,  D},		1, 0, gettext_noop("Fear")},
    {4, {S,  W,  W,  C2},	0, 0, gettext_noop("Fire Storm")},
    {4, {W,  D,  D,  C2},	0, 0, gettext_noop("Lightning Bolt")},
    {3, {W,  F,  P},		0, 0, gettext_noop("Cause Light Wounds")},
    {6, {W,  F,  P,  S,  F,  W},0, 1, gettext_noop("Summon Giant")},
    {4, {W,  P,  F,  D},	0, 0, gettext_noop("Cause Heavy Wounds")},
    {3, {W,  P,  P},		0, 0, gettext_noop("Counter-Spell")},
    {4, {W,  S,  S,  C2},	0, 0, gettext_noop("Ice Storm")},
    {4, {W,  W,  F,  P},	1, 1, gettext_noop("Resist Heat")},
    {3, {W,  W,  P},		1, 1, gettext_noop("Protection From Evil")},
    {3, {W,  W,  S},		0, 0, gettext_noop("Counter-Spell")},
    {1,	{Gesture_KNIFE},	0, 0, gettext_noop("stab")}
};

#undef P
#undef D
#undef F
#undef W
#undef C
#undef S
#undef P2
#undef D2
#undef F2
#undef W2
#undef C2
#undef S2

int reverse_sort_list[NUMSPELLS] = {
    SP__LIGHTNING_BOLT2, SP__DISEASE, SP__TIME_STOP, SP__ICE_STORM, SP__RAISE_DEAD,
    SP__HASTE, SP__FIRE_STORM, SP__LIGHTNING_BOLT, SP__CHARM_MONSTER, SP__FIREBALL,
    SP__BLINDNESS, SP__CAUSE_HEAVY_WOUNDS, SP__MISSILE, SP__FINGER_OF_DEATH,
    SP__POISON, SP__FEAR, SP__CHARM_PERSON, SP__PARALYSIS, SP__ANTI_SPELL,
    SP__CONFUSION, SP__SHIELD, SP__SURRENDER, SP__RESIST_COLD, SP__CAUSE_LIGHT_WOUNDS,
    SP__RESIST_HEAT, SP__AMNESIA, SP__COUNTER_SPELL, SP__DELAYED_EFFECT,
    SP__REMOVE_ENCHANTMENT, SP__PROTECTION_FROM_EVIL, SP__INVISIBILITY,
    SP__COUNTER_SPELL2, SP__SUMMON_ELEMENTAL, SP__MAGIC_MIRROR, SP__PERMANENCY,
    SP__CURE_LIGHT_WOUNDS, SP__SUMMON_GOBLIN, SP__SUMMON_OGRE, SP__SUMMON_TROLL,
    SP__SUMMON_GIANT, SP__DISPEL_MAGIC, SP__CURE_HEAVY_WOUNDS, SP__STAB
};
int alphabet_sort_list[NUMSPELLS] = {
    SP__AMNESIA, SP__ANTI_SPELL, SP__BLINDNESS, SP__CAUSE_HEAVY_WOUNDS,
    SP__CAUSE_LIGHT_WOUNDS, SP__CHARM_MONSTER, SP__CHARM_PERSON, SP__CONFUSION,
    SP__COUNTER_SPELL, SP__COUNTER_SPELL2, SP__CURE_HEAVY_WOUNDS,
    SP__CURE_LIGHT_WOUNDS, SP__DELAYED_EFFECT, SP__DISEASE, SP__DISPEL_MAGIC,
    SP__FEAR, SP__FINGER_OF_DEATH, SP__FIRE_STORM, SP__FIREBALL, SP__HASTE,
    SP__ICE_STORM, SP__INVISIBILITY, SP__LIGHTNING_BOLT, SP__LIGHTNING_BOLT2,
    SP__MAGIC_MIRROR, SP__MISSILE, SP__PARALYSIS, SP__PERMANENCY, SP__POISON,
    SP__PROTECTION_FROM_EVIL, SP__RAISE_DEAD, SP__REMOVE_ENCHANTMENT,
    SP__RESIST_COLD, SP__RESIST_HEAT, SP__SHIELD, SP__SUMMON_ELEMENTAL,
    SP__SUMMON_GIANT, SP__SUMMON_GOBLIN, SP__SUMMON_OGRE, SP__SUMMON_TROLL,
    SP__SURRENDER, SP__TIME_STOP, SP__STAB
};

static int check_one_spell(numgests, glist, mainhand, spel)
int numgests;
struct wizgesture *glist;
int mainhand;
struct spelldef *spel;
{
    int otherhand = (1-mainhand);
    int jx, result, pos;

    for (jx=spel->length-1; jx>=0; jx--) {
	pos = numgests - (spel->length - jx);
	if (pos<0) {
	    /* fell off beginning of gesture list */
	    return 0; 
	}
	if (spel->gests[jx] & Gesture_DOUBLE) {
	    result = spel->gests[jx] & (~Gesture_DOUBLE);
	    if (!(glist[pos].did[mainhand] == result
		  && glist[pos].did[otherhand] == result)) {
		/* failed to do two-handed gesture */
		return 0; 
	    }
	}
	else {
	    if (!(glist[pos].did[mainhand] == spel->gests[jx])) {
		/* failed to do one-handed gesture */
		 return 0; 
	    }
	}
    }

    return 1;
}

/* writes results into found[] (OR of MASK_LEFT and MASK_RIGHT, or else MASK_BOTH) */
void find_castspells(found, numgests, glist)
int *found; /* pointer to array[NUMSPELLS] */
int numgests;
struct wizgesture *glist;
{
    int ix, result;
    struct spelldef *spel;

    for (ix=0; ix<NUMSPELLS; ix++) {
	spel = &(spelllist[ix]);
	result = 0;
	if (check_one_spell(numgests, glist, 0, spel))
	    result |= MASK_LEFT;
	if (check_one_spell(numgests, glist, 1, spel))
	    result |= MASK_RIGHT;
	if (result && (spel->gests[spel->length-1] & Gesture_DOUBLE)) {
	    /* spell was completed with a double-handed gesture */
	    result = MASK_TWOHAND;
	}
	found[ix] = result;
    }
}