| 1 |
root |
1.1 |
/* |
| 2 |
|
|
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
| 3 |
|
|
* |
| 4 |
|
|
* Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
| 5 |
root |
1.9 |
* Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
| 6 |
|
|
* Copyright (©) 1992 Frank Tore Johansen |
| 7 |
root |
1.1 |
* |
| 8 |
|
|
* Deliantra is free software: you can redistribute it and/or modify it under |
| 9 |
|
|
* the terms of the Affero GNU General Public License as published by the |
| 10 |
|
|
* Free Software Foundation, either version 3 of the License, or (at your |
| 11 |
|
|
* option) any later version. |
| 12 |
|
|
* |
| 13 |
|
|
* This program is distributed in the hope that it will be useful, |
| 14 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
|
|
* GNU General Public License for more details. |
| 17 |
|
|
* |
| 18 |
|
|
* You should have received a copy of the Affero GNU General Public License |
| 19 |
|
|
* and the GNU General Public License along with this program. If not, see |
| 20 |
|
|
* <http://www.gnu.org/licenses/>. |
| 21 |
|
|
* |
| 22 |
|
|
* The authors can be reached via e-mail to <support@deliantra.net> |
| 23 |
|
|
*/ |
| 24 |
|
|
|
| 25 |
|
|
#include <global.h> |
| 26 |
|
|
#include <material.h> |
| 27 |
|
|
|
| 28 |
root |
1.3 |
//+GPL |
| 29 |
|
|
|
| 30 |
root |
1.5 |
materialtype_t *materialt; |
| 31 |
|
|
|
| 32 |
|
|
/* |
| 33 |
|
|
materialtype material[NROFMATERIALS] = { |
| 34 |
|
|
* P M F E C C A D W G P S P T F C D D C C G H B I * |
| 35 |
|
|
* H A I L O O C R E H O L A U E A E E H O O O L N * |
| 36 |
|
|
* Y G R E L N I A A O I O R R A N P A A U D L I T * |
| 37 |
|
|
* S I E C D F D I P S S W A N R C L T O N Y N R * |
| 38 |
|
|
* I C T U N O T O L E E H S T P D N * |
| 39 |
|
|
{"paper", {15,10,17, 9, 5, 7,13, 0,20,15, 0,0,0,0,0,10,0,0,0,0,0,0,0,0}}, |
| 40 |
|
|
{"metal", { 2,12, 3,12, 2,10, 7, 0,20,15, 0,0,0,0,0,10,0,0,0,0,0,0,0,0}}, |
| 41 |
|
|
{"glass", {14,11, 8, 3,10, 5, 1, 0,20,15, 0,0,0,0,0, 0,0,0,0,0,0,0,0,0}}, |
| 42 |
|
|
{"leather", { 5,10,10, 3, 3,10,10, 0,20,15, 0,0,0,0,0,12,0,0,0,0,0,0,0,0}}, |
| 43 |
|
|
{"wood", {10,11,13, 2, 2,10, 9, 0,20,15, 0,0,0,0,0,12,0,0,0,0,0,0,0,0}}, |
| 44 |
|
|
{"organics", { 3,12, 9,11, 3,10, 9, 0,20,15, 0,0,0,0,0, 0,0,0,0,0,0,0,0,0}}, |
| 45 |
|
|
{"stone", { 2, 5, 2, 2, 2, 2, 1, 0,20,15, 0,0,0,0,0, 5,0,0,0,0,0,0,0,0}}, |
| 46 |
|
|
{"cloth", {14,11,13, 4, 4, 5,10, 0,20,15, 0,0,0,0,0, 5,0,0,0,0,0,0,0,0}}, |
| 47 |
|
|
{"adamant", { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0,0, 0,0,0,0,0,0,0,0,0}}, |
| 48 |
|
|
{"liquid", { 0, 8, 9, 6,17, 0,15, 0,20,15,12,0,0,0,0,11,0,0,0,0,0,0,0,0}}, |
| 49 |
|
|
{"soft metal",{ 6,12, 6,14, 2,10, 1, 0,20,15, 0,0,0,0,0,10,0,0,0,0,0,0,0,0}}, |
| 50 |
|
|
{"bone", {10, 9, 4, 5, 3,10,10, 0,20,15, 0,0,0,0,0, 2,0,0,0,0,0,0,0,0}}, |
| 51 |
|
|
{"ice", {14,11,16, 5, 0, 5, 6, 0,20,15, 0,0,0,0,0, 7,0,0,0,0,0,0,0,0}} |
| 52 |
|
|
}; |
| 53 |
|
|
*/ |
| 54 |
|
|
|
| 55 |
|
|
materialtype_t::materialtype_t () |
| 56 |
|
|
{ |
| 57 |
|
|
next = 0; |
| 58 |
|
|
name = shstr_unknown; |
| 59 |
|
|
description = shstr_unknown_material_description; |
| 60 |
|
|
material = 0; |
| 61 |
|
|
|
| 62 |
|
|
for (int i = 0; i < NROFATTACKS; i++) |
| 63 |
|
|
{ |
| 64 |
root |
1.6 |
save [i] = 0; |
| 65 |
|
|
mod [i] = 0; |
| 66 |
root |
1.5 |
} |
| 67 |
|
|
|
| 68 |
|
|
chance = 0; |
| 69 |
|
|
difficulty = 0; |
| 70 |
|
|
magic = 0; |
| 71 |
|
|
damage = 0; |
| 72 |
|
|
wc = 0; |
| 73 |
|
|
ac = 0; |
| 74 |
|
|
sp = 0; |
| 75 |
|
|
weight = 100; |
| 76 |
|
|
value = 100; |
| 77 |
|
|
density = 1000; |
| 78 |
|
|
} |
| 79 |
|
|
|
| 80 |
root |
1.1 |
/* convert materialname to materialtype_t */ |
| 81 |
|
|
materialtype_t * |
| 82 |
root |
1.5 |
name_to_material (const shstr_tmp name) |
| 83 |
root |
1.1 |
{ |
| 84 |
|
|
for (materialtype_t *mt = materialt; mt; mt = mt->next) |
| 85 |
|
|
if (name == mt->name) |
| 86 |
|
|
return mt; |
| 87 |
|
|
|
| 88 |
root |
1.5 |
LOG (llevError, "name_to_material called with nonexistent material '%s'\n", &name); |
| 89 |
|
|
|
| 90 |
|
|
// create a new material of the given name |
| 91 |
|
|
materialtype_t *mt = new materialtype_t; |
| 92 |
|
|
mt->name = name; |
| 93 |
|
|
|
| 94 |
root |
1.6 |
// make it susceptible to attacks |
| 95 |
|
|
for (int i = 0; i < NROFATTACKS; i++) |
| 96 |
|
|
{ |
| 97 |
|
|
mt->save [i] = 10; |
| 98 |
|
|
mt->mod [i] = 9; |
| 99 |
|
|
} |
| 100 |
|
|
|
| 101 |
|
|
mt->next = materialt; materialt = mt; |
| 102 |
root |
1.5 |
|
| 103 |
|
|
return mt; |
| 104 |
root |
1.1 |
} |
| 105 |
|
|
|
| 106 |
|
|
/* when doing transmutation of objects, we have to recheck the resistances, |
| 107 |
|
|
* as some that did not apply previously, may apply now. |
| 108 |
|
|
*/ |
| 109 |
|
|
void |
| 110 |
|
|
transmute_materialname (object *op, const object *change) |
| 111 |
|
|
{ |
| 112 |
root |
1.6 |
if (!op->is_armor ()) |
| 113 |
|
|
return; |
| 114 |
root |
1.1 |
|
| 115 |
root |
1.7 |
if (op->material == MATERIAL_NULL) |
| 116 |
root |
1.1 |
return; |
| 117 |
|
|
|
| 118 |
root |
1.6 |
if (op->material != change->material) |
| 119 |
root |
1.1 |
return; |
| 120 |
|
|
|
| 121 |
root |
1.5 |
materialtype_t *mt = op->material; |
| 122 |
root |
1.1 |
|
| 123 |
root |
1.6 |
for (int j = 0; j < NROFATTACKS; j++) |
| 124 |
root |
1.1 |
if (op->resist[j] == 0 && change->resist[j] != 0) |
| 125 |
|
|
{ |
| 126 |
|
|
op->resist[j] += mt->mod[j]; |
| 127 |
root |
1.5 |
|
| 128 |
|
|
if (op->resist[j] > 100) op->resist[j] = 100; |
| 129 |
|
|
if (op->resist[j] < -100) op->resist[j] = -100; |
| 130 |
root |
1.1 |
} |
| 131 |
|
|
} |
| 132 |
|
|
|
| 133 |
|
|
/* set the materialname and type for an item */ |
| 134 |
|
|
void |
| 135 |
root |
1.5 |
select_material (object *op, int difficulty) |
| 136 |
root |
1.1 |
{ |
| 137 |
root |
1.7 |
if (op->material != MATERIAL_NULL || !op->materials) |
| 138 |
root |
1.5 |
return; |
| 139 |
root |
1.1 |
|
| 140 |
root |
1.5 |
materialtype_t *lmt = 0; |
| 141 |
root |
1.1 |
|
| 142 |
root |
1.5 |
//TODL: dead code? |
| 143 |
|
|
for (materialtype_t *mt = materialt; mt; mt = mt->next) |
| 144 |
|
|
if (op->materials & mt->material |
| 145 |
|
|
&& difficulty >= mt->difficulty |
| 146 |
|
|
&& rndm (1, 100) <= mt->chance |
| 147 |
|
|
&& (op->magic >= mt->magic || mt->magic == 0)) |
| 148 |
|
|
{ |
| 149 |
|
|
lmt = mt; |
| 150 |
root |
1.1 |
|
| 151 |
root |
1.5 |
if (!(op->is_weapon () || op->is_armor ())) |
| 152 |
|
|
break; |
| 153 |
|
|
} |
| 154 |
root |
1.1 |
|
| 155 |
|
|
if (lmt) |
| 156 |
|
|
{ |
| 157 |
|
|
if (op->stats.dam && op->is_weapon ()) |
| 158 |
|
|
{ |
| 159 |
|
|
op->stats.dam += lmt->damage; |
| 160 |
|
|
if (op->stats.dam < 1) |
| 161 |
|
|
op->stats.dam = 1; |
| 162 |
|
|
} |
| 163 |
|
|
|
| 164 |
root |
1.5 |
if (op->stats.sp && op->type == BOW ) op->stats.sp += lmt->sp; |
| 165 |
|
|
if (op->stats.wc && op->is_weapon ()) op->stats.wc += lmt->wc; |
| 166 |
|
|
|
| 167 |
root |
1.1 |
if (op->is_armor ()) |
| 168 |
|
|
{ |
| 169 |
|
|
if (op->stats.ac) |
| 170 |
|
|
op->stats.ac += lmt->ac; |
| 171 |
|
|
|
| 172 |
|
|
for (int j = 0; j < NROFATTACKS; j++) |
| 173 |
|
|
if (op->resist[j] != 0) |
| 174 |
|
|
{ |
| 175 |
|
|
op->resist[j] += lmt->mod[j]; |
| 176 |
root |
1.5 |
if (op->resist[j] > 100) op->resist[j] = 100; |
| 177 |
|
|
if (op->resist[j] < -100) op->resist[j] = -100; |
| 178 |
root |
1.1 |
} |
| 179 |
|
|
} |
| 180 |
|
|
|
| 181 |
root |
1.5 |
op->material = lmt; |
| 182 |
|
|
|
| 183 |
root |
1.1 |
/* dont make it unstackable if it doesn't need to be */ |
| 184 |
|
|
if (op->is_weapon () || op->is_armor ()) |
| 185 |
|
|
{ |
| 186 |
root |
1.5 |
op->weight = op->weight * lmt->weight / 100; |
| 187 |
|
|
op->value = op->value * lmt->value / 100; |
| 188 |
root |
1.1 |
} |
| 189 |
|
|
} |
| 190 |
|
|
} |
| 191 |
|
|
|
| 192 |
root |
1.3 |
//-GPL |
| 193 |
|
|
|
| 194 |
root |
1.2 |
void |
| 195 |
root |
1.8 |
load_materials () |
| 196 |
root |
1.2 |
{ |
| 197 |
|
|
char filename[MAX_BUF]; |
| 198 |
|
|
|
| 199 |
|
|
sprintf (filename, "%s/materials", settings.datadir); |
| 200 |
|
|
LOG (llevDebug, "Reading material type data from %s...\n", filename); |
| 201 |
|
|
|
| 202 |
|
|
//TODO: somehow free old materials, or update them in-place |
| 203 |
root |
1.6 |
material_null.next = 0; materialt = &material_null; |
| 204 |
root |
1.2 |
|
| 205 |
|
|
object_thawer thawer (filename); |
| 206 |
|
|
|
| 207 |
|
|
if (!thawer) |
| 208 |
|
|
{ |
| 209 |
|
|
LOG (llevError, "Cannot open %s for reading\n", filename); |
| 210 |
|
|
goto done; |
| 211 |
|
|
} |
| 212 |
|
|
|
| 213 |
|
|
while (thawer.kw != KW_name) |
| 214 |
|
|
{ |
| 215 |
|
|
thawer.next (); |
| 216 |
|
|
|
| 217 |
|
|
if (thawer.kw == KW_EOF) |
| 218 |
|
|
goto done; |
| 219 |
|
|
} |
| 220 |
|
|
|
| 221 |
|
|
materialtype_t *mt; |
| 222 |
|
|
|
| 223 |
|
|
for (;;) |
| 224 |
|
|
{ |
| 225 |
|
|
switch (thawer.kw) |
| 226 |
|
|
{ |
| 227 |
|
|
case KW_name: |
| 228 |
root |
1.5 |
mt = new materialtype_t; |
| 229 |
|
|
thawer.get (mt->name); |
| 230 |
|
|
mt->description = mt->name; |
| 231 |
|
|
|
| 232 |
root |
1.6 |
mt->next = materialt; materialt = mt; |
| 233 |
root |
1.2 |
break; |
| 234 |
|
|
|
| 235 |
|
|
case KW_description: |
| 236 |
|
|
thawer.get (mt->description); |
| 237 |
|
|
break; |
| 238 |
|
|
|
| 239 |
|
|
case KW_material: |
| 240 |
|
|
thawer.get (mt->material); |
| 241 |
|
|
break; |
| 242 |
|
|
|
| 243 |
|
|
case KW_saves: |
| 244 |
|
|
{ |
| 245 |
|
|
const char *cp = thawer.get_str () - 1; |
| 246 |
|
|
|
| 247 |
|
|
for (int i = 0; i < NROFATTACKS; i++) |
| 248 |
|
|
{ |
| 249 |
|
|
if (!cp) |
| 250 |
|
|
{ |
| 251 |
|
|
mt->save[i] = 0; |
| 252 |
|
|
continue; |
| 253 |
|
|
} |
| 254 |
|
|
|
| 255 |
|
|
int value; |
| 256 |
|
|
++cp; |
| 257 |
|
|
sscanf (cp, "%d", &value); |
| 258 |
|
|
mt->save[i] = (sint8) value; |
| 259 |
|
|
cp = strchr (cp, ','); |
| 260 |
|
|
} |
| 261 |
|
|
} |
| 262 |
|
|
break; |
| 263 |
|
|
|
| 264 |
|
|
case KW_mods: |
| 265 |
|
|
{ |
| 266 |
|
|
const char *cp = thawer.get_str () - 1; |
| 267 |
|
|
|
| 268 |
|
|
for (int i = 0; i < NROFATTACKS; i++) |
| 269 |
|
|
{ |
| 270 |
|
|
if (!cp) |
| 271 |
|
|
{ |
| 272 |
|
|
mt->save[i] = 0; |
| 273 |
|
|
continue; |
| 274 |
|
|
} |
| 275 |
|
|
|
| 276 |
|
|
++cp; |
| 277 |
|
|
int value; |
| 278 |
|
|
sscanf (cp, "%d", &value); |
| 279 |
|
|
mt->mod[i] = (sint8) value; |
| 280 |
|
|
cp = strchr (cp, ','); |
| 281 |
|
|
} |
| 282 |
|
|
} |
| 283 |
|
|
break; |
| 284 |
|
|
|
| 285 |
|
|
case KW_chance: thawer.get (mt->chance); break; |
| 286 |
|
|
case KW_difficulty: // cf+ alias, not original cf |
| 287 |
|
|
case KW_diff: thawer.get (mt->difficulty); break; |
| 288 |
|
|
case KW_magic: thawer.get (mt->magic); break; |
| 289 |
|
|
case KW_dam: // cf+ alias, not original cf |
| 290 |
|
|
case KW_damage: thawer.get (mt->damage); break; |
| 291 |
|
|
case KW_wc: thawer.get (mt->wc); break; |
| 292 |
|
|
case KW_ac: thawer.get (mt->ac); break; |
| 293 |
|
|
case KW_sp: thawer.get (mt->sp); break; |
| 294 |
|
|
case KW_weight: thawer.get (mt->weight); break; |
| 295 |
|
|
case KW_value: thawer.get (mt->value); break; |
| 296 |
|
|
case KW_density: thawer.get (mt->density); break; |
| 297 |
|
|
|
| 298 |
|
|
case KW_EOF: |
| 299 |
|
|
goto done; |
| 300 |
|
|
|
| 301 |
|
|
default: |
| 302 |
|
|
if (!thawer.parse_error ("materials file", "materials")) |
| 303 |
|
|
goto done; |
| 304 |
|
|
break; |
| 305 |
|
|
} |
| 306 |
|
|
|
| 307 |
|
|
thawer.next (); |
| 308 |
|
|
} |
| 309 |
|
|
|
| 310 |
|
|
done: |
| 311 |
|
|
LOG (llevDebug, "Done.\n"); |
| 312 |
|
|
} |
| 313 |
|
|
|