/* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team * Copyright (©) 1992,2007 Frank Tore Johansen * * Deliantra is free software: you can redistribute it and/or modify it under * the terms of the Affero GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the Affero GNU General Public License * and the GNU General Public License along with this program. If not, see * . * * The authors can be reached via e-mail to */ #include #include /* convert materialname to materialtype_t */ materialtype_t * name_to_material (const shstr_cmp name) { for (materialtype_t *mt = materialt; mt; mt = mt->next) if (name == mt->name) return mt; return 0; } /* when doing transmutation of objects, we have to recheck the resistances, * as some that did not apply previously, may apply now. */ void transmute_materialname (object *op, const object *change) { materialtype_t *mt; int j; if (!op->materialname) return; if (op->materialname != change->materialname) return; if (!op->is_armor ()) return; mt = name_to_material (op->materialname); if (!mt) { LOG (llevError, "archetype '%s>%s' uses nonexistent material '%s'\n", &op->arch->archname, &op->name, &op->materialname); return; } for (j = 0; j < NROFATTACKS; j++) if (op->resist[j] == 0 && change->resist[j] != 0) { op->resist[j] += mt->mod[j]; if (op->resist[j] > 100) op->resist[j] = 100; if (op->resist[j] < -100) op->resist[j] = -100; } } /* set the materialname and type for an item */ void set_materialname (object *op, int difficulty, materialtype_t *nmt) { materialtype_t *mt, *lmt; if (!op->materialname) return; if (nmt) lmt = nmt; else { lmt = 0; for (mt = materialt; mt; mt = mt->next) if (op->materials & mt->material && rndm (1, 100) <= mt->chance && difficulty >= mt->difficulty && (op->magic >= mt->magic || mt->magic == 0)) { lmt = mt; if (!(op->is_weapon () || op->is_armor ())) break; } } if (lmt) { if (op->stats.dam && op->is_weapon ()) { op->stats.dam += lmt->damage; if (op->stats.dam < 1) op->stats.dam = 1; } if (op->stats.sp && op->type == BOW) op->stats.sp += lmt->sp; if (op->stats.wc && op->is_weapon ()) op->stats.wc += lmt->wc; if (op->is_armor ()) { if (op->stats.ac) op->stats.ac += lmt->ac; for (int j = 0; j < NROFATTACKS; j++) if (op->resist[j] != 0) { op->resist[j] += lmt->mod[j]; if (op->resist[j] > 100) op->resist[j] = 100; if (op->resist[j] < -100) op->resist[j] = -100; } } op->materialname = lmt->name; /* dont make it unstackable if it doesn't need to be */ if (op->is_weapon () || op->is_armor ()) { op->weight = (op->weight * lmt->weight) / 100; op->value = (op->value * lmt->value) / 100; } } }