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.64 by root, Tue May 5 04:51:56 2009 UTC vs.
Revision 1.71 by root, Sat Nov 7 13:58:01 2009 UTC

3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2003,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2003,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24#include <global.h> 25#include <global.h>
48 return -1; 49 return -1;
49 } 50 }
50 51
51 /* ADJUSTMENTS */ 52 /* ADJUSTMENTS */
52 53
53 /* Its harder to steal from hostile beings! */ 54 /* It's harder to steal from hostile beings! */
54 if (!QUERY_FLAG (victim, FLAG_UNAGGRESSIVE)) 55 if (!QUERY_FLAG (victim, FLAG_UNAGGRESSIVE))
55 roll = roll / 2; 56 roll = roll / 2;
56 57
57 /* Easier to steal from sleeping beings, or if the thief is 58 /* Easier to steal from sleeping beings, or if the thief is
58 * unseen */ 59 * unseen */
658} 659}
659 660
660/* Helper function for do_skill_ident, so that we can loop 661/* Helper function for do_skill_ident, so that we can loop
661 * over inventory AND objects on the ground conveniently. 662 * over inventory AND objects on the ground conveniently.
662 */ 663 */
663int 664static int
664do_skill_ident2 (object *tmp, object *pl, int obj_class, object *skill) 665do_skill_ident2 (object *tmp, object *pl, int obj_class, object *skill)
665{ 666{
666 int success = 0, chance; 667 int success = 0, chance;
667 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;
668 669
1052} 1053}
1053 1054
1054/* remove_trap() - This skill will disarm any previously discovered trap 1055/* remove_trap() - This skill will disarm any previously discovered trap
1055 * the algorithm is based (almost totally) on the old command_disarm() - b.t. 1056 * the algorithm is based (almost totally) on the old command_disarm() - b.t.
1056 */ 1057 */
1057
1058int 1058int
1059remove_trap (object *op, int dir, object *skill) 1059remove_trap (object *op, int dir, object *skill)
1060{ 1060{
1061 object *tmp, *tmp2; 1061 object *tmp, *tmp2;
1062 int i, success = 0, mflags; 1062 int i, success = 0, mflags;
1072 mflags = get_map_flags (m, &m, x, y, &x, &y); 1072 mflags = get_map_flags (m, &m, x, y, &x, &y);
1073 if (mflags & P_OUT_OF_MAP) 1073 if (mflags & P_OUT_OF_MAP)
1074 continue; 1074 continue;
1075 1075
1076 /* Check everything in the square for trapness */ 1076 /* Check everything in the square for trapness */
1077 for (tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) 1077 for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above)
1078 { 1078 {
1079 /* And now we'd better do an inventory traversal of each 1079 /* And now we'd better do an inventory traversal of each
1080 * of these objects inventory. Like above, only 1080 * of these objects inventory. Like above, only
1081 * do this for interesting objects. 1081 * do this for interesting objects.
1082 */ 1082 */
1083 1083
1084 if (tmp->type != PLAYER && !QUERY_FLAG (tmp, FLAG_MONSTER)) 1084 if (tmp->type != PLAYER && !QUERY_FLAG (tmp, FLAG_MONSTER))
1085 { 1085 {
1086 for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) 1086 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
1087 if ((tmp2->type == RUNE || tmp2->type == TRAP) && tmp2->stats.Cha <= 1) 1087 if ((tmp2->type == RUNE || tmp2->type == TRAP) && tmp2->stats.Cha <= 1)
1088 { 1088 {
1089 trap_show (tmp2, tmp); 1089 trap_show (tmp2, tmp);
1090
1090 if (trap_disarm (op, tmp2, 1, skill) && (!tmp2->owner || tmp2->owner->type != PLAYER)) 1091 if (trap_disarm (op, tmp2, 1, skill) && (!tmp2->owner || tmp2->owner->type != PLAYER))
1091 { 1092 {
1092 tmp->stats.exp = tmp->stats.Cha * tmp->level; 1093 tmp->stats.exp = tmp->stats.Cha * tmp->level;
1093 success += calc_skill_exp (op, tmp2, skill); 1094 success += calc_skill_exp (op, tmp2, skill);
1094 } 1095 }
1095 } 1096 }
1096 } 1097 }
1098
1097 if ((tmp->type == RUNE || tmp->type == TRAP) && tmp->stats.Cha <= 1) 1099 if ((tmp->type == RUNE || tmp->type == TRAP) && tmp->stats.Cha <= 1)
1098 { 1100 {
1099 trap_show (tmp, tmp); 1101 trap_show (tmp, tmp);
1102
1100 if (trap_disarm (op, tmp, 1, skill) && (!tmp->owner || tmp->owner->type != PLAYER)) 1103 if (trap_disarm (op, tmp, 1, skill) && (!tmp->owner || tmp->owner->type != PLAYER))
1101 { 1104 {
1102 tmp->stats.exp = tmp->stats.Cha * tmp->level; 1105 tmp->stats.exp = tmp->stats.Cha * tmp->level;
1103 success += calc_skill_exp (op, tmp, skill); 1106 success += calc_skill_exp (op, tmp, skill);
1104 } 1107 }
1130 /* Check all objects - we could stop at floor objects, 1133 /* Check all objects - we could stop at floor objects,
1131 * but if someone buries an altar, I don't see a problem with 1134 * but if someone buries an altar, I don't see a problem with
1132 * going through all the objects, and it shouldn't be much slower 1135 * going through all the objects, and it shouldn't be much slower
1133 * than extra checks on object attributes. 1136 * than extra checks on object attributes.
1134 */ 1137 */
1135 for (tmp = pl->below; tmp != NULL; tmp = tmp->below) 1138 for (tmp = pl->below; tmp; tmp = tmp->below)
1136 { 1139 {
1137 /* Only if the altar actually belongs to someone do you get special benefits */ 1140 /* Only if the altar actually belongs to someone do you get special benefits */
1138 if (tmp && tmp->type == HOLY_ALTAR && tmp->other_arch) 1141 if (tmp && tmp->type == HOLY_ALTAR && tmp->other_arch)
1139 { 1142 {
1140 sprintf (buf, "You pray over the %s.", &tmp->name); 1143 sprintf (buf, "You pray over the %s.", &tmp->name);
1215 * ordinary inscribable 'books' (anything that is not a SPELL). b.t. 1218 * ordinary inscribable 'books' (anything that is not a SPELL). b.t.
1216 */ 1219 */
1217static int 1220static int
1218write_note (object *pl, object *item, const char *msg, object *skill) 1221write_note (object *pl, object *item, const char *msg, object *skill)
1219{ 1222{
1220 if (strstr (msg, "\nendmsg")) 1223 if (!msg_is_safe (msg))
1221 { 1224 {
1222 new_draw_info (NDI_UNIQUE, 0, pl, "Trying to cheat now are we?"); 1225 new_draw_info (NDI_UNIQUE, 0, pl, "Trying to cheat now are we?");
1226 LOG (llevInfo, "write_note: player %s tried to write bogus note %s\n", &pl->name, msg);
1223 return 0; 1227 return 0;
1224 } 1228 }
1225 1229
1226 int len = strlen (msg); 1230 int len = strlen (msg);
1227 1231
1232 } 1236 }
1233 1237
1234 if (INVOKE_OBJECT (INSCRIBE_NOTE, item, ARG_PLAYER (pl->contr), ARG_STRING (msg), ARG_OBJECT (skill))) 1238 if (INVOKE_OBJECT (INSCRIBE_NOTE, item, ARG_PLAYER (pl->contr), ARG_STRING (msg), ARG_OBJECT (skill)))
1235 return RESULT_INT (0); 1239 return RESULT_INT (0);
1236 1240
1237 char buf[1024]; 1241 STRLEN char_len = utf8_length ((U8 *)msg, (U8 *)(msg+len));
1238 1242
1239 if (len < sizeof (buf) - 2) 1243 if (char_len <= item->weight_limit)
1240 { 1244 {
1241 snprintf (buf, sizeof (buf), "%s\n", msg);
1242
1243 object *newbook = arch_to_object (item->other_arch); 1245 object *newbook = arch_to_object (item->other_arch);
1244 item->decrease (); 1246 item->decrease ();
1245 newbook->nrof = 1; 1247 newbook->nrof = 1;
1246 newbook->msg = buf; 1248 newbook->msg = shstr (msg);
1247 newbook->flag [FLAG_IDENTIFIED] = true; 1249 newbook->flag [FLAG_IDENTIFIED] = true;
1248 1250
1249 if (item->subtype == 1) // mailscrolls 1251 if (item->subtype == 1) // mailscrolls
1250 { 1252 {
1251 newbook->name = item->name; 1253 newbook->name = item->name;
1254 1256
1255 pl->insert (newbook); 1257 pl->insert (newbook);
1256 1258
1257 pl->contr->play_sound (sound_find ("inscribe_success")); 1259 pl->contr->play_sound (sound_find ("inscribe_success"));
1258 new_draw_info_format (NDI_UNIQUE, 0, pl, "You write in the %s.", &item->name); 1260 new_draw_info_format (NDI_UNIQUE, 0, pl, "You write in the %s.", &item->name);
1259 return strlen (msg); 1261 return char_len;
1260 } 1262 }
1261 else 1263 else
1262 new_draw_info_format (NDI_UNIQUE, 0, pl, "Your message won't fit in the %s!", &item->name); 1264 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.>",
1265 &item->name, item->weight_limit, char_len);
1263 1266
1264 return 0; 1267 return 0;
1265} 1268}
1266 1269
1267/* write_scroll() - this routine allows players to inscribe spell scrolls 1270/* write_scroll() - this routine allows players to inscribe spell scrolls

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines