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.58 by elmex, Sun Dec 14 13:49:11 2008 UTC vs.
Revision 1.71 by root, Sat Nov 7 13:58:01 2009 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 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>
41 /* Only prohibit stealing if the player does not have a free 42 /* Only prohibit stealing if the player does not have a free
42 * hand available and in fact does have hands. 43 * hand available and in fact does have hands.
43 */ 44 */
44 if (op->type == PLAYER && op->slot[body_arm].used <= 0 && op->slot[body_arm].info) 45 if (op->type == PLAYER && op->slot[body_arm].used <= 0 && op->slot[body_arm].info)
45 { 46 {
46 new_draw_info (NDI_UNIQUE, 0, op, "But you have no free hands to steal with!"); 47 new_draw_info (NDI_UNIQUE, 0, op, "But you have no free hands to steal with! "
48 "H<Try to unapply weapons or things you hold in your hands, use the C<body> command.>");
47 return -1; 49 return -1;
48 } 50 }
49 51
50 /* ADJUSTMENTS */ 52 /* ADJUSTMENTS */
51 53
52 /* Its harder to steal from hostile beings! */ 54 /* It's harder to steal from hostile beings! */
53 if (!QUERY_FLAG (victim, FLAG_UNAGGRESSIVE)) 55 if (!QUERY_FLAG (victim, FLAG_UNAGGRESSIVE))
54 roll = roll / 2; 56 roll = roll / 2;
55 57
56 /* Easier to steal from sleeping beings, or if the thief is 58 /* Easier to steal from sleeping beings, or if the thief is
57 * unseen */ 59 * unseen */
101{ 103{
102 object *success = NULL, *tmp = NULL, *next; 104 object *success = NULL, *tmp = NULL, *next;
103 int roll = 0, chance = 0, stats_value; 105 int roll = 0, chance = 0, stats_value;
104 rv_vector rv; 106 rv_vector rv;
105 107
106 stats_value = ((who->stats.Dex + who->stats.Int) * 3) / 2; 108 stats_value = (who->stats.Dex + who->stats.Int) * 3 / 2;
107 109
108 /* if the victim is aware of a thief in the area (FLAG_NO_STEAL set on them) 110 /* if the victim is aware of a thief in the area (FLAG_NO_STEAL set on them)
109 * they will try to prevent stealing if they can. Only unseen theives will 111 * they will try to prevent stealing if they can. Only unseen theives will
110 * have much chance of success. 112 * have much chance of success.
111 */ 113 */
112 if (op->type != PLAYER && QUERY_FLAG (op, FLAG_NO_STEAL)) 114 if (!op->is_player () && op->flag [FLAG_NO_STEAL])
113 { 115 {
114 if (can_detect_enemy (op, who, &rv)) 116 if (can_detect_enemy (op, who, &rv))
115 { 117 {
116 npc_call_help (op); 118 npc_call_help (op);
117 CLEAR_FLAG (op, FLAG_UNAGGRESSIVE); 119 CLEAR_FLAG (op, FLAG_UNAGGRESSIVE);
118 new_draw_info (NDI_UNIQUE, 0, who, "Your attempt is prevented!"); 120 new_draw_info (NDI_UNIQUE, 0, who, "Your attempt is prevented!");
119 return 0; 121 return 0;
120 } 122 }
121 else /* help npc to detect thief next time by raising its wisdom */ 123 else /* help npc to detect thief next time by raising its wisdom */
122 op->stats.Wis += (op->stats.Int / 5) + 1; 124 op->stats.Wis += (op->stats.Int / 5) + 1;
125
123 if (op->stats.Wis > MAX_STAT) 126 if (op->stats.Wis > MAX_STAT)
124 op->stats.Wis = MAX_STAT; 127 op->stats.Wis = MAX_STAT;
125 } 128 }
126 129
127 if (op->type == PLAYER && QUERY_FLAG (op, FLAG_WIZ)) 130 if (op->is_player () && op->flag [FLAG_WIZ])
128 { 131 {
129 new_draw_info (NDI_UNIQUE, 0, who, "You can't steal from the dungeon master!\n"); 132 new_draw_info (NDI_UNIQUE, 0, who, "You can't steal from the dungeon master!\n");
130 return 0; 133 return 0;
131 } 134 }
132 135
133 // only allow stealing between hostile players (TODO: probably should change) 136 // only allow stealing between hostile players (TODO: probably should change)
134 if (op->type == PLAYER && who->type == PLAYER && (who->contr->peaceful || op->contr->peaceful)) 137 if (op->is_player () && who->is_player () && (who->contr->peaceful || op->contr->peaceful))
135 { 138 {
136 new_draw_info (NDI_UNIQUE, 0, who, "You can't steal from other players!\n"); 139 new_draw_info (NDI_UNIQUE, 0, who, "You can't steal from other players!\n");
137 return 0; 140 return 0;
138 } 141 }
139 142
544 } 547 }
545 548
546 pl->x = x; 549 pl->x = x;
547 pl->y = y; 550 pl->y = y;
548 pl->map = m; 551 pl->map = m;
552
553 if (m->at (x, y).move_on & pl->move_type)
554 {
555 new_draw_info (NDI_UNIQUE, 0, pl, "Your jump is stopped.");
556 stop_jump (pl, i, spaces);
557 return 0;
558 }
549 } 559 }
550 560
551 stop_jump (pl, i, spaces); 561 stop_jump (pl, i, spaces);
552 562
553 return calc_skill_exp (pl, NULL, skill); 563 return calc_skill_exp (pl, NULL, skill);
649} 659}
650 660
651/* Helper function for do_skill_ident, so that we can loop 661/* Helper function for do_skill_ident, so that we can loop
652 * over inventory AND objects on the ground conveniently. 662 * over inventory AND objects on the ground conveniently.
653 */ 663 */
654int 664static int
655do_skill_ident2 (object *tmp, object *pl, int obj_class, object *skill) 665do_skill_ident2 (object *tmp, object *pl, int obj_class, object *skill)
656{ 666{
657 int success = 0, chance; 667 int success = 0, chance;
658 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;
659 669
1043} 1053}
1044 1054
1045/* remove_trap() - This skill will disarm any previously discovered trap 1055/* remove_trap() - This skill will disarm any previously discovered trap
1046 * 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.
1047 */ 1057 */
1048
1049int 1058int
1050remove_trap (object *op, int dir, object *skill) 1059remove_trap (object *op, int dir, object *skill)
1051{ 1060{
1052 object *tmp, *tmp2; 1061 object *tmp, *tmp2;
1053 int i, success = 0, mflags; 1062 int i, success = 0, mflags;
1063 mflags = get_map_flags (m, &m, x, y, &x, &y); 1072 mflags = get_map_flags (m, &m, x, y, &x, &y);
1064 if (mflags & P_OUT_OF_MAP) 1073 if (mflags & P_OUT_OF_MAP)
1065 continue; 1074 continue;
1066 1075
1067 /* Check everything in the square for trapness */ 1076 /* Check everything in the square for trapness */
1068 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)
1069 { 1078 {
1070 /* And now we'd better do an inventory traversal of each 1079 /* And now we'd better do an inventory traversal of each
1071 * of these objects inventory. Like above, only 1080 * of these objects inventory. Like above, only
1072 * do this for interesting objects. 1081 * do this for interesting objects.
1073 */ 1082 */
1074 1083
1075 if (tmp->type != PLAYER && !QUERY_FLAG (tmp, FLAG_MONSTER)) 1084 if (tmp->type != PLAYER && !QUERY_FLAG (tmp, FLAG_MONSTER))
1076 { 1085 {
1077 for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) 1086 for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below)
1078 if ((tmp2->type == RUNE || tmp2->type == TRAP) && tmp2->stats.Cha <= 1) 1087 if ((tmp2->type == RUNE || tmp2->type == TRAP) && tmp2->stats.Cha <= 1)
1079 { 1088 {
1080 trap_show (tmp2, tmp); 1089 trap_show (tmp2, tmp);
1090
1081 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))
1082 { 1092 {
1083 tmp->stats.exp = tmp->stats.Cha * tmp->level; 1093 tmp->stats.exp = tmp->stats.Cha * tmp->level;
1084 success += calc_skill_exp (op, tmp2, skill); 1094 success += calc_skill_exp (op, tmp2, skill);
1085 } 1095 }
1086 } 1096 }
1087 } 1097 }
1098
1088 if ((tmp->type == RUNE || tmp->type == TRAP) && tmp->stats.Cha <= 1) 1099 if ((tmp->type == RUNE || tmp->type == TRAP) && tmp->stats.Cha <= 1)
1089 { 1100 {
1090 trap_show (tmp, tmp); 1101 trap_show (tmp, tmp);
1102
1091 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))
1092 { 1104 {
1093 tmp->stats.exp = tmp->stats.Cha * tmp->level; 1105 tmp->stats.exp = tmp->stats.Cha * tmp->level;
1094 success += calc_skill_exp (op, tmp, skill); 1106 success += calc_skill_exp (op, tmp, skill);
1095 } 1107 }
1121 /* Check all objects - we could stop at floor objects, 1133 /* Check all objects - we could stop at floor objects,
1122 * 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
1123 * 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
1124 * than extra checks on object attributes. 1136 * than extra checks on object attributes.
1125 */ 1137 */
1126 for (tmp = pl->below; tmp != NULL; tmp = tmp->below) 1138 for (tmp = pl->below; tmp; tmp = tmp->below)
1127 { 1139 {
1128 /* 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 */
1129 if (tmp && tmp->type == HOLY_ALTAR && tmp->other_arch) 1141 if (tmp && tmp->type == HOLY_ALTAR && tmp->other_arch)
1130 { 1142 {
1131 sprintf (buf, "You pray over the %s.", &tmp->name); 1143 sprintf (buf, "You pray over the %s.", &tmp->name);
1206 * ordinary inscribable 'books' (anything that is not a SPELL). b.t. 1218 * ordinary inscribable 'books' (anything that is not a SPELL). b.t.
1207 */ 1219 */
1208static int 1220static int
1209write_note (object *pl, object *item, const char *msg, object *skill) 1221write_note (object *pl, object *item, const char *msg, object *skill)
1210{ 1222{
1211 if (strstr (msg, "\nendmsg")) 1223 if (!msg_is_safe (msg))
1212 { 1224 {
1213 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);
1214 return 0; 1227 return 0;
1215 } 1228 }
1216 1229
1217 int len = strlen (msg); 1230 int len = strlen (msg);
1218 1231
1223 } 1236 }
1224 1237
1225 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)))
1226 return RESULT_INT (0); 1239 return RESULT_INT (0);
1227 1240
1228 char buf[1024]; 1241 STRLEN char_len = utf8_length ((U8 *)msg, (U8 *)(msg+len));
1229 1242
1230 if (len < sizeof (buf) - 2) 1243 if (char_len <= item->weight_limit)
1231 { 1244 {
1232 snprintf (buf, sizeof (buf), "%s\n", msg);
1233
1234 object *newbook = arch_to_object (item->other_arch); 1245 object *newbook = arch_to_object (item->other_arch);
1235 item->decrease (); 1246 item->decrease ();
1236 newbook->nrof = 1; 1247 newbook->nrof = 1;
1237 newbook->msg = buf; 1248 newbook->msg = shstr (msg);
1238 newbook->flag [FLAG_IDENTIFIED] = true; 1249 newbook->flag [FLAG_IDENTIFIED] = true;
1239 1250
1240 if (item->subtype == 1) // mailscrolls 1251 if (item->subtype == 1) // mailscrolls
1241 { 1252 {
1242 newbook->name = item->name; 1253 newbook->name = item->name;
1245 1256
1246 pl->insert (newbook); 1257 pl->insert (newbook);
1247 1258
1248 pl->contr->play_sound (sound_find ("inscribe_success")); 1259 pl->contr->play_sound (sound_find ("inscribe_success"));
1249 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);
1250 return strlen (msg); 1261 return char_len;
1251 } 1262 }
1252 else 1263 else
1253 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);
1254 1266
1255 return 0; 1267 return 0;
1256} 1268}
1257 1269
1258/* write_scroll() - this routine allows players to inscribe spell scrolls 1270/* write_scroll() - this routine allows players to inscribe spell scrolls
1471 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 1483 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
1472 { 1484 {
1473 /* can't toss invisible or inv-locked items */ 1485 /* can't toss invisible or inv-locked items */
1474 if (tmp->invisible || QUERY_FLAG (tmp, FLAG_INV_LOCKED)) 1486 if (tmp->invisible || QUERY_FLAG (tmp, FLAG_INV_LOCKED))
1475 continue; 1487 continue;
1476 if (!request || !strcmp (query_name (tmp), request) || !strcmp (tmp->name, request)) 1488 if (!request || !strcmp (query_name (tmp), request) || !strcmp (&tmp->name, request))
1477 break; 1489 break;
1478 } 1490 }
1479 } 1491 }
1480 1492
1481 /* this should prevent us from throwing away 1493 /* this should prevent us from throwing away
1712 { 1724 {
1713 throw_ob->last_sp += eff_str / 3; /* fly a little further */ 1725 throw_ob->last_sp += eff_str / 3; /* fly a little further */
1714 throw_ob->stats.dam += throw_ob->inv->stats.dam + throw_ob->magic + 2; 1726 throw_ob->stats.dam += throw_ob->inv->stats.dam + throw_ob->magic + 2;
1715 throw_ob->stats.wc -= throw_ob->magic + throw_ob->inv->stats.wc; 1727 throw_ob->stats.wc -= throw_ob->magic + throw_ob->inv->stats.wc;
1716 /* only throw objects get directional faces */ 1728 /* only throw objects get directional faces */
1717 if (GET_ANIM_ID (throw_ob) && NUM_ANIMATIONS (throw_ob)) 1729 if (throw_ob->has_anim () && throw_ob->anim_frames ())
1718 SET_ANIMATION (throw_ob, dir); 1730 throw_ob->set_anim_frame (dir);
1719 } 1731 }
1720 else 1732 else
1721 { 1733 {
1722 uint16 mat = throw_ob->materials; 1734 uint16 mat = throw_ob->materials;
1723 1735

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines