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.50 by root, Sat May 12 18:14:47 2007 UTC vs.
Revision 1.60 by root, Fri May 18 01:01:01 2007 UTC

242change_attr_value (living *stats, int attr, sint8 value) 242change_attr_value (living *stats, int attr, sint8 value)
243{ 243{
244 stats->stat (attr) += value; 244 stats->stat (attr) += value;
245} 245}
246 246
247sint8 &
248living::stat (int index)
249{
250 switch (index)
251 {
252 case STR: return Str;
253 case DEX: return Dex;
254 case CON: return Con;
255 case INT: return Int;
256 case WIS: return Wis;
257 case POW: return Pow;
258 case CHA: return Cha;
259 }
260
261 LOG (llevError | logBacktrace, "living.stat() called with out-of-range stat index");
262 static sint8 dummy;
263 return dummy;
264}
265
266sint8
267living::stat (int index) const
268{
269 switch (index)
270 {
271 case STR: return Str;
272 case DEX: return Dex;
273 case CON: return Con;
274 case INT: return Int;
275 case WIS: return Wis;
276 case POW: return Pow;
277 case CHA: return Cha;
278 }
279
280 LOG (llevError | logBacktrace, "living.stat() called with out-of-range stat index");
281 static sint8 dummy;
282 return dummy;
283}
284
285/* 247/*
286 * Ensures that all stats (str/dex/con/wis/cha/int) are within the 248 * Ensures that all stats (str/dex/con/wis/cha/int) are within the
287 * 1-30 stat limit. 249 * 1-30 stat limit.
288 */ 250 */
289void 251void
319 * that gives them that ability. 281 * that gives them that ability.
320 */ 282 */
321int 283int
322change_abil (object *op, object *tmp) 284change_abil (object *op, object *tmp)
323{ 285{
324 int flag = QUERY_FLAG (tmp, FLAG_APPLIED) ? 1 : -1, i, j, success = 0; 286 int flag = QUERY_FLAG (tmp, FLAG_APPLIED) ? 1 : -1, success = 0;
325 char message[MAX_BUF]; 287 char message[MAX_BUF];
326 int potion_max = 0; 288 int potion_max = 0;
327 289
328 /* remember what object was like before it was changed. note that 290 /* remember what object was like before it was changed. note that
329 * refop is a local copy of op only to be used for detecting changes 291 * refop is a local copy of op only to be used for detecting changes
334 if (op->type == PLAYER) 296 if (op->type == PLAYER)
335 { 297 {
336 if (tmp->type == POTION) 298 if (tmp->type == POTION)
337 { 299 {
338 potion_max = 1; 300 potion_max = 1;
339 for (j = 0; j < NUM_STATS; j++) 301 for (int j = 0; j < NUM_STATS; j++)
340 { 302 {
341 int nstat, ostat;
342
343 ostat = op->contr->orig_stats.stat (j); 303 int ostat = op->contr->orig_stats.stat (j);
344 i = tmp->stats.stat (j); 304 int i = tmp->stats.stat (j);
345 305
346 /* nstat is what the stat will be after use of the potion */ 306 /* nstat is what the stat will be after use of the potion */
347 nstat = flag * i + ostat; 307 int nstat = flag * i + ostat;
348 308
349 /* Do some bounds checking. While I don't think any 309 /* Do some bounds checking. While I don't think any
350 * potions do so right now, there is the potential for potions 310 * potions do so right now, there is the potential for potions
351 * that adjust that stat by more than one point, so we need 311 * that adjust that stat by more than one point, so we need
352 * to allow for that. 312 * to allow for that.
370 330
371 /* This section of code ups the characters normal stats also. I am not 331 /* This section of code ups the characters normal stats also. I am not
372 * sure if this is strictly necessary, being that fix_player probably 332 * sure if this is strictly necessary, being that fix_player probably
373 * recalculates this anyway. 333 * recalculates this anyway.
374 */ 334 */
375 for (j = 0; j < NUM_STATS; j++) 335 for (int j = 0; j < NUM_STATS; j++)
376 change_attr_value (&op->stats, j, flag * tmp->stats.stat (j)); 336 change_attr_value (&op->stats, j, flag * tmp->stats.stat (j));
377 337
378 check_stat_bounds (&op->stats); 338 check_stat_bounds (&op->stats);
379 } /* end of potion handling code */ 339 } /* end of potion handling code */
380 } 340 }
381 341
382 /* reset attributes that fix_player doesn't reset since it doesn't search 342 /* reset attributes that update_stats doesn't reset since it doesn't search
383 * everything to set 343 * everything to set
384 */ 344 */
385 if (flag == -1) 345 if (flag == -1)
386 { 346 {
387 op->attacktype &= ~tmp->attacktype; 347 op->attacktype &= ~tmp->attacktype;
393 */ 353 */
394 op->move_type &= ~tmp->move_type; 354 op->move_type &= ~tmp->move_type;
395 } 355 }
396 356
397 /* call fix_player since op object could have whatever attribute due 357 /* call fix_player since op object could have whatever attribute due
398 * to multiple items. if fix_player always has to be called after 358 * to multiple items. if update_stats always has to be called after
399 * change_ability then might as well call it from here 359 * change_ability then might as well call it from here
400 */ 360 */
401 op->update_stats (); 361 op->update_stats ();
402 362
403 /* Fix player won't add the bows ability to the player, so don't 363 /* update_stats won't add the bows ability to the player, so don't
404 * print out message if this is a bow. 364 * print out message if this is a bow.
405 */ 365 */
406 if (tmp->attacktype & AT_CONFUSION && tmp->type != BOW) 366 if (tmp->attacktype & AT_CONFUSION && tmp->type != BOW)
407 { 367 {
408 success = 1; 368 success = 1;
448 if (tmp->move_type & MOVE_FLY_HIGH) 408 if (tmp->move_type & MOVE_FLY_HIGH)
449 { 409 {
450 /* double conditional - second case covers if you have move_fly_low - 410 /* double conditional - second case covers if you have move_fly_low -
451 * in that case, you don't actually land 411 * in that case, you don't actually land
452 */ 412 */
453 DIFF_MSG (flag, "You soar into the air air!.", 413 DIFF_MSG (flag, "You soar into the air!",
454 (op->move_type & MOVE_FLY_LOW ? "You fly lower in the air" : "You float down to the ground.")); 414 (op->move_type & MOVE_FLY_LOW ? "You fly lower in the air" : "You float down to the ground."));
455 } 415 }
456 416
457 if (tmp->move_type & MOVE_SWIM) 417 if (tmp->move_type & MOVE_SWIM)
458 DIFF_MSG (flag, "You feel ready for a swim", "You no longer feel like swimming"); 418 DIFF_MSG (flag, "You feel ready for a swim", "You no longer feel like swimming");
589 success = 1; 549 success = 1;
590 DIFF_MSG (flag * tmp->stats.food, "You feel your digestion slowing down.", "You feel your digestion speeding up."); 550 DIFF_MSG (flag * tmp->stats.food, "You feel your digestion slowing down.", "You feel your digestion speeding up.");
591 } 551 }
592 552
593 /* Messages for changed resistance */ 553 /* Messages for changed resistance */
594 for (i = 0; i < NROFATTACKS; i++) 554 for (int i = 0; i < NROFATTACKS; i++)
595 { 555 {
596 if (i == ATNR_PHYSICAL) 556 if (i == ATNR_PHYSICAL)
597 continue; /* Don't display about armour */ 557 continue; /* Don't display about armour */
598 558
599 if (op->resist[i] != refop.resist[i]) 559 if (op->resist[i] != refop.resist[i])
608 } 568 }
609 } 569 }
610 570
611 if (!potion_max) 571 if (!potion_max)
612 { 572 {
613 for (j = 0; j < NUM_STATS; j++) 573 for (int j = 0; j < NUM_STATS; j++)
614 { 574 {
615 if ((i = tmp->stats.stat (j))) 575 if (int i = tmp->stats.stat (j))
616 { 576 {
617 success = 1; 577 success = 1;
618 DIFF_MSG (i * flag, gain_msg[j], lose_msg[j]); 578 DIFF_MSG (i * flag, gain_msg[j], lose_msg[j]);
619 } 579 }
620 } 580 }
723 * Subtracts stat-bonuses given by the class which the player has chosen. 683 * Subtracts stat-bonuses given by the class which the player has chosen.
724 */ 684 */
725void 685void
726object::remove_statbonus () 686object::remove_statbonus ()
727{ 687{
728 stats.Str -= arch->clone.stats.Str; 688 for (int i = 0; i < NUM_STATS; ++i)
729 stats.Dex -= arch->clone.stats.Dex; 689 {
730 stats.Con -= arch->clone.stats.Con; 690 sint8 v = arch->clone.stats.stat (i);
731 stats.Wis -= arch->clone.stats.Wis; 691 stats.stat (i) -= v;
732 stats.Pow -= arch->clone.stats.Pow; 692 contr->orig_stats.stat (i) -= v;
733 stats.Cha -= arch->clone.stats.Cha; 693 }
734 stats.Int -= arch->clone.stats.Int;
735
736 contr->orig_stats.Str -= arch->clone.stats.Str;
737 contr->orig_stats.Dex -= arch->clone.stats.Dex;
738 contr->orig_stats.Con -= arch->clone.stats.Con;
739 contr->orig_stats.Wis -= arch->clone.stats.Wis;
740 contr->orig_stats.Pow -= arch->clone.stats.Pow;
741 contr->orig_stats.Cha -= arch->clone.stats.Cha;
742 contr->orig_stats.Int -= arch->clone.stats.Int;
743} 694}
744 695
745/* 696/*
746 * Adds stat-bonuses given by the class which the player has chosen. 697 * Adds stat-bonuses given by the class which the player has chosen.
747 */ 698 */
748void 699void
749object::add_statbonus () 700object::add_statbonus ()
750{ 701{
751 stats.Str += arch->clone.stats.Str; 702 for (int i = 0; i < NUM_STATS; ++i)
752 stats.Dex += arch->clone.stats.Dex; 703 {
753 stats.Con += arch->clone.stats.Con; 704 sint8 v = arch->clone.stats.stat (i);
754 stats.Wis += arch->clone.stats.Wis; 705 stats.stat (i) += v;
755 stats.Pow += arch->clone.stats.Pow; 706 contr->orig_stats.stat (i) += v;
756 stats.Cha += arch->clone.stats.Cha; 707 }
757 stats.Int += arch->clone.stats.Int;
758
759 contr->orig_stats.Str += arch->clone.stats.Str;
760 contr->orig_stats.Dex += arch->clone.stats.Dex;
761 contr->orig_stats.Con += arch->clone.stats.Con;
762 contr->orig_stats.Wis += arch->clone.stats.Wis;
763 contr->orig_stats.Pow += arch->clone.stats.Pow;
764 contr->orig_stats.Cha += arch->clone.stats.Cha;
765 contr->orig_stats.Int += arch->clone.stats.Int;
766} 708}
767 709
768/* 710/*
769 * Updates all abilities given by applied objects in the inventory 711 * Updates all abilities given by applied objects in the inventory
770 * of the given object. Note: This function works for both monsters 712 * of the given object. Note: This function works for both monsters
781 int i, j; 723 int i, j;
782 float f, max = 9, added_speed = 0, bonus_speed = 0, sp_tmp, speed_reduce_from_disease = 1; 724 float f, max = 9, added_speed = 0, bonus_speed = 0, sp_tmp, speed_reduce_from_disease = 1;
783 int weapon_weight = 0, weapon_speed = 0; 725 int weapon_weight = 0, weapon_speed = 0;
784 int best_wc = 0, best_ac = 0, wc = 0, ac = 0; 726 int best_wc = 0, best_ac = 0, wc = 0, ac = 0;
785 int prot[NROFATTACKS], vuln[NROFATTACKS], potion_resist[NROFATTACKS]; 727 int prot[NROFATTACKS], vuln[NROFATTACKS], potion_resist[NROFATTACKS];
786 object *grace_obj = NULL, *mana_obj = NULL, *wc_obj = NULL, *tmp; 728 object *grace_obj = NULL, *mana_obj = NULL, *tmp;
787 float old_speed = speed; 729 float old_speed = speed;
788 730
789 /* First task is to clear all the values back to their original values */ 731 /* First task is to clear all the values back to their original values */
790 if (type == PLAYER) 732 if (type == PLAYER)
791 { 733 {
924 && tmp->subtype == SK_PRAYING)) 866 && tmp->subtype == SK_PRAYING))
925 { 867 {
926 if (type == PLAYER) 868 if (type == PLAYER)
927 { 869 {
928 if (tmp == contr->combat_ob || tmp == contr->ranged_ob) 870 if (tmp == contr->combat_ob || tmp == contr->ranged_ob)
871 if (tmp != current_weapon
929 if (tmp != current_weapon && (tmp->type != SKILL || tmp->subtype != SK_PRAYING)) 872 && (tmp->type != SKILL || tmp->subtype != SK_PRAYING)
873 && !tmp->flag [FLAG_CURSED]
874 && !tmp->flag [FLAG_DAMNED])
930 continue; 875 continue;
931 876
932 for (i = 0; i < NUM_STATS; i++) 877 for (i = 0; i < NUM_STATS; i++)
933 change_attr_value (&stats, i, tmp->stats.stat (i)); 878 change_attr_value (&stats, i, tmp->stats.stat (i));
934 879
935 /* these are the items that currently can change digestion, regeneration, 880 /* These are the items that currently can change digestion, regeneration,
936 * spell point recovery and mana point recovery. Seems sort of an arbitary 881 * spell point recovery and mana point recovery. Seems sort of an arbitary
937 * list, but other items store other info into stats array. 882 * list, but other items store other info into stats array.
938 */ 883 */
939 if (tmp->type == WEAPON || tmp->type == BOW || 884 if (tmp->type == WEAPON || tmp->type == BOW ||
940 tmp->type == ARMOUR || tmp->type == HELMET || 885 tmp->type == ARMOUR || tmp->type == HELMET ||
941 tmp->type == SHIELD || tmp->type == RING || 886 tmp->type == SHIELD || tmp->type == RING ||
997 vuln[i] += ((100 - vuln[i]) * -tmp->resist[i]) / 100; 942 vuln[i] += ((100 - vuln[i]) * -tmp->resist[i]) / 100;
998 } 943 }
999 } 944 }
1000 945
1001 /* There may be other things that should not adjust the attacktype */ 946 /* There may be other things that should not adjust the attacktype */
1002 if ((tmp->type != WEAPON && tmp->type != BOW && tmp->type != SYMPTOM) 947 if (tmp->type != SYMPTOM)
1003 || current_weapon == tmp)
1004 { 948 {
1005 attacktype |= tmp->attacktype; 949 attacktype |= tmp->attacktype;
1006 path_attuned |= tmp->path_attuned; 950 path_attuned |= tmp->path_attuned;
1007 path_repelled |= tmp->path_repelled; 951 path_repelled |= tmp->path_repelled;
1008 path_denied |= tmp->path_denied; 952 path_denied |= tmp->path_denied;
1053 /* for all skills and skill granting objects */ 997 /* for all skills and skill granting objects */
1054 case SKILL: 998 case SKILL:
1055 if (!QUERY_FLAG (tmp, FLAG_APPLIED)) 999 if (!QUERY_FLAG (tmp, FLAG_APPLIED))
1056 break; 1000 break;
1057 1001
1058 if (IS_COMBAT_SKILL (tmp->subtype))
1059 wc_obj = tmp;
1060
1061 if (chosen_skill) 1002 if (chosen_skill)
1062 LOG (llevDebug, "fix_player, op %s has multiple skills applied\n", &name); 1003 LOG (llevDebug, "fix_player, op %s has multiple skills applied (%s and %s)\n",
1004 &name, &chosen_skill->name, &tmp->name);
1063 1005
1064 chosen_skill = tmp; 1006 chosen_skill = tmp;
1065 1007
1066 if (tmp->stats.dam > 0) 1008 if (tmp->stats.dam > 0)
1067 { /* skill is a 'weapon' */ 1009 { /* skill is a 'weapon' */
1070 1012
1071 if (weapon_speed < 0) 1013 if (weapon_speed < 0)
1072 weapon_speed = 0; 1014 weapon_speed = 0;
1073 1015
1074 weapon_weight = tmp->weight; 1016 weapon_weight = tmp->weight;
1075 stats.dam += tmp->stats.dam * (1 + (chosen_skill->level / 9)); 1017 stats.dam += 1 + (chosen_skill->level * tmp->stats.dam / 9);
1076 1018
1077 if (tmp->magic) 1019 if (tmp->magic)
1078 stats.dam += tmp->magic; 1020 stats.dam += tmp->magic;
1079 } 1021 }
1080 1022
1088 ac -= tmp->stats.ac + tmp->magic; 1030 ac -= tmp->stats.ac + tmp->magic;
1089 1031
1090 if (settings.spell_encumbrance == TRUE && type == PLAYER) 1032 if (settings.spell_encumbrance == TRUE && type == PLAYER)
1091 contr->encumbrance += (int) 3 *tmp->weight / 1000; 1033 contr->encumbrance += (int) 3 *tmp->weight / 1000;
1092 1034
1093 break;
1094
1095 case SKILL_TOOL:
1096 if (chosen_skill)
1097 LOG (llevDebug, "fix_player, op %s has multiple skills applied\n", &name);
1098
1099 chosen_skill = tmp;
1100 break; 1035 break;
1101 1036
1102 case SHIELD: 1037 case SHIELD:
1103 if (settings.spell_encumbrance == TRUE && type == PLAYER) 1038 if (settings.spell_encumbrance == TRUE && type == PLAYER)
1104 contr->encumbrance += (int) tmp->weight / 2000; 1039 contr->encumbrance += (int) tmp->weight / 2000;
1284 stats.maxsp = (sint16)sp_tmp; 1219 stats.maxsp = (sint16)sp_tmp;
1285 1220
1286 for (i = 11; i <= mana_obj->level; i++) 1221 for (i = 11; i <= mana_obj->level; i++)
1287 stats.maxsp += 2; 1222 stats.maxsp += 2;
1288 } 1223 }
1224
1289 /* Characters can get their sp supercharged via rune of transferrance */ 1225 /* Characters can get their sp supercharged via rune of transferrance */
1290 if (stats.sp > stats.maxsp * 2) 1226 if (stats.sp > stats.maxsp * 2)
1291 stats.sp = stats.maxsp * 2; 1227 stats.sp = stats.maxsp * 2;
1292 1228
1293 /* set maxgrace, notice 3-4 lines below it depends on both Wis and Pow */ 1229 /* set maxgrace, notice 3-4 lines below it depends on both Wis and Pow */
1324 1260
1325 /* two grace points per level after 11 */ 1261 /* two grace points per level after 11 */
1326 for (i = 11; i <= grace_obj->level; i++) 1262 for (i = 11; i <= grace_obj->level; i++)
1327 stats.maxgrace += 2; 1263 stats.maxgrace += 2;
1328 } 1264 }
1265
1329 /* No limit on grace vs maxgrace */ 1266 /* No limit on grace vs maxgrace */
1330 1267
1331 if (contr->braced) 1268 if (contr->braced)
1332 { 1269 {
1333 ac += 2; 1270 ac += 2;
1345 * improvement every level, now its fighterlevel/5. So 1282 * improvement every level, now its fighterlevel/5. So
1346 * we give the player a bonus here in wc and dam 1283 * we give the player a bonus here in wc and dam
1347 * to make up for the change. Note that I left the 1284 * to make up for the change. Note that I left the
1348 * monster bonus the same as before. -b.t. 1285 * monster bonus the same as before. -b.t.
1349 */ 1286 */
1287 object *wc_obj = chosen_skill;
1350 1288
1351 if (type == PLAYER && wc_obj && wc_obj->level > 1) 1289 if (contr && wc_obj && wc_obj->level > 1)
1352 { 1290 {
1353 wc -= wc_obj->level + thaco_bonus[stats.Str]; 1291 wc -= wc_obj->level + thaco_bonus[stats.Str];
1354 1292
1355 for (i = 1; i < wc_obj->level; i++) 1293 for (i = 1; i < wc_obj->level; i++)
1356 { 1294 {
1357 /* addtional wc every 6 levels */ 1295 /* additional wc every 6 levels */
1358 if (!(i % 6)) 1296 if (!(i % 6))
1359 wc--; 1297 wc--;
1360 1298
1361 /* addtional dam every 4 levels. */ 1299 /* additional dam every 4 levels. */
1362 if (!(i % 4) && dam_bonus[stats.Str] >= 0) 1300 if (!(i % 4) && dam_bonus[stats.Str] >= 0)
1363 stats.dam += 1 + dam_bonus[stats.Str] / 5; 1301 stats.dam += 1 + dam_bonus[stats.Str] / 5;
1364 } 1302 }
1365 } 1303 }
1366 else 1304 else
1376 if (settings.search_items && contr->search_str[0]) 1314 if (settings.search_items && contr->search_str[0])
1377 speed -= 1; 1315 speed -= 1;
1378 1316
1379 if (attacktype == 0) 1317 if (attacktype == 0)
1380 attacktype = arch->clone.attacktype; 1318 attacktype = arch->clone.attacktype;
1381
1382 } /* End if player */ 1319 } /* End if player */
1383 1320
1384 if (added_speed >= 0) 1321 if (added_speed >= 0)
1385 speed += added_speed / 10.f; 1322 speed += added_speed / 10.f;
1386 else /* Something wrong here...: */ 1323 else /* Something wrong here...: */
1420 * that would just be a real pain to read. 1357 * that would just be a real pain to read.
1421 */ 1358 */
1422 float M = (max_carry[stats.Str] - 121) / 121.f; 1359 float M = (max_carry[stats.Str] - 121) / 121.f;
1423 float M2 = max_carry[stats.Str] / 100.f; 1360 float M2 = max_carry[stats.Str] / 100.f;
1424 float W = weapon_weight / 20000.f; 1361 float W = weapon_weight / 20000.f;
1425 float s = 2 - weapon_speed / 10.f; 1362 float s = (20 - weapon_speed) / 10.f;
1426 float D = (stats.Dex - 14) / 14.f; 1363 float D = (stats.Dex - 14) / 14.f;
1427 float K = 1 + M / 3.f - W / (3 * M2) + speed / 5.f + D / 2.f; 1364 float K = 1 + M / 3.f - W / (3 * M2) + speed / 5.f + D / 2.f;
1428 1365
1429 K *= (4 + level) *1.2f / (6 + level); 1366 K *= (4 + level) * 1.2f / (6 + level);
1430 1367
1431 if (K <= 0.f) 1368 if (K <= 0.01f)
1432 K = 0.01f; 1369 K = 0.01f;
1433 1370
1434 float S = speed / (K * s); 1371 float S = speed / (K * s);
1435 1372
1436 contr->weapon_sp = S; 1373 contr->weapon_sp = S;
1438 1375
1439 /* I want to limit the power of small monsters with big weapons: */ 1376 /* I want to limit the power of small monsters with big weapons: */
1440 if (type != PLAYER && arch && stats.dam > arch->clone.stats.dam * 3) 1377 if (type != PLAYER && arch && stats.dam > arch->clone.stats.dam * 3)
1441 stats.dam = arch->clone.stats.dam * 3; 1378 stats.dam = arch->clone.stats.dam * 3;
1442 1379
1443 /* Prevent overflows of wc - best you can get is ABS(120) - this 1380 stats.wc = clamp (wc, MIN_WC, MAX_WC);
1444 * should be more than enough - remember, AC is also in 8 bits, 1381 stats.ac = clamp (ac, MIN_AC, MAX_AC);
1445 * so its value is the same.
1446 */
1447 if (wc > 120)
1448 wc = 120;
1449 else if (wc < -120)
1450 wc = -120;
1451
1452 stats.wc = wc;
1453
1454 if (ac > 120)
1455 ac = 120;
1456 else if (ac < -120)
1457 ac = -120;
1458
1459 stats.ac = ac;
1460 1382
1461 /* if for some reason the creature doesn't have any move type, 1383 /* if for some reason the creature doesn't have any move type,
1462 * give them walking as a default. 1384 * give them walking as a default.
1463 * The second case is a special case - to more closely mimic the 1385 * The second case is a special case - to more closely mimic the
1464 * old behaviour - if your flying, your not walking - just 1386 * old behaviour - if your flying, your not walking - just
1644 if (!skill_obj) 1566 if (!skill_obj)
1645 { 1567 {
1646 LOG (llevError, "add_player_exp: couldn't find skill %s\n", skill_name); 1568 LOG (llevError, "add_player_exp: couldn't find skill %s\n", skill_name);
1647 return NULL; 1569 return NULL;
1648 } 1570 }
1571
1649 /* clear the flag - exp goes into this bucket, but player 1572 /* clear the flag - exp goes into this bucket, but player
1650 * still doesn't know it. 1573 * still doesn't know it.
1651 */ 1574 */
1652 CLEAR_FLAG (skill_obj, FLAG_CAN_USE_SKILL); 1575 CLEAR_FLAG (skill_obj, FLAG_CAN_USE_SKILL);
1653 skill_obj->stats.exp = 0; 1576 skill_obj->stats.exp = 0;
1654 skill_obj->level = 1; 1577 skill_obj->level = 1;
1655 insert_ob_in_ob (skill_obj, op); 1578 insert_ob_in_ob (skill_obj, op);
1656 1579
1657 if (op->contr) 1580 if (player *pl = op->contr)
1658 { 1581 {
1659 op->contr->last_skill_ob [skill_obj->subtype] = skill_obj; 1582 pl->last_skill_ob [skill_obj->subtype] = skill_obj;
1660 if (op->contr->ns) 1583 if (pl->ns)
1661 op->contr->ns->last_skill_exp[skill_obj->subtype] = -1;//TODO: should be made superfluous 1584 pl->ns->last_skill_exp[skill_obj->subtype] = -1;//TODO: should be made superfluous
1662 } 1585 }
1663 1586
1664 return skill_obj; 1587 return skill_obj;
1665} 1588}
1666
1667 1589
1668/* player_lvl_adj() - for the new exp system. we are concerned with 1590/* player_lvl_adj() - for the new exp system. we are concerned with
1669 * whether the player gets more hp, sp and new levels. 1591 * whether the player gets more hp, sp and new levels.
1670 * Note this this function should only be called for players. Monstes 1592 * Note this this function should only be called for players. Monstes
1671 * don't really gain levels 1593 * don't really gain levels
1682 1604
1683 if (op->level < settings.max_level && op->stats.exp >= level_exp (op->level + 1, who->expmul)) 1605 if (op->level < settings.max_level && op->stats.exp >= level_exp (op->level + 1, who->expmul))
1684 { 1606 {
1685 op->level++; 1607 op->level++;
1686 1608
1687 if (op != NULL && op == who && op->stats.exp > 1 && is_dragon_pl (who)) 1609 if (op && op == who && op->stats.exp > 1 && is_dragon_pl (who))
1688 dragon_level_gain (who); 1610 dragon_level_gain (who);
1689 1611
1690 /* Only roll these if it is the player (who) that gained the level */ 1612 /* Only roll these if it is the player (who) that gained the level */
1691 if (op == who && (who->level < 11) && who->type == PLAYER) 1613 if (op == who && (who->level < 11) && who->type == PLAYER)
1692 { 1614 {
1700 { 1622 {
1701 if (op->type != PLAYER) 1623 if (op->type != PLAYER)
1702 sprintf (buf, "You are now level %d in the %s skill.", op->level, &op->name); 1624 sprintf (buf, "You are now level %d in the %s skill.", op->level, &op->name);
1703 else 1625 else
1704 sprintf (buf, "You are now level %d.", op->level); 1626 sprintf (buf, "You are now level %d.", op->level);
1627
1705 if (who) 1628 if (who)
1706 new_draw_info (NDI_UNIQUE | NDI_RED, 0, who, buf); 1629 new_draw_info (NDI_UNIQUE | NDI_RED, 0, who, buf);
1707 } 1630 }
1631
1708 player_lvl_adj (who, op); /* To increase more levels */ 1632 player_lvl_adj (who, op); /* To increase more levels */
1709 } 1633 }
1710 else if (op->level > 1 && op->stats.exp < level_exp (op->level, who->expmul)) 1634 else if (op->level > 1 && op->stats.exp < level_exp (op->level, who->expmul))
1711 { 1635 {
1712 op->level--; 1636 op->level--;
1713 who->update_stats (); 1637 who->update_stats ();
1638
1714 if (op->type != PLAYER) 1639 if (op->type != PLAYER)
1715 { 1640 {
1716 sprintf (buf, "You are now level %d in the %s skill.", op->level, &op->name); 1641 sprintf (buf, "You are now level %d in the %s skill.", op->level, &op->name);
1717 new_draw_info (NDI_UNIQUE | NDI_RED, 0, who, buf); 1642 new_draw_info (NDI_UNIQUE | NDI_RED, 0, who, buf);
1718 } 1643 }
1644
1719 player_lvl_adj (who, op); /* To decrease more levels */ 1645 player_lvl_adj (who, op); /* To decrease more levels */
1720 } 1646 }
1721 1647
1722 /* check if the spell data has changed */ 1648 /* check if the spell data has changed */
1723 esrv_update_stats (who->contr); 1649 esrv_update_stats (who->contr);
2034 player_lvl_adj (op, tmp); 1960 player_lvl_adj (op, tmp);
2035 } 1961 }
2036 1962
2037 percentage_loss = op->stats.exp * settings.death_penalty_ratio / 100; 1963 percentage_loss = op->stats.exp * settings.death_penalty_ratio / 100;
2038 level_loss = op->stats.exp - levels[MAX (0, op->level - settings.death_penalty_level)]; 1964 level_loss = op->stats.exp - levels[MAX (0, op->level - settings.death_penalty_level)];
1965
2039 if (level_loss < 0) 1966 if (level_loss < 0)
2040 level_loss = 0; 1967 level_loss = 0;
2041 loss = check_exp_loss (op, MIN (level_loss, percentage_loss)); 1968 loss = check_exp_loss (op, MIN (level_loss, percentage_loss));
2042 1969
2043 op->stats.exp -= loss; 1970 op->stats.exp -= loss;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines