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

Comparing deliantra/server/server/skill_util.C (file contents):
Revision 1.30 by root, Sun Apr 29 03:44:36 2007 UTC vs.
Revision 1.47 by root, Sun May 13 19:56:57 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 * Copryight (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copryight (C) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
7 * 7 *
44#include <object.h> 44#include <object.h>
45#include <sproto.h> 45#include <sproto.h>
46#include <living.h> /* for defs of STR,CON,DEX,etc. -b.t. */ 46#include <living.h> /* for defs of STR,CON,DEX,etc. -b.t. */
47#include <spells.h> 47#include <spells.h>
48 48
49/* Table of unarmed attack skills. Terminated by -1. This 49const uint8_t skill_flags[NUM_SKILLS] = {
50 * is also the list that we should try to use skills when 50 0, // SK_NONE
51 * automatically applying one for the player. 51# define def(uc, flags) flags,
52 */ 52# include "skillinc.h"
53static uint8 unarmed_skills[] = { 53# undef def
54 SK_KARATE,
55 SK_CLAWING,
56 SK_FLAME_TOUCH,
57 SK_SPARK_TOUCH,
58 SK_SHIVER,
59 SK_ACID_SPLASH,
60 SK_POISON_NAIL,
61 SK_PUNCHING,
62 (uint8)-1
63}; 54};
64 55
65static int attack_hth (object *pl, int dir, const char *string, object *skill); 56static int attack_hth (object *pl, int dir, const char *string, object *skill);
66static int attack_melee_weapon (object *op, int dir, const char *string, object *skill); 57static int attack_melee_weapon (object *op, int dir, const char *string, object *skill);
67 58
70 * subtypes. 61 * subtypes.
71 */ 62 */
72void 63void
73init_skills (void) 64init_skills (void)
74{ 65{
75 int i;
76 archetype *at;
77
78 for (at = first_archetype; at != NULL; at = at->next) 66 for (archetype *at = first_archetype; at; at = at->next)
79 if (at->clone.type == SKILL) 67 if (at->clone.type == SKILL)
80 { 68 {
81 if (skill_names[at->clone.subtype] != NULL) 69 if (skill_names[at->clone.subtype])
82 LOG (llevError, "init_skills: multiple skill using same subtype %d, %s, %s\n", 70 LOG (llevError, "init_skills: multiple skill using same subtype %d, %s, %s\n",
83 at->clone.subtype, &skill_names[at->clone.subtype], &at->clone.skill); 71 at->clone.subtype, &skill_names[at->clone.subtype], &at->clone.skill);
84 else 72 else
85 skill_names[at->clone.subtype] = at->clone.skill; 73 skill_names[at->clone.subtype] = at->clone.skill;
86 } 74 }
87 75
88 /* This isn't really an error if there is no skill subtype set, but 76 /* This isn't really an error if there is no skill subtype set, but
89 * checking for this may catch some user errors. 77 * checking for this may catch some user errors.
90 */ 78 */
91 for (i = 1; i < NUM_SKILLS; i++) 79 for (int i = 1; i < NUM_SKILLS; i++)
92 {
93 if (!skill_names[i]) 80 if (!skill_names[i])
94 LOG (llevError, "init_skills: skill subtype %d doesn't have a name?\n", i); 81 LOG (llevError, "init_skills: skill subtype %d doesn't have a name?\n", i);
95 }
96} 82}
97 83
98/* This function goes through the player inventory and sets 84/* This function goes through the player inventory and sets
99 * up the last_skills[] array in the player object. 85 * up the last_skills[] array in the player object.
100 * the last_skills[] is used to more quickly lookup skills - 86 * the last_skills[] is used to more quickly lookup skills -
129 * tool, this code will equip it. 115 * tool, this code will equip it.
130 */ 116 */
131object * 117object *
132find_skill_by_name (object *who, const char *name) 118find_skill_by_name (object *who, const char *name)
133{ 119{
134 object *skill = NULL, *skill_tool = NULL, *tmp;
135
136 if (!name) 120 if (!name)
137 return NULL; 121 return 0;
122
123 object *skill = 0, *skill_tool = 0;
138 124
139 /* We make sure the length of the string in the object is greater 125 /* We make sure the length of the string in the object is greater
140 * in length than the passed string. Eg, if we have a skill called 126 * in length than the passed string. Eg, if we have a skill called
141 * 'hi', we don't want to match if the user passed 'high' 127 * 'hi', we don't want to match if the user passed 'high'
142 */ 128 */
143 for (tmp = who->inv; tmp != NULL; tmp = tmp->below) 129 for (object *tmp = who->inv; tmp; tmp = tmp->below)
144 { 130 {
145 if (tmp->type == SKILL && !strncasecmp (name, tmp->skill, strlen (name)) && (size_t) strlen (tmp->skill) >= strlen (name)) 131 if (tmp->type == SKILL && !strncasecmp (name, tmp->skill, strlen (name)) && strlen (tmp->skill) >= strlen (name))
146 skill = tmp; 132 skill = tmp;
147 133
148 /* Try to find appropriate skilltool. If the player has one already 134 /* Try to find appropriate skilltool. If the player has one already
149 * applied, we try to keep using that one. 135 * applied, we try to keep using that one.
150 */ 136 */
151 else if (tmp->type == SKILL_TOOL && !strncasecmp (name, tmp->skill, strlen (name)) && (size_t) strlen (tmp->skill) >= strlen (name)) 137 else if (tmp->type == SKILL_TOOL && !strncasecmp (name, tmp->skill, strlen (name)) && strlen (tmp->skill) >= strlen (name))
152 { 138 {
153 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 139 if (QUERY_FLAG (tmp, FLAG_APPLIED))
154 skill_tool = tmp; 140 skill_tool = tmp;
155 else if (!skill_tool || !QUERY_FLAG (skill_tool, FLAG_APPLIED)) 141 else if (!skill_tool || !QUERY_FLAG (skill_tool, FLAG_APPLIED))
156 skill_tool = tmp; 142 skill_tool = tmp;
157 } 143 }
158 } 144 }
145
159 /* If this is a skill that can be used without a tool, return it */ 146 /* If this is a skill that can be used without a tool, return it */
160 if (skill && QUERY_FLAG (skill, FLAG_CAN_USE_SKILL)) 147 if (skill && QUERY_FLAG (skill, FLAG_CAN_USE_SKILL))
161 return skill; 148 return skill;
162 149
163 /* Player has a tool to use the skill. IF not applied, apply it - 150 /* Player has a tool to use the skill. If not applied, apply it -
164 * if not successful, return null. If they do have the skill tool 151 * if not successful, return null. If they do have the skill tool
165 * but not the skill itself, give it to them. 152 * but not the skill itself, give it to them.
166 */ 153 */
167 if (skill_tool) 154 if (skill_tool)
168 { 155 {
169 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) 156 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED))
170 {
171 if (apply_special (who, skill_tool, 0)) 157 if (apply_special (who, skill_tool, 0))
172 return NULL; 158 return 0;
173 } 159
174 if (!skill) 160 if (!skill)
175 { 161 {
176 skill = give_skill_by_name (who, skill_tool->skill); 162 skill = give_skill_by_name (who, skill_tool->skill);
177 link_player_skills (who); 163 link_player_skills (who);
178 } 164 }
165
179 return skill; 166 return skill;
180 } 167 }
168
181 return NULL; 169 return 0;
182} 170}
183
184 171
185/* This returns the skill pointer of the given name (the 172/* This returns the skill pointer of the given name (the
186 * one that accumlates exp, has the level, etc). 173 * one that accumlates exp, has the level, etc).
187 * 174 *
188 * It is presumed that the player will be needing to actually 175 * It is presumed that the player will be needing to actually
194 * this replaces find_skill. 181 * this replaces find_skill.
195 */ 182 */
196object * 183object *
197find_skill_by_number (object *who, int skillno) 184find_skill_by_number (object *who, int skillno)
198{ 185{
186 if (!IN_RANGE_EXC (skillno, 1, NUM_SKILLS))
187 return 0;
188
199 object *skill = NULL, *skill_tool = NULL, *tmp; 189 object *skill = NULL, *skill_tool = NULL;
200 190
201 if (skillno < 1 || skillno >= NUM_SKILLS)
202 return NULL;
203
204 for (tmp = who->inv; tmp != NULL; tmp = tmp->below) 191 for (object *tmp = who->inv; tmp; tmp = tmp->below)
205 { 192 {
206 if (tmp->type == SKILL && tmp->subtype == skillno) 193 if (tmp->type == SKILL && tmp->subtype == skillno)
207 skill = tmp; 194 skill = tmp;
208 195
209 /* Try to find appropriate skilltool. If the player has one already 196 /* Try to find appropriate skilltool. If the player has one already
215 skill_tool = tmp; 202 skill_tool = tmp;
216 else if (!skill_tool || !QUERY_FLAG (skill_tool, FLAG_APPLIED)) 203 else if (!skill_tool || !QUERY_FLAG (skill_tool, FLAG_APPLIED))
217 skill_tool = tmp; 204 skill_tool = tmp;
218 } 205 }
219 } 206 }
207
220 /* If this is a skill that can be used without a tool, return it */ 208 /* If this is a skill that can be used without a tool, return it */
221 if (skill && QUERY_FLAG (skill, FLAG_CAN_USE_SKILL)) 209 if (skill && QUERY_FLAG (skill, FLAG_CAN_USE_SKILL))
222 return skill; 210 return skill;
223 211
224 /* Player has a tool to use the skill. IF not applied, apply it - 212 /* Player has a tool to use the skill. If not applied, apply it -
225 * if not successful, return null. If they do have the skill tool 213 * if not successful, return null. If they do have the skill tool
226 * but not the skill itself, give it to them. 214 * but not the skill itself, give it to them.
227 */ 215 */
228 if (skill_tool) 216 if (skill_tool)
229 { 217 {
230 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) 218 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED))
246} 234}
247 235
248/* This changes the objects skill to new_skill. 236/* This changes the objects skill to new_skill.
249 * note that this function doesn't always need to get used - 237 * note that this function doesn't always need to get used -
250 * you can now add skill exp to the player without the chosen_skill being 238 * you can now add skill exp to the player without the chosen_skill being
251 * set. This function is of most interest to players to update 239 * set. This function is of most interest to players to update
252 * the various range information. 240 * the various range information.
253 * if new_skill is null, this just unapplies the skill.
254 * flag has the current meaning:
255 * 0x1: If set, don't update the range pointer. This is useful when we
256 * need to ready a new skill, but don't want to clobber range.
257 * return 1 on success, 0 on error 241 * return 1 on success, 0 on error
258 */ 242 */
259
260int 243int
261change_skill (object *who, object *new_skill, int flag) 244change_skill (object *who, object *new_skill, int flag)
262{ 245{
263 int old_range;
264
265 if (who->type != PLAYER) 246 if (who->type != PLAYER)
266 return 0; 247 return 0;
267 248
268 old_range = who->contr->shoottype; 249#if 0
269 250 // optimise this supposedly common case
270 if (who->chosen_skill && who->chosen_skill == new_skill)
271 {
272 /* optimization for changing skill to current skill */
273 if (who->type == PLAYER && !(flag & 0x1))
274 who->contr->shoottype = range_skill;
275
276 return 1;
277 }
278
279 // move skill to front, so it will be preferred next time
280 new_skill->remove ();
281 who->insert (new_skill);
282
283 if (!new_skill || who->chosen_skill) 251 if (new_skill == who->chosen_skill)
284 if (who->chosen_skill) 252 return 1;
285 apply_special (who, who->chosen_skill, AP_UNAPPLY); 253#endif
286 254
287 /* Only goal in this case was to unapply a skill */
288 if (!new_skill) 255 if (!new_skill)
256 {
257 LOG (llevError | logBacktrace, "change_skill called on %s with NULL skill\n",
258 who->debug_desc ());
289 return 0; 259 return 0;
260 }
261
262 // the skill could be readied already because it is used by a weapon.
263 who->change_weapon (0);
264 new_skill->inv_splay ();
290 265
291 if (apply_special (who, new_skill, AP_APPLY)) 266 if (apply_special (who, new_skill, AP_APPLY))
292 return 0; 267 return 0;
293 268
294 if (flag & 0x1)
295 who->contr->shoottype = (rangetype)old_range;
296
297 return 1; 269 return 1;
298} 270}
299 271
300/* This function just clears the chosen_skill and range_skill values 272/* This function just clears the chosen_skill and range_skill values
301 * inthe player. 273 * in the player.
302 */ 274 */
303void 275void
304clear_skill (object *who) 276clear_skill (object *who)
305{ 277{
306 who->chosen_skill = NULL; 278 who->chosen_skill = 0;
307 CLEAR_FLAG (who, FLAG_READY_SKILL); 279 CLEAR_FLAG (who, FLAG_READY_SKILL);
280
308 if (who->type == PLAYER) 281 if (who->type == PLAYER)
309 { 282 if (who->contr->ranged_ob && who->contr->ranged_ob->type == SKILL)
310 who->contr->ranges[range_skill] = NULL; 283 who->contr->ranged_ob = 0;
311 if (who->contr->shoottype == range_skill)
312 who->contr->shoottype = range_none;
313 }
314} 284}
315 285
316/* do_skill() - Main skills use function-similar in scope to cast_spell(). 286/* do_skill() - Main skills use function-similar in scope to cast_spell().
317 * We handle all requests for skill use outside of some combat here. 287 * We handle all requests for skill use outside of some combat here.
318 * We require a separate routine outside of fire() so as to allow monsters 288 * We require a separate routine outside of fire() so as to allow monsters
321 * exp - no caller needed that info, but it also prevented the callers 291 * exp - no caller needed that info, but it also prevented the callers
322 * from know if a skill was actually used, as many skills don't 292 * from know if a skill was actually used, as many skills don't
323 * give any exp for their direct use (eg, throwing). 293 * give any exp for their direct use (eg, throwing).
324 * It returns 0 if no skill was used. 294 * It returns 0 if no skill was used.
325 */ 295 */
326
327int 296int
328do_skill (object *op, object *part, object *skill, int dir, const char *string) 297do_skill (object *op, object *part, object *skill, int dir, const char *string)
329{ 298{
330 int success = 0, exp = 0; 299 int success = 0, exp = 0;
331 int did_alc = 0; 300 int did_alc = 0;
332 object *tmp, *next;
333 301
334 if (!skill) 302 if (!skill)
335 return 0; 303 return 0;
336 304
337 /* The code below presumes that the skill points to the object that 305 /* The code below presumes that the skill points to the object that
339 * go and try to find the actual real skill pointer, and if the 307 * go and try to find the actual real skill pointer, and if the
340 * the player doesn't have a bucket for that, create one. 308 * the player doesn't have a bucket for that, create one.
341 */ 309 */
342 if (skill->type != SKILL && op->type == PLAYER) 310 if (skill->type != SKILL && op->type == PLAYER)
343 { 311 {
344 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 312 for (object *tmp = op->inv; tmp; tmp = tmp->below)
345 if (tmp->type == SKILL && tmp->skill == skill->skill) 313 if (tmp->type == SKILL && tmp->skill == skill->skill)
346 break; 314 {
315 skill = tmp;
316 goto found;
317 }
347 318
348 if (!tmp)
349 tmp = give_skill_by_name (op, skill->skill); 319 skill = give_skill_by_name (op, skill->skill);
350 320found: ;
351 skill = tmp;
352 } 321 }
353 322
354 // skill, by_whom, on_which_object, which direction, skill_argument 323 // skill, by_whom, on_which_object, which direction, skill_argument
355 if (INVOKE_OBJECT (USE_SKILL, skill, ARG_OBJECT (op), ARG_OBJECT (part), ARG_INT (dir), ARG_STRING (string))) 324 if (INVOKE_OBJECT (USE_SKILL, skill, ARG_OBJECT (op), ARG_OBJECT (part), ARG_INT (dir), ARG_STRING (string)))
356 return 0; 325 return 0;
461 case SK_LITERACY: 430 case SK_LITERACY:
462 case SK_WOODSMAN: 431 case SK_WOODSMAN:
463 /* first, we try to find a cauldron, and do the alchemy thing. 432 /* first, we try to find a cauldron, and do the alchemy thing.
464 * failing that, we go and identify stuff. 433 * failing that, we go and identify stuff.
465 */ 434 */
466 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = next) 435 for (object *next, *tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = next)
467 { 436 {
468 next = tmp->above; 437 next = tmp->above;
469 438
470 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) 439 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON))
471 { 440 {
532 * If certain skills should take more/less time, that should be 501 * If certain skills should take more/less time, that should be
533 * in the code for the skill itself. 502 * in the code for the skill itself.
534 */ 503 */
535 504
536 if (op->type == PLAYER) 505 if (op->type == PLAYER)
537 op->speed_left -= 1.0; 506 op->speed_left -= 1.f;
538 507
539 /* this is a good place to add experience for successfull use of skills. 508 /* this is a good place to add experience for successfull use of skills.
540 * Note that add_exp() will figure out player/monster experience 509 * Note that add_exp() will figure out player/monster experience
541 * gain problems. 510 * gain problems.
542 */ 511 */
570 * op is the object that was 'defeated'. 539 * op is the object that was 'defeated'.
571 * skill is the skill used. If no skill is used, it should just 540 * skill is the skill used. If no skill is used, it should just
572 * point back to who. 541 * point back to who.
573 * 542 *
574 */ 543 */
575
576int 544int
577calc_skill_exp (object *who, object *op, object *skill) 545calc_skill_exp (object *who, object *op, object *skill)
578{ 546{
579 int op_exp = 0, op_lvl = 0; 547 int op_exp = 0, op_lvl = 0;
580 float base, value, lvl_mult = 0.0; 548 float base, value, lvl_mult = 0.0;
669 * This one actually teaches the player the skill as something 637 * This one actually teaches the player the skill as something
670 * they can equip. 638 * they can equip.
671 * Return 0 if the player knows the skill, 1 if the 639 * Return 0 if the player knows the skill, 1 if the
672 * player learns the skill, 2 otherwise. 640 * player learns the skill, 2 otherwise.
673 */ 641 */
674
675int 642int
676learn_skill (object *pl, object *scroll) 643learn_skill (object *pl, object *scroll)
677{ 644{
678 object *tmp; 645 object *tmp;
679 646
715 link_player_skills (pl); 682 link_player_skills (pl);
716 return 1; 683 return 1;
717} 684}
718 685
719/* Gives a percentage clipped to 0% -> 100% of a/b. */ 686/* Gives a percentage clipped to 0% -> 100% of a/b. */
720
721/* Probably belongs in some global utils-type file? */ 687/* Probably belongs in some global utils-type file? */
722static int 688static int
723clipped_percent (sint64 a, sint64 b) 689clipped_percent (sint64 a, sint64 b)
724{ 690{
725 int rv; 691 int rv;
818 * direction that the user is facing. Returns false if we are unable to 784 * direction that the user is facing. Returns false if we are unable to
819 * change to the requested skill, or were unable to use the skill properly. 785 * change to the requested skill, or were unable to use the skill properly.
820 * This is tricky because skills can have spaces. We basically roll 786 * This is tricky because skills can have spaces. We basically roll
821 * our own find_skill_by_name so we can try to do better string matching. 787 * our own find_skill_by_name so we can try to do better string matching.
822 */ 788 */
823
824int 789int
825use_skill (object *op, const char *string) 790use_skill (object *op, const char *string)
826{ 791{
827 object *skop; 792 object *skop;
828 size_t len; 793 size_t len;
876} 841}
877 842
878static bool 843static bool
879hth_skill_p (object *skill) 844hth_skill_p (object *skill)
880{ 845{
881 for (unsigned int i = 0; i < sizeof (unarmed_skills); ++i) 846 return (skill_flags [skill->subtype] & (SF_COMBAT | SF_NEED_WEAPON)) == SF_COMBAT;
882 if (skill->subtype == unarmed_skills[i])
883 return 1;
884
885 return 0;
886} 847}
887 848
888/* This finds the first unarmed skill the player has, and returns it. 849/* This finds the first unarmed skill the player has, and returns it.
889 */ 850 */
890static object * 851static object *
907 * the damage. 868 * the damage.
908 */ 869 */
909static int 870static int
910do_skill_attack (object *tmp, object *op, const char *string, object *skill) 871do_skill_attack (object *tmp, object *op, const char *string, object *skill)
911{ 872{
912 int success;
913
914 if (INVOKE_OBJECT (SKILL_ATTACK, op, ARG_OBJECT (tmp), ARG_STRING (string), ARG_OBJECT (skill))) 873 if (INVOKE_OBJECT (SKILL_ATTACK, op, ARG_OBJECT (tmp), ARG_STRING (string), ARG_OBJECT (skill)))
915 return RESULT_INT (0); 874 return RESULT_INT (0);
916 875
917 /* For Players only: if there is no ready weapon, and no "attack" skill 876 /* For Players only: if there is no ready weapon, and no "attack" skill
918 * is readied either then try to find a skill for the player to use. 877 * is readied either then try to find a skill for the player to use.
919 * it is presumed that if skill is set, it is a valid attack skill (eg, 878 * it is presumed that if skill is set, it is a valid attack skill (eg,
920 * the caller should have set it appropriately). We still want to pass 879 * the caller should have set it appropriately). We still want to pass
921 * through that code if skill is set to change to the skill. 880 * through that code if skill is set to change to the skill.
922 */ 881 */
923 if (op->type == PLAYER) 882 if (player *pl = op->contr)
924 { 883 {
925 if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) 884 if (!pl->combat_ob)
926 { 885 {
927 if (!skill) 886 if (QUERY_FLAG (op, FLAG_READY_WEAPON))
928 { 887 {
929 /* See if the players chosen skill is a combat skill, and use 888 for (tmp = op->inv; tmp; tmp = tmp->below)
930 * it if appropriate. 889 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_APPLIED))
931 */ 890 break;
932 if (op->chosen_skill && hth_skill_p (op->chosen_skill)) 891
933 skill = op->chosen_skill; 892 if (!tmp)
934 else
935 { 893 {
936 skill = find_player_hth_skill (op); 894 LOG (llevError, "Could not find applied weapon on %s\n", &op->name);
895 return 0;
896 }
937 897
898 change_skill (op, find_skill_by_name (op, tmp->skill), 1);
899 }
900 else
901 {
938 if (!skill) 902 if (!skill)
903 {
904 /* See if the players chosen skill is a combat skill, and use
905 * it if appropriate.
906 */
907 if (op->chosen_skill && hth_skill_p (op->chosen_skill))
908 skill = op->chosen_skill;
909 else
939 { 910 {
911 skill = find_player_hth_skill (op);
912
913 if (!skill)
914 {
940 new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!"); 915 new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!");
941 return 0; 916 return 0;
917 }
942 } 918 }
943 } 919 }
920
921 /* now try to ready the new skill */
922 if (!change_skill (op, skill, 0))
923 { /* oh oh, trouble! */
924 new_draw_info_format (NDI_UNIQUE, 0, op, "Couldn't change to skill %s", &skill->name);
925 return 0;
926 }
944 } 927 }
945 928
946 /* now try to ready the new skill */ 929 if (!pl->combat_ob)
947 if (!change_skill (op, skill, 0)) 930 {
948 { /* oh oh, trouble! */ 931 LOG (llevError, "Could not find anything to attack on %s\n", &op->name);
949 new_draw_info_format (NDI_UNIQUE, 0, tmp, "Couldn't change to skill %s", &skill->name);
950 return 0; 932 return 0;
951 } 933 }
952 } 934 }
953 else 935
936 if (!op->change_weapon (pl->combat_ob))
937 return 0;
938
939 /* lose invisiblity/hiding status for running attacks */
940 if (pl->tmp_invis)
954 { 941 {
955 /* Seen some crashes below where current_weapon is not set, 942 pl->tmp_invis = 0;
956 * even though the flag says it is. So if current weapon isn't set, 943 op->invisible = 0;
957 * do some work in trying to find the object to use. 944 op->hide = 0;
958 */ 945 update_object (op, UP_OBJ_CHANGE);
959 if (!op->current_weapon)
960 {
961 object *tmp;
962
963 LOG (llevError, "Player %s does not have current weapon set but flag_ready_weapon is set\n", &op->name);
964 for (tmp = op->inv; tmp; tmp = tmp->below)
965 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_APPLIED))
966 break;
967
968 if (!tmp)
969 {
970 LOG (llevError, "Could not find applied weapon on %s\n", &op->name);
971 op->current_weapon = NULL;
972 return 0;
973 }
974 else
975 {
976 op->current_weapon = tmp;
977 }
978 }
979
980 change_skill (op, find_skill_by_name (op, op->current_weapon->skill), 1);
981 } 946 }
982 } 947 }
983 948
984 /* lose invisiblity/hiding status for running attacks */
985
986 if (op->type == PLAYER && op->contr->tmp_invis)
987 {
988 op->contr->tmp_invis = 0;
989 op->invisible = 0;
990 op->hide = 0;
991 update_object (op, UP_OBJ_CHANGE);
992 }
993
994 success = attack_ob (tmp, op); 949 int success = attack_ob (tmp, op);
995 950
996 /* print appropriate messages to the player */ 951 /* print appropriate messages to the player */
997 952
998 if (success && string != NULL && tmp && !QUERY_FLAG (tmp, FLAG_FREED)) 953 if (success && string && tmp && !QUERY_FLAG (tmp, FLAG_FREED))
999 { 954 {
1000 if (op->type == PLAYER) 955 if (op->type == PLAYER)
1001 new_draw_info_format (NDI_UNIQUE, 0, op, "You %s %s!", string, query_name (tmp)); 956 new_draw_info_format (NDI_UNIQUE, 0, op, "You %s %s!", string, query_name (tmp));
1002 else if (tmp->type == PLAYER) 957 else if (tmp->type == PLAYER)
1003 new_draw_info_format (NDI_UNIQUE, 0, tmp, "%s %s you!", query_name (op), string); 958 new_draw_info_format (NDI_UNIQUE, 0, tmp, "%s %s you!", query_name (op), string);
1031 ty = freearr_y[dir]; 986 ty = freearr_y[dir];
1032 987
1033 /* If we don't yet have an opponent, find if one exists, and attack. 988 /* If we don't yet have an opponent, find if one exists, and attack.
1034 * Legal opponents are the same as outlined in move_player_attack() 989 * Legal opponents are the same as outlined in move_player_attack()
1035 */ 990 */
1036 991 if (!tmp)
1037 if (tmp == NULL)
1038 { 992 {
1039 m = pl->map; 993 m = pl->map;
1040 tx = pl->x + freearr_x[dir]; 994 tx = pl->x + freearr_x[dir];
1041 ty = pl->y + freearr_y[dir]; 995 ty = pl->y + freearr_y[dir];
1042 996
1052 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->stats.hp >= 0) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || tmp->type == LOCKED_DOOR) 1006 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->stats.hp >= 0) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || tmp->type == LOCKED_DOOR)
1053 { 1007 {
1054 /* Don't attack party members */ 1008 /* Don't attack party members */
1055 if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party)) 1009 if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party))
1056 return 0; 1010 return 0;
1011
1057 break; 1012 break;
1058 } 1013 }
1059 } 1014 }
1015
1060 if (!tmp) 1016 if (!tmp)
1061 { 1017 {
1062 if (pl->type == PLAYER) 1018 if (pl->type == PLAYER)
1063 new_draw_info (NDI_UNIQUE, 0, pl, "There is nothing to attack!"); 1019 new_draw_info (NDI_UNIQUE, 0, pl, "There is nothing to attack!");
1020
1064 return 0; 1021 return 0;
1065 } 1022 }
1066 1023
1067 return do_skill_attack (tmp, pl, string, skill); 1024 return do_skill_attack (tmp, pl, string, skill);
1068} 1025}
1069
1070 1026
1071/* attack_hth() - this handles all hand-to-hand attacks -b.t. */ 1027/* attack_hth() - this handles all hand-to-hand attacks -b.t. */
1072 1028
1073/* July 5, 1995 - I broke up attack_hth() into 2 parts. In the first 1029/* July 5, 1995 - I broke up attack_hth() into 2 parts. In the first
1074 * (attack_hth) we check for weapon use, etc in the second (the new 1030 * (attack_hth) we check for weapon use, etc in the second (the new
1075 * function skill_attack() we actually attack. 1031 * function skill_attack() we actually attack.
1076 */ 1032 */
1077
1078static int 1033static int
1079attack_hth (object *pl, int dir, const char *string, object *skill) 1034attack_hth (object *pl, int dir, const char *string, object *skill)
1080{ 1035{
1081 object *enemy = NULL, *weapon; 1036 object *enemy = NULL, *weapon;
1082 1037
1091 if (pl->type == PLAYER) 1046 if (pl->type == PLAYER)
1092 { 1047 {
1093 new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack."); 1048 new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack.");
1094 esrv_update_item (UPD_FLAGS, pl, weapon); 1049 esrv_update_item (UPD_FLAGS, pl, weapon);
1095 } 1050 }
1051
1096 break; 1052 break;
1097 } 1053 }
1098 } 1054 }
1099 1055
1100 return skill_attack (enemy, pl, dir, string, skill); 1056 return skill_attack (enemy, pl, dir, string, skill);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines