1 /*
2 This file is part of "Avanor, the Land of Mystery" roguelike game
3 Home page: http://www.avanor.com/
4 Copyright (C) 2000-2003 Vadim Gaidukevich
5 
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20 
21 #include "xweapon.h"
22 #include "xapi.h"
23 
24 REGISTER_CLASS(XWeapon);
25 
26 _MAIN_ITEM_STRUCT weapon_db[] =
27 {
28 {IT_CLUB,		"club",			'/',		"",	"",	"",		"1d3",  "",		"", 	ISET_WOODSTONE,		1,		10,	0,	""},
29 {IT_WARHAMMER,	"war hammer",	'/',		"",	"",	"1d2-4","1d7",  "1d4",	"", 	ISET_HARDMETAL,		12,		10,	0,	""},
30 
31 {IT_DAGGER,		"dagger",		'/',		"",	"",	"",		"1d4",  "",		"", 	ISET_WEAPON,		2,		3,	0,	""},
32 {IT_KNIFE,		"knife",		'/',		"",	"",	"1d2-2","1d3",  "",		"", 	ISET_SIMPLEWEAPON,	1,		2,	0,	""},
33 {IT_ORCISHDAGGER,"orcish dagger",'/',		"",	"",	"1d2",	"1d3",  "1d2",	"", 	ISET_STEEL,			3,		3,	0,	""},
34 {IT_LONGDAGGER,	"long dagger",	'/',		"",	"",	"1d3-1","1d4",  "1d2-1","", 	ISET_STEEL,			4,		3,	0,	""},
35 
36 {IT_SHORTSWORD,	"short sword",	'/',		"",	"",	"",		"1d5",  "",		"", 	ISET_OBSIMETAL,		6,		5,	0,	""},
37 {IT_LONGSWORD,	"long sword",	'|',		"",	"",	"",		"2d4",  "",		"", 	ISET_OBSIMETAL,		18,		10,	0,	""},
38 {IT_BROADSWORD,	"broad sword",	'|',		"",	"",	"",		"2d5",  "",		"", 	ISET_OBSIMETAL,		20,		12,	0,	""},
39 {IT_RAPIER,		"rapier",		'|',		"",	"",	"1d3-1","1d6",  "",		"", 	ISET_HARDMETAL,		7,		5,	0,	""},
40 {IT_SCIMITAR,	"scimitar",		'|',		"",	"",	"1",	"1d6",  "1d3-1","", 	ISET_HARDMETAL,		7,		6,	0,	""},
41 {IT_KATANA,		"katana",		'|',		"",	"",	"1",	"3d6",  "1d3-1","", 	ISET_HARDMETAL,		50,		1,	0,	""},
42 {IT_WAKIZASHI,	"wakizashi",	'|',		"",	"",	"1",	"2d6",  "1d3-1","", 	ISET_HARDMETAL,		45,		1,	0,	""},
43 
44 {IT_SMALLAXE,	"small axe",	'\\',		"",	"",	"",		"1d6",  "",		"", 	ISET_OBSIMETAL,		10,		6,	0,	""},
45 {IT_WARAXE,		"war axe",		'\\',		"",	"",	"1d3-1","2d3",  "",		"", 	ISET_OBSIMETAL,		15,		7,	0,	""},
46 {IT_BATTLEAXE,	"battle axe",	'\\',		"",	"",	"1d3-2","2d5",  "1d3-1","", 	ISET_HARDMETAL,		25,		12,	0,	""},
47 {IT_GREATAXE,	"great axe",	'\\',		"",	"",	"",		"3d4",  "",		"",		ISET_HARDMETAL,		30,		20,	0,	""},
48 {IT_ORCISHAXE,	"orcish axe",	'\\',		"",	"",	"1d3-1","2d4",  "",		"", 	ISET_OBSIMETAL,		10,		10,	0,	""},
49 
50 {IT_MACE,		"mace",			'\\',		"",	"",	"",		"1d6",  "",		"", 	ISET_OBSIMETAL,		10,		7,	0,	""},
51 {IT_FLAIL,		"flail",		'\\',		"",	"",	"",		"1d7",  "",		"", 	ISET_HARDMETAL,		15,		7,	0,	""},
52 
53 {IT_SHORTSPEAR,	"short spear",	'/',		"",	"",	"",		"1d5",  "",		"", 	ISET_WOODSTONE,		3,		4,	0,	""},
54 {IT_LONGSPEAR,	"long spear",	'/',		"",	"",	"",		"1d9",  "",		"", 	ISET_STEEL,			8,		6,	0,	""},
55 {IT_PITCHFORK,	"pitchfork",	'/',		"",	"",	"1d2-4","1d3",  "",		"", 	ISET_BLACKMETAL,	1,		3,	0,	""},
56 {IT_PIKE,		"pike",			'/',		"",	"",	"",		"1d10", "",		"", 	ISET_BLACKMETAL,	1,		3,	0,	""},
57 {IT_HALBERD,	"halberd",		'/',		"",	"",	"",		"1d12", "",		"", 	ISET_BLACKMETAL,	1,		3,	0,	""},
58 
59 {IT_STAFF,		"staff",		'/',		"",	"",	"1d2-2","1d10",  "1d2",		"", 	ISET_WOOD,		8,		3,	0,	""},
60 };
61 const int weapon_db_size = 26;
62 
63 _WEAPON_BIND wbind[weapon_db_size] = {
64 {IT_CLUB,			WSK_CLUB},
65 {IT_WARHAMMER,		WSK_CLUB},
66 //{IT_SCEPTER,		WSK_CLUB},
67 
68 {IT_DAGGER,			WSK_DAGGER},
69 {IT_KNIFE,			WSK_DAGGER},
70 {IT_ORCISHDAGGER,	WSK_DAGGER},
71 {IT_LONGDAGGER,		WSK_DAGGER},
72 
73 {IT_SHORTSWORD,		WSK_SWORD},
74 {IT_LONGSWORD,		WSK_SWORD},
75 {IT_BROADSWORD,		WSK_SWORD},
76 {IT_RAPIER,			WSK_SWORD},
77 {IT_SCIMITAR,		WSK_SWORD},
78 {IT_KATANA,			WSK_SWORD},
79 {IT_WAKIZASHI,		WSK_SWORD},
80 
81 {IT_SMALLAXE,		WSK_AXE},
82 {IT_WARAXE,			WSK_AXE},
83 {IT_BATTLEAXE,		WSK_AXE},
84 {IT_GREATAXE,		WSK_AXE},
85 {IT_ORCISHAXE,		WSK_AXE},
86 
87 {IT_MACE,			WSK_MACE},
88 {IT_FLAIL,			WSK_MACE},
89 
90 {IT_SHORTSPEAR,		WSK_POLEARM},
91 {IT_LONGSPEAR,		WSK_POLEARM},
92 {IT_PITCHFORK,		WSK_POLEARM},
93 {IT_PIKE,			WSK_POLEARM},
94 {IT_HALBERD,		WSK_POLEARM},
95 
96 {IT_STAFF,			WSK_STAVE},
97 };
98 
99 
100 struct WEAPON_BRAND_TYPE_NAME
101 {
102 	BRAND_TYPE brt;
103 	char * templ;
104 };
105 
106 const int weapon_brand_name_db_size = 17;
107 
108 WEAPON_BRAND_TYPE_NAME weapon_brand_name_db[weapon_brand_name_db_size]=
109 {
110 	{BR_FIRE,			"%s of Fire",			},
111 	{BR_HELLFIRE,		"%s of Hell Fire",		},
112 	{BR_COLD,			"%s of Cold"			},
113 	{BR_ULTIMATECOLD,	"%s of Ultimate Cold"	},
114 	{BR_LIGHTNING,		"%s of Lightning"		},
115 
116 	{BR_ACID,			"%s of Acid"			},
117 	{BR_POISON,			"%s of Poison"			},
118 	{BR_DEATH,			"%s of Death"			},
119 
120 	{BR_UNDEADSLAYER,	"%s of Slay Undead"		},
121 	{BR_HUMANOIDSLAYER,	"%s of Slay Humanoids"	},
122 	{BR_ANIMALSLAYER,	"%s of Slay Animals"	},
123 	{BR_DRAGONSLAYER,	"%s of Dragon Slaying"	},
124 	{BR_GIANTSLAYER,	"%s of Giant Slaying"	},
125 	{BR_ORCSLAYER,		"%s of Slay Orcs"		},
126 	{BR_TROLLSLAYER,	"%s of Slay Trolls"		},
127 	{BR_TROLLSLAYER,	"%s of Slay Trolls"		},
128 	{BR_DEMONSLAYER,	"%s of Slay Demons"		},
129 };
130 
131 
XWeapon(ITEM_TYPE _it)132 XWeapon::XWeapon(ITEM_TYPE _it)
133 {
134 	im = IM_WEAPON;
135 	BasicFill(_it, weapon_db, weapon_db_size);
136 	bp = BP_HAND;
137 	RNG = 0;
138 	BindWeapon();
139 }
140 
BindWeapon()141 int XWeapon::BindWeapon()
142 {
143 	for (int i = 0; i < weapon_db_size; i++)
144 		if (wbind[i].it == it)
145 		{
146 			wt = wbind[i].ws;
147 			return 1;
148 		}
149 	assert(0);
150 	return 0;
151 }
152 
toString(char * buf)153 void XWeapon::toString(char * buf)
154 {
155 //	GetFullName(buf);
156 
157 	char w_name[256];
158 	_ITEMPROP * prop = GetMaterial(material_index);
159 	strcpy(w_name, prop->propname);
160 	for (int i = 0; i < weapon_db_size; i++)
161 	{
162 		if (it == weapon_db[i].it)
163 		{
164 			strcat(w_name, " ");
165 			strcat(w_name, weapon_db[i].name);
166 			break;
167 		}
168 	}
169 
170 	char * brand_templ = NULL;
171 
172 	char zbuf[256] = "%s";
173 	if (brt)
174 	{
175 		int ec = vBitsCount(brt & BR_ELEMENTAL_MASK);
176 		int bc = vBitsCount(brt & BR_BLACK_MASK);
177 		int sc = vBitsCount(brt & BR_SLAYER_MASK);
178 
179 		if (ec == 1 && bc == 0 && sc == 0)
180 		{
181 			brand_templ = GetTemplate(brt & BR_ELEMENTAL_MASK);
182 		} else
183 		if (ec == 0 && bc == 0 && sc == 1)
184 		{
185 			brand_templ = GetTemplate(brt & BR_SLAYER_MASK);
186 		} else
187 		if (ec >= 1 && bc == 0 && sc == 1)
188 		{
189 			strcpy(zbuf, "Elemental ");
190 			strcat(zbuf, GetTemplate(brt & BR_SLAYER_MASK));
191 			brand_templ = zbuf;
192 		} else
193 		if (ec >= 1 && bc == 0 && sc > 1)
194 		{
195 			brand_templ = "Elemental %s of Slaying";
196 		} else
197 		if (ec == 0 && bc == 0 && sc > 1)
198 		{
199 			brand_templ = "%s of Slaying";
200 		} else
201 		if (ec > 1 && bc == 0 && sc == 0)
202 		{
203 			brand_templ = "Elemental %s";
204 		}
205 
206 	}
207 
208 	if (quantity == 1)
209 	{
210 		if (brand_templ)
211 			sprintf(buf, brand_templ, w_name);
212 		else
213 			sprintf(buf, "%s", w_name);
214 	}
215 	else
216 	{
217 		if (brand_templ)
218 		{
219 			char xbuf[256];
220 			strcpy(xbuf, "heap of (%d)");
221 			strcat(xbuf, brand_templ);
222 			sprintf(buf, xbuf, quantity, w_name);
223 		}
224 		else
225 			sprintf(buf, "heap of (%d) %ss", quantity, w_name);
226 	}
227 
228 
229 
230 	if (isIdentifed())
231 	{
232 		strcat(buf, " ");
233 		char tbuf[256];
234 
235 		if (RNG != 0)
236 		{
237 			sprintf(tbuf, "<%+d>", RNG);
238 			strcat(buf, tbuf);
239 		}
240 
241 		if (_DV != 0 || _PV != 0)
242 		{
243 			sprintf(tbuf, "[%+d, %+d]", _DV, _PV);
244 			strcat(buf, tbuf);
245 		}
246 		sprintf(tbuf, "(%+d, %dd%d%+d)", _HIT, dice.X, dice.Y, dice.Z);
247 		strcat(buf, tbuf);
248 
249 		StatsToString(tbuf);
250 		strcat(buf, tbuf);
251 	}
252 }
253 
GetTemplate(unsigned int mask,int isRight)254 char * XWeapon::GetTemplate(unsigned int mask, int isRight)
255 {
256 	char * brand_templ = NULL;
257 	for (int j = 0; j < weapon_brand_name_db_size; j++)
258 	{
259 		if ((weapon_brand_name_db[j].brt ^ mask) == 0)
260 		{
261 			brand_templ = weapon_brand_name_db[j].templ;
262 			break;
263 		}
264 	}
265 	return brand_templ;
266 }
267