ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/living.C
(Generate patch)

Comparing deliantra/server/common/living.C (file contents):
Revision 1.9 by root, Sun Sep 10 16:00:23 2006 UTC vs.
Revision 1.18 by elmex, Wed Dec 20 10:31:00 2006 UTC

1
2/*
3 * static char *rcsid_living_c =
4 * "$Id: living.C,v 1.9 2006/09/10 16:00:23 root Exp $";
5 */
6
7/* 1/*
8 CrossFire, A Multiplayer game for X-windows 2 CrossFire, A Multiplayer game for X-windows
9 3
10 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 5 Copyright (C) 1992 Frank Tore Johansen
22 16
23 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 18 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 20
27 The authors can be reached via e-mail at crossfire-devel@real-time.com 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
28*/ 22*/
29 23
30#include <global.h> 24#include <global.h>
31#include <funcpoint.h> 25#include <funcpoint.h>
32 26
164 * -b.t. 158 * -b.t.
165 */ 159 */
166 160
167#define MAX_EXP_IN_OBJ levels[settings.max_level]/(MAX_EXP_CAT - 1) 161#define MAX_EXP_IN_OBJ levels[settings.max_level]/(MAX_EXP_CAT - 1)
168 162
169#ifndef WIN32
170extern uint64 *levels;
171#else
172extern sint64 *levels; 163extern sint64 *levels;
173#endif
174 164
175#define MAX_SAVE_LEVEL 110 165#define MAX_SAVE_LEVEL 110
176 166
177/* This no longer needs to be changed anytime the number of 167/* This no longer needs to be changed anytime the number of
178 * levels is increased - rather, did_make_save will do the 168 * levels is increased - rather, did_make_save will do the
251void 241void
252set_attr_value (living * stats, int attr, sint8 value) 242set_attr_value (living * stats, int attr, sint8 value)
253{ 243{
254 switch (attr) 244 switch (attr)
255 { 245 {
256 case STR: 246 case STR:
257 stats->Str = value; 247 stats->Str = value;
258 break; 248 break;
259 case DEX: 249 case DEX:
260 stats->Dex = value; 250 stats->Dex = value;
261 break; 251 break;
262 case CON: 252 case CON:
263 stats->Con = value; 253 stats->Con = value;
264 break; 254 break;
265 case WIS: 255 case WIS:
266 stats->Wis = value; 256 stats->Wis = value;
267 break; 257 break;
268 case POW: 258 case POW:
269 stats->Pow = value; 259 stats->Pow = value;
270 break; 260 break;
271 case CHA: 261 case CHA:
272 stats->Cha = value; 262 stats->Cha = value;
273 break; 263 break;
274 case INT: 264 case INT:
275 stats->Int = value; 265 stats->Int = value;
276 break; 266 break;
277 } 267 }
278} 268}
279 269
280/* 270/*
281 * Like set_attr_value(), but instead the value (which can be negative) 271 * Like set_attr_value(), but instead the value (which can be negative)
287{ 277{
288 if (value == 0) 278 if (value == 0)
289 return; 279 return;
290 switch (attr) 280 switch (attr)
291 { 281 {
292 case STR: 282 case STR:
293 stats->Str += value; 283 stats->Str += value;
294 break; 284 break;
295 case DEX: 285 case DEX:
296 stats->Dex += value; 286 stats->Dex += value;
297 break; 287 break;
298 case CON: 288 case CON:
299 stats->Con += value; 289 stats->Con += value;
300 break; 290 break;
301 case WIS: 291 case WIS:
302 stats->Wis += value; 292 stats->Wis += value;
303 break; 293 break;
304 case POW: 294 case POW:
305 stats->Pow += value; 295 stats->Pow += value;
306 break; 296 break;
307 case CHA: 297 case CHA:
308 stats->Cha += value; 298 stats->Cha += value;
309 break; 299 break;
310 case INT: 300 case INT:
311 stats->Int += value; 301 stats->Int += value;
312 break; 302 break;
313 default: 303 default:
314 LOG (llevError, "Invalid attribute in change_attr_value: %d\n", attr); 304 LOG (llevError, "Invalid attribute in change_attr_value: %d\n", attr);
315 } 305 }
316} 306}
317 307
318/* 308/*
319 * returns the specified stat. See also set_attr_value(). 309 * returns the specified stat. See also set_attr_value().
322sint8 312sint8
323get_attr_value (const living * stats, int attr) 313get_attr_value (const living * stats, int attr)
324{ 314{
325 switch (attr) 315 switch (attr)
326 { 316 {
327 case STR: 317 case STR:
328 return (stats->Str); 318 return (stats->Str);
329 case DEX: 319 case DEX:
330 return (stats->Dex); 320 return (stats->Dex);
331 case CON: 321 case CON:
332 return (stats->Con); 322 return (stats->Con);
333 case WIS: 323 case WIS:
334 return (stats->Wis); 324 return (stats->Wis);
335 case CHA: 325 case CHA:
336 return (stats->Cha); 326 return (stats->Cha);
337 case INT: 327 case INT:
338 return (stats->Int); 328 return (stats->Int);
339 case POW: 329 case POW:
340 return (stats->Pow); 330 return (stats->Pow);
341 } 331 }
342 return 0; 332 return 0;
343} 333}
344 334
345/* 335/*
661 651
662 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, op, message); 652 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, op, message);
663 } 653 }
664 } 654 }
665 655
666 if (tmp->type != EXPERIENCE && !potion_max) 656 if (!potion_max)
667 { 657 {
668 for (j = 0; j < NUM_STATS; j++) 658 for (j = 0; j < NUM_STATS; j++)
669 { 659 {
670 if ((i = get_attr_value (&(tmp->stats), j)) != 0) 660 if ((i = get_attr_value (&(tmp->stats), j)) != 0)
671 { 661 {
692drain_specific_stat (object *op, int deplete_stats) 682drain_specific_stat (object *op, int deplete_stats)
693{ 683{
694 object *tmp; 684 object *tmp;
695 archetype *at; 685 archetype *at;
696 686
697 at = find_archetype (ARCH_DEPLETION); 687 at = archetype::find (ARCH_DEPLETION);
698 if (!at) 688 if (!at)
699 { 689 {
700 LOG (llevError, "Couldn't find archetype depletion.\n"); 690 LOG (llevError, "Couldn't find archetype depletion.\n");
701 return; 691 return;
702 } 692 }
726{ 716{
727 object *tmp; 717 object *tmp;
728 archetype *at; 718 archetype *at;
729 int new_luck; 719 int new_luck;
730 720
731 at = find_archetype ("luck"); 721 at = archetype::find ("luck");
732 if (!at) 722 if (!at)
733 LOG (llevError, "Couldn't find archetype luck.\n"); 723 LOG (llevError, "Couldn't find archetype luck.\n");
734 else 724 else
735 { 725 {
736 tmp = present_arch_in_ob (at, op); 726 tmp = present_arch_in_ob (at, op);
1000 990
1001 /* these are the items that currently can change digestion, regeneration, 991 /* these are the items that currently can change digestion, regeneration,
1002 * spell point recovery and mana point recovery. Seems sort of an arbitary 992 * spell point recovery and mana point recovery. Seems sort of an arbitary
1003 * list, but other items store other info into stats array. 993 * list, but other items store other info into stats array.
1004 */ 994 */
1005 if ((tmp->type == EXPERIENCE) || (tmp->type == WEAPON) || 995 if ((tmp->type == WEAPON) ||
1006 (tmp->type == ARMOUR) || (tmp->type == HELMET) || 996 (tmp->type == ARMOUR) || (tmp->type == HELMET) ||
1007 (tmp->type == SHIELD) || (tmp->type == RING) || 997 (tmp->type == SHIELD) || (tmp->type == RING) ||
1008 (tmp->type == BOOTS) || (tmp->type == GLOVES) || 998 (tmp->type == BOOTS) || (tmp->type == GLOVES) ||
1009 (tmp->type == AMULET) || (tmp->type == GIRDLE) || 999 (tmp->type == AMULET) || (tmp->type == GIRDLE) ||
1010 (tmp->type == BRACERS) || (tmp->type == CLOAK) || (tmp->type == DISEASE) || (tmp->type == FORCE) || (tmp->type == SKILL)) 1000 (tmp->type == BRACERS) || (tmp->type == CLOAK) ||
1001 (tmp->type == DISEASE) || (tmp->type == FORCE) ||
1002 (tmp->type == SKILL))
1011 { 1003 {
1012 op->contr->digestion += tmp->stats.food; 1004 op->contr->digestion += tmp->stats.food;
1013 op->contr->gen_hp += tmp->stats.hp; 1005 op->contr->gen_hp += tmp->stats.hp;
1014 op->contr->gen_sp += tmp->stats.sp; 1006 op->contr->gen_sp += tmp->stats.sp;
1015 op->contr->gen_grace += tmp->stats.grace; 1007 op->contr->gen_grace += tmp->stats.grace;
1016 op->contr->gen_sp_armour += tmp->gen_sp_armour; 1008 op->contr->gen_sp_armour += tmp->gen_sp_armour;
1017 op->contr->item_power += tmp->item_power; 1009 op->contr->item_power += tmp->item_power;
1018 } 1010 }
1019 } /* if this is a player */ 1011 } /* if this is a player */
1020 1012
1021 /* Update slots used for items */ 1013 /* Update slots used for items */
1022 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 1014 if (QUERY_FLAG (tmp, FLAG_APPLIED))
1103 added_speed += (float) tmp->stats.exp; 1095 added_speed += (float) tmp->stats.exp;
1104 } 1096 }
1105 1097
1106 switch (tmp->type) 1098 switch (tmp->type)
1107 { 1099 {
1108 /* skills modifying the character -b.t. */ 1100 /* skills modifying the character -b.t. */
1109 /* for all skills and skill granting objects */ 1101 /* for all skills and skill granting objects */
1110 case SKILL: 1102 case SKILL:
1111 if (!QUERY_FLAG (tmp, FLAG_APPLIED)) 1103 if (!QUERY_FLAG (tmp, FLAG_APPLIED))
1112 break;
1113
1114 if (IS_COMBAT_SKILL (tmp->subtype))
1115 wc_obj = tmp;
1116
1117 if (op->chosen_skill)
1118 {
1119 LOG (llevDebug, "fix_player, op %s has multiple skills applied\n", &op->name);
1120 }
1121 op->chosen_skill = tmp;
1122 if (tmp->stats.dam > 0)
1123 { /* skill is a 'weapon' */
1124 if (!QUERY_FLAG (op, FLAG_READY_WEAPON))
1125 weapon_speed = (int) WEAPON_SPEED (tmp);
1126 if (weapon_speed < 0)
1127 weapon_speed = 0;
1128 weapon_weight = tmp->weight;
1129 op->stats.dam += tmp->stats.dam * (1 + (op->chosen_skill->level / 9));
1130 if (tmp->magic)
1131 op->stats.dam += tmp->magic;
1132 }
1133 if (tmp->stats.wc)
1134 wc -= (tmp->stats.wc + tmp->magic);
1135
1136 if (tmp->slaying != NULL)
1137 op->slaying = tmp->slaying;
1138
1139 if (tmp->stats.ac)
1140 ac -= (tmp->stats.ac + tmp->magic);
1141 if (settings.spell_encumbrance == TRUE && op->type == PLAYER)
1142 op->contr->encumbrance += (int) 3 *tmp->weight / 1000;
1143
1144 if (op->type == PLAYER)
1145 op->contr->ranges[range_skill] = op;
1146 break; 1104 break;
1147 1105
1148 case SKILL_TOOL: 1106 if (IS_COMBAT_SKILL (tmp->subtype))
1107 wc_obj = tmp;
1108
1149 if (op->chosen_skill) 1109 if (op->chosen_skill)
1150 {
1151 LOG (llevDebug, "fix_player, op %s has multiple skills applied\n", &op->name); 1110 LOG (llevDebug, "fix_player, op %s has multiple skills applied\n", &op->name);
1152 } 1111
1153 op->chosen_skill = tmp; 1112 op->chosen_skill = tmp;
1154 if (op->type == PLAYER) 1113
1155 op->contr->ranges[range_skill] = op; 1114 if (tmp->stats.dam > 0)
1115 { /* skill is a 'weapon' */
1116 if (!QUERY_FLAG (op, FLAG_READY_WEAPON))
1117 weapon_speed = (int) WEAPON_SPEED (tmp);
1118 if (weapon_speed < 0)
1119 weapon_speed = 0;
1120 weapon_weight = tmp->weight;
1121 op->stats.dam += tmp->stats.dam * (1 + (op->chosen_skill->level / 9));
1122 if (tmp->magic)
1123 op->stats.dam += tmp->magic;
1156 break; 1124 }
1157 1125
1158 case SHIELD:
1159 if (settings.spell_encumbrance == TRUE && op->type == PLAYER)
1160 op->contr->encumbrance += (int) tmp->weight / 2000;
1161 case RING:
1162 case AMULET:
1163 case GIRDLE:
1164 case HELMET:
1165 case BOOTS:
1166 case GLOVES:
1167 case CLOAK:
1168 if (tmp->stats.wc) 1126 if (tmp->stats.wc)
1169 wc -= (tmp->stats.wc + tmp->magic);
1170 if (tmp->stats.dam)
1171 op->stats.dam += (tmp->stats.dam + tmp->magic);
1172 if (tmp->stats.ac)
1173 ac -= (tmp->stats.ac + tmp->magic);
1174 break;
1175
1176 case WEAPON:
1177 wc -= (tmp->stats.wc + tmp->magic); 1127 wc -= (tmp->stats.wc + tmp->magic);
1178 if (tmp->stats.ac && tmp->stats.ac + tmp->magic > 0) 1128
1129 if (tmp->slaying != NULL)
1130 op->slaying = tmp->slaying;
1131
1132 if (tmp->stats.ac)
1179 ac -= tmp->stats.ac + tmp->magic; 1133 ac -= (tmp->stats.ac + tmp->magic);
1134 if (settings.spell_encumbrance == TRUE && op->type == PLAYER)
1135 op->contr->encumbrance += (int) 3 *tmp->weight / 1000;
1136
1137 if (op->type == PLAYER)
1138 op->contr->ranges[range_skill] = op;
1139 break;
1140
1141 case SKILL_TOOL:
1142 if (op->chosen_skill)
1143 {
1144 LOG (llevDebug, "fix_player, op %s has multiple skills applied\n", &op->name);
1145 }
1146 op->chosen_skill = tmp;
1147 if (op->type == PLAYER)
1148 op->contr->ranges[range_skill] = op;
1149 break;
1150
1151 case SHIELD:
1152 if (settings.spell_encumbrance == TRUE && op->type == PLAYER)
1153 op->contr->encumbrance += (int) tmp->weight / 2000;
1154 case RING:
1155 case AMULET:
1156 case GIRDLE:
1157 case HELMET:
1158 case BOOTS:
1159 case GLOVES:
1160 case CLOAK:
1161 if (tmp->stats.wc)
1162 wc -= (tmp->stats.wc + tmp->magic);
1163 if (tmp->stats.dam)
1180 op->stats.dam += (tmp->stats.dam + tmp->magic); 1164 op->stats.dam += (tmp->stats.dam + tmp->magic);
1165 if (tmp->stats.ac)
1166 ac -= (tmp->stats.ac + tmp->magic);
1167 break;
1168
1169 case WEAPON:
1170 wc -= (tmp->stats.wc + tmp->magic);
1171 if (tmp->stats.ac && tmp->stats.ac + tmp->magic > 0)
1172 ac -= tmp->stats.ac + tmp->magic;
1173 op->stats.dam += (tmp->stats.dam + tmp->magic);
1181 weapon_weight = tmp->weight; 1174 weapon_weight = tmp->weight;
1182 weapon_speed = ((int) WEAPON_SPEED (tmp) * 2 - tmp->magic) / 2; 1175 weapon_speed = ((int) WEAPON_SPEED (tmp) * 2 - tmp->magic) / 2;
1183 if (weapon_speed < 0) 1176 if (weapon_speed < 0)
1184 weapon_speed = 0; 1177 weapon_speed = 0;
1185 op->slaying = tmp->slaying; 1178 op->slaying = tmp->slaying;
1186 /* If there is desire that two handed weapons should do 1179 /* If there is desire that two handed weapons should do
1187 * extra strength damage, this is where the code should 1180 * extra strength damage, this is where the code should
1188 * go. 1181 * go.
1189 */ 1182 */
1190 op->current_weapon = tmp; 1183 op->current_weapon = tmp;
1191 if (settings.spell_encumbrance == TRUE && op->type == PLAYER) 1184 if (settings.spell_encumbrance == TRUE && op->type == PLAYER)
1192 op->contr->encumbrance += (int) 3 *tmp->weight / 1000; 1185 op->contr->encumbrance += (int) 3 *tmp->weight / 1000;
1193 1186
1194 break; 1187 break;
1195 1188
1196 case ARMOUR: /* Only the best of these three are used: */ 1189 case ARMOUR: /* Only the best of these three are used: */
1197 if (settings.spell_encumbrance == TRUE && op->type == PLAYER) 1190 if (settings.spell_encumbrance == TRUE && op->type == PLAYER)
1198 op->contr->encumbrance += (int) tmp->weight / 1000; 1191 op->contr->encumbrance += (int) tmp->weight / 1000;
1199 1192
1200 case BRACERS: 1193 case BRACERS:
1201 case FORCE: 1194 case FORCE:
1202 if (tmp->stats.wc) 1195 if (tmp->stats.wc)
1203 { 1196 {
1204 if (best_wc < tmp->stats.wc + tmp->magic) 1197 if (best_wc < tmp->stats.wc + tmp->magic)
1205 { 1198 {
1206 wc += best_wc; 1199 wc += best_wc;
1207 best_wc = tmp->stats.wc + tmp->magic; 1200 best_wc = tmp->stats.wc + tmp->magic;
1208 } 1201 }
1209 else 1202 else
1210 wc += tmp->stats.wc + tmp->magic; 1203 wc += tmp->stats.wc + tmp->magic;
1211 } 1204 }
1212 if (tmp->stats.ac) 1205 if (tmp->stats.ac)
1213 { 1206 {
1214 if (best_ac < tmp->stats.ac + tmp->magic) 1207 if (best_ac < tmp->stats.ac + tmp->magic)
1215 { 1208 {
1216 ac += best_ac; /* Remove last bonus */ 1209 ac += best_ac; /* Remove last bonus */
1217 best_ac = tmp->stats.ac + tmp->magic; 1210 best_ac = tmp->stats.ac + tmp->magic;
1218 } 1211 }
1219 else /* To nullify the below effect */ 1212 else /* To nullify the below effect */
1220 ac += tmp->stats.ac + tmp->magic; 1213 ac += tmp->stats.ac + tmp->magic;
1221 } 1214 }
1222 if (tmp->stats.wc) 1215 if (tmp->stats.wc)
1223 wc -= (tmp->stats.wc + tmp->magic); 1216 wc -= (tmp->stats.wc + tmp->magic);
1224 if (tmp->stats.ac) 1217 if (tmp->stats.ac)
1225 ac -= (tmp->stats.ac + tmp->magic); 1218 ac -= (tmp->stats.ac + tmp->magic);
1226 if (ARMOUR_SPEED (tmp) && ARMOUR_SPEED (tmp) / 10.0 < max) 1219 if (ARMOUR_SPEED (tmp) && ARMOUR_SPEED (tmp) / 10.0 < max)
1227 max = ARMOUR_SPEED (tmp) / 10.0; 1220 max = ARMOUR_SPEED (tmp) / 10.0;
1228 break; 1221 break;
1229 } /* switch tmp->type */ 1222 } /* switch tmp->type */
1230 } /* item is equipped */ 1223 } /* item is equipped */
1231 } /* for loop of items */ 1224 } /* for loop of items */
1232 1225
1233 /* We've gone through all the objects the player has equipped. For many things, we 1226 /* We've gone through all the objects the player has equipped. For many things, we
1964void 1957void
1965change_exp (object *op, sint64 exp, const char *skill_name, int flag) 1958change_exp (object *op, sint64 exp, const char *skill_name, int flag)
1966{ 1959{
1967 1960
1968#ifdef EXP_DEBUG 1961#ifdef EXP_DEBUG
1969# ifndef WIN32
1970 LOG (llevDebug, "change_exp() called for %s, exp = %lld\n", query_name (op), exp);
1971# else
1972 LOG (llevDebug, "change_exp() called for %s, exp = %I64d\n", query_name (op), exp); 1962 LOG (llevDebug, "change_exp() called for %s, exp = %" PRId64 "\n", query_name (op), exp);
1973# endif
1974#endif 1963#endif
1975 1964
1976 /* safety */ 1965 /* safety */
1977 if (!op) 1966 if (!op)
1978 { 1967 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines