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

Comparing deliantra/server/server/skills.C (file contents):
Revision 1.66 by root, Mon Oct 12 14:00:59 2009 UTC vs.
Revision 1.73 by root, Sun Nov 8 13:36:14 2009 UTC

49 return -1; 49 return -1;
50 } 50 }
51 51
52 /* ADJUSTMENTS */ 52 /* ADJUSTMENTS */
53 53
54 /* Its harder to steal from hostile beings! */ 54 /* It's harder to steal from hostile beings! */
55 if (!QUERY_FLAG (victim, FLAG_UNAGGRESSIVE)) 55 if (!QUERY_FLAG (victim, FLAG_UNAGGRESSIVE))
56 roll = roll / 2; 56 roll = roll / 2;
57 57
58 /* Easier to steal from sleeping beings, or if the thief is 58 /* Easier to steal from sleeping beings, or if the thief is
59 * unseen */ 59 * unseen */
315 // reduce monster experience by experience we gained, as to 315 // reduce monster experience by experience we gained, as to
316 // limit the amount of exp that can be gained by stealing from monsters 316 // limit the amount of exp that can be gained by stealing from monsters
317 // (jessies gave ~20,000,000 exp otherwise. 317 // (jessies gave ~20,000,000 exp otherwise.
318 int exp = calc_skill_exp (op, tmp, skill); 318 int exp = calc_skill_exp (op, tmp, skill);
319 319
320 exp = MIN (tmp->stats.exp, exp); 320 exp = min (tmp->stats.exp, exp);
321 tmp->stats.exp -= exp; 321 tmp->stats.exp -= exp;
322 return exp; 322 return exp;
323 } 323 }
324 } 324 }
325 return 0; 325 return 0;
659} 659}
660 660
661/* Helper function for do_skill_ident, so that we can loop 661/* Helper function for do_skill_ident, so that we can loop
662 * over inventory AND objects on the ground conveniently. 662 * over inventory AND objects on the ground conveniently.
663 */ 663 */
664int 664static int
665do_skill_ident2 (object *tmp, object *pl, int obj_class, object *skill) 665do_skill_ident2 (object *tmp, object *pl, int obj_class, object *skill)
666{ 666{
667 int success = 0, chance; 667 int success = 0, chance;
668 int skill_value = skill->level * pl->stats.Int ? pl->stats.Int : 10; 668 int skill_value = skill->level * pl->stats.Int ? pl->stats.Int : 10;
669 669
925 925
926 if (pl->type != PLAYER) 926 if (pl->type != PLAYER)
927 return 0; /* only players use this skill */ 927 return 0; /* only players use this skill */
928 928
929 new_draw_info_format (NDI_UNIQUE, 0, pl, "You sing."); 929 new_draw_info_format (NDI_UNIQUE, 0, pl, "You sing.");
930 for (i = 0; i < MIN (skill->level, SIZEOFFREE); i++) 930 for (i = 0; i < min (skill->level, SIZEOFFREE); i++)
931 { 931 {
932 x = pl->x + freearr_x[i]; 932 x = pl->x + freearr_x[i];
933 y = pl->y + freearr_y[i]; 933 y = pl->y + freearr_y[i];
934 m = pl->map; 934 m = pl->map;
935 935
986} 986}
987 987
988/* The find_traps skill (aka, search). Checks for traps 988/* The find_traps skill (aka, search). Checks for traps
989 * on the spaces or in certain objects 989 * on the spaces or in certain objects
990 */ 990 */
991
992int 991int
993find_traps (object *pl, object *skill) 992find_traps (object *pl, object *skill)
994{ 993{
995 object *tmp, *tmp2; 994 object *tmp, *tmp2;
996 int i, expsum = 0, mflags; 995 int i, expsum = 0, mflags;
998 maptile *m; 997 maptile *m;
999 998
1000 /* First we search all around us for runes and traps, which are 999 /* First we search all around us for runes and traps, which are
1001 * all type RUNE 1000 * all type RUNE
1002 */ 1001 */
1003
1004 for (i = 0; i < 9; i++) 1002 for (i = 0; i < 9; i++)
1005 { 1003 {
1006 x = pl->x + freearr_x[i]; 1004 x = pl->x + freearr_x[i];
1007 y = pl->y + freearr_y[i]; 1005 y = pl->y + freearr_y[i];
1008 m = pl->map; 1006 m = pl->map;
1010 mflags = get_map_flags (m, &m, x, y, &x, &y); 1008 mflags = get_map_flags (m, &m, x, y, &x, &y);
1011 if (mflags & P_OUT_OF_MAP) 1009 if (mflags & P_OUT_OF_MAP)
1012 continue; 1010 continue;
1013 1011
1014 /* Check everything in the square for trapness */ 1012 /* Check everything in the square for trapness */
1015 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) 1013 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
1016 { 1014 {
1017
1018 /* And now we'd better do an inventory traversal of each 1015 /* And now we'd better do an inventory traversal of each
1019 * of these objects' inventory 1016 * of these objects' inventory
1020 * We can narrow this down a bit - no reason to search through 1017 * We can narrow this down a bit - no reason to search through
1021 * the players inventory or monsters for that matter. 1018 * the players inventory or monsters for that matter.
1022 */ 1019 */
1023 if (tmp->type != PLAYER && !QUERY_FLAG (tmp, FLAG_MONSTER)) 1020 if (tmp->type != PLAYER && !QUERY_FLAG (tmp, FLAG_MONSTER))
1024 {
1025 for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) 1021 for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below)
1026 if (tmp2->type == RUNE || tmp2->type == TRAP) 1022 if (tmp2->type == RUNE || tmp2->type == TRAP)
1027 if (trap_see (pl, tmp2)) 1023 if (trap_see (pl, tmp2))
1028 { 1024 {
1029 trap_show (tmp2, tmp); 1025 trap_show (tmp2, tmp);
1030 if (tmp2->stats.Cha > 1) 1026 if (tmp2->stats.Cha > 1)
1031 { 1027 {
1032 if (!tmp2->owner || tmp2->owner->type != PLAYER) 1028 if (!tmp2->owner || tmp2->owner->type != PLAYER)
1033 expsum += calc_skill_exp (pl, tmp2, skill); 1029 expsum += calc_skill_exp (pl, tmp2, skill);
1034 1030
1035 tmp2->stats.Cha = 1; /* unhide the trap */ 1031 tmp2->stats.Cha = 1; /* unhide the trap */
1036 } 1032 }
1037 } 1033 }
1038 } 1034
1039 if ((tmp->type == RUNE || tmp->type == TRAP) && trap_see (pl, tmp)) 1035 if ((tmp->type == RUNE || tmp->type == TRAP) && trap_see (pl, tmp))
1040 { 1036 {
1041 trap_show (tmp, tmp); 1037 trap_show (tmp, tmp);
1042 if (tmp->stats.Cha > 1) 1038 if (tmp->stats.Cha > 1)
1043 { 1039 {
1046 tmp->stats.Cha = 1; /* unhide the trap */ 1042 tmp->stats.Cha = 1; /* unhide the trap */
1047 } 1043 }
1048 } 1044 }
1049 } 1045 }
1050 } 1046 }
1047
1051 new_draw_info (NDI_BLACK, 0, pl, "You search the area."); 1048 new_draw_info (NDI_BLACK, 0, pl, "You search the area.");
1052 return expsum; 1049 return expsum;
1053} 1050}
1054 1051
1055/* remove_trap() - This skill will disarm any previously discovered trap 1052/* remove_trap() - This skill will disarm any previously discovered trap
1056 * the algorithm is based (almost totally) on the old command_disarm() - b.t. 1053 * the algorithm is based (almost totally) on the old command_disarm() - b.t.
1057 */ 1054 */
1058
1059int 1055int
1060remove_trap (object *op, int dir, object *skill) 1056remove_trap (object *op, int dir, object *skill)
1061{ 1057{
1062 object *tmp, *tmp2; 1058 object *tmp, *tmp2;
1063 int i, success = 0, mflags; 1059 int i, success = 0, mflags;
1073 mflags = get_map_flags (m, &m, x, y, &x, &y); 1069 mflags = get_map_flags (m, &m, x, y, &x, &y);
1074 if (mflags & P_OUT_OF_MAP) 1070 if (mflags & P_OUT_OF_MAP)
1075 continue; 1071 continue;
1076 1072
1077 /* Check everything in the square for trapness */ 1073 /* Check everything in the square for trapness */
1078 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) 1074 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
1079 { 1075 {
1080 /* And now we'd better do an inventory traversal of each 1076 /* And now we'd better do an inventory traversal of each
1081 * of these objects inventory. Like above, only 1077 * of these objects inventory. Like above, only
1082 * do this for interesting objects. 1078 * do this for interesting objects.
1083 */ 1079 */
1084 1080
1085 if (tmp->type != PLAYER && !QUERY_FLAG (tmp, FLAG_MONSTER)) 1081 if (tmp->type != PLAYER && !QUERY_FLAG (tmp, FLAG_MONSTER))
1086 { 1082 {
1087 for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) 1083 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
1088 if ((tmp2->type == RUNE || tmp2->type == TRAP) && tmp2->stats.Cha <= 1) 1084 if ((tmp2->type == RUNE || tmp2->type == TRAP) && tmp2->stats.Cha <= 1)
1089 { 1085 {
1090 trap_show (tmp2, tmp); 1086 trap_show (tmp2, tmp);
1087
1091 if (trap_disarm (op, tmp2, 1, skill) && (!tmp2->owner || tmp2->owner->type != PLAYER)) 1088 if (trap_disarm (op, tmp2, 1, skill) && (!tmp2->owner || tmp2->owner->type != PLAYER))
1092 { 1089 {
1093 tmp->stats.exp = tmp->stats.Cha * tmp->level; 1090 tmp->stats.exp = tmp->stats.Cha * tmp->level;
1094 success += calc_skill_exp (op, tmp2, skill); 1091 success += calc_skill_exp (op, tmp2, skill);
1095 } 1092 }
1096 } 1093 }
1097 } 1094 }
1095
1098 if ((tmp->type == RUNE || tmp->type == TRAP) && tmp->stats.Cha <= 1) 1096 if ((tmp->type == RUNE || tmp->type == TRAP) && tmp->stats.Cha <= 1)
1099 { 1097 {
1100 trap_show (tmp, tmp); 1098 trap_show (tmp, tmp);
1099
1101 if (trap_disarm (op, tmp, 1, skill) && (!tmp->owner || tmp->owner->type != PLAYER)) 1100 if (trap_disarm (op, tmp, 1, skill) && (!tmp->owner || tmp->owner->type != PLAYER))
1102 { 1101 {
1103 tmp->stats.exp = tmp->stats.Cha * tmp->level; 1102 tmp->stats.exp = tmp->stats.Cha * tmp->level;
1104 success += calc_skill_exp (op, tmp, skill); 1103 success += calc_skill_exp (op, tmp, skill);
1105 } 1104 }
1131 /* Check all objects - we could stop at floor objects, 1130 /* Check all objects - we could stop at floor objects,
1132 * but if someone buries an altar, I don't see a problem with 1131 * but if someone buries an altar, I don't see a problem with
1133 * going through all the objects, and it shouldn't be much slower 1132 * going through all the objects, and it shouldn't be much slower
1134 * than extra checks on object attributes. 1133 * than extra checks on object attributes.
1135 */ 1134 */
1136 for (tmp = pl->below; tmp != NULL; tmp = tmp->below) 1135 for (tmp = pl->below; tmp; tmp = tmp->below)
1137 { 1136 {
1138 /* Only if the altar actually belongs to someone do you get special benefits */ 1137 /* Only if the altar actually belongs to someone do you get special benefits */
1139 if (tmp && tmp->type == HOLY_ALTAR && tmp->other_arch) 1138 if (tmp && tmp->type == HOLY_ALTAR && tmp->other_arch)
1140 { 1139 {
1141 sprintf (buf, "You pray over the %s.", &tmp->name); 1140 sprintf (buf, "You pray over the %s.", &tmp->name);
1234 } 1233 }
1235 1234
1236 if (INVOKE_OBJECT (INSCRIBE_NOTE, item, ARG_PLAYER (pl->contr), ARG_STRING (msg), ARG_OBJECT (skill))) 1235 if (INVOKE_OBJECT (INSCRIBE_NOTE, item, ARG_PLAYER (pl->contr), ARG_STRING (msg), ARG_OBJECT (skill)))
1237 return RESULT_INT (0); 1236 return RESULT_INT (0);
1238 1237
1239 char buf[1024]; 1238 STRLEN char_len = utf8_length ((U8 *)msg, (U8 *)(msg+len));
1240 1239
1241 if (len < sizeof (buf) - 2) 1240 if (char_len <= item->weight_limit)
1242 { 1241 {
1243 snprintf (buf, sizeof (buf), "%s\n", msg);
1244
1245 object *newbook = arch_to_object (item->other_arch); 1242 object *newbook = arch_to_object (item->other_arch);
1246 item->decrease (); 1243 item->decrease ();
1247 newbook->nrof = 1; 1244 newbook->nrof = 1;
1248 newbook->msg = buf; 1245 newbook->msg = shstr (msg);
1249 newbook->flag [FLAG_IDENTIFIED] = true; 1246 newbook->flag [FLAG_IDENTIFIED] = true;
1250 1247
1251 if (item->subtype == 1) // mailscrolls 1248 if (item->subtype == 1) // mailscrolls
1252 { 1249 {
1253 newbook->name = item->name; 1250 newbook->name = item->name;
1256 1253
1257 pl->insert (newbook); 1254 pl->insert (newbook);
1258 1255
1259 pl->contr->play_sound (sound_find ("inscribe_success")); 1256 pl->contr->play_sound (sound_find ("inscribe_success"));
1260 new_draw_info_format (NDI_UNIQUE, 0, pl, "You write in the %s.", &item->name); 1257 new_draw_info_format (NDI_UNIQUE, 0, pl, "You write in the %s.", &item->name);
1261 return strlen (msg); 1258 return char_len;
1262 } 1259 }
1263 else 1260 else
1264 new_draw_info_format (NDI_UNIQUE, 0, pl, "Your message won't fit in the %s!", &item->name); 1261 new_draw_info_format (NDI_UNIQUE, 0, pl, "Your message won't fit in the %s! H<It is only big enough for %d characters, your message had %d characters.>",
1262 &item->name, item->weight_limit, char_len);
1265 1263
1266 return 0; 1264 return 0;
1267} 1265}
1268 1266
1269/* write_scroll() - this routine allows players to inscribe spell scrolls 1267/* write_scroll() - this routine allows players to inscribe spell scrolls
1313 1311
1314 pl->contr->play_sound (sound_find ("inscribe_success")); 1312 pl->contr->play_sound (sound_find ("inscribe_success"));
1315 1313
1316 if (!confused) 1314 if (!confused)
1317 { 1315 {
1318 newscroll->level = MAX (skill->level, chosen_spell->level); 1316 newscroll->level = max (skill->level, chosen_spell->level);
1319 newscroll->flag [FLAG_IDENTIFIED] = true; 1317 newscroll->flag [FLAG_IDENTIFIED] = true;
1320 new_draw_info (NDI_UNIQUE, 0, pl, "You succeed in writing the spell."); 1318 new_draw_info (NDI_UNIQUE, 0, pl, "You succeed in writing the spell.");
1321 } 1319 }
1322 else 1320 else
1323 { 1321 {
1324 chosen_spell = find_random_spell_in_ob (pl, NULL); 1322 chosen_spell = find_random_spell_in_ob (pl, NULL);
1325 if (!chosen_spell) 1323 if (!chosen_spell)
1326 return 0; 1324 return 0;
1327 1325
1328 newscroll->level = MAX (skill->level, chosen_spell->level); 1326 newscroll->level = max (skill->level, chosen_spell->level);
1329 new_draw_info (NDI_UNIQUE, 0, pl, "In your confused state, you write down some odd spell."); 1327 new_draw_info (NDI_UNIQUE, 0, pl, "In your confused state, you write down some odd spell.");
1330 } 1328 }
1331 1329
1332 object *tmp = chosen_spell->clone (); 1330 object *tmp = chosen_spell->clone ();
1333 insert_ob_in_ob (tmp, newscroll); 1331 insert_ob_in_ob (tmp, newscroll);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines