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.34 by root, Mon Apr 30 05:54:14 2007 UTC

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 -
169 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) 155 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED))
170 { 156 {
171 if (apply_special (who, skill_tool, 0)) 157 if (apply_special (who, skill_tool, 0))
172 return NULL; 158 return NULL;
173 } 159 }
160
174 if (!skill) 161 if (!skill)
175 { 162 {
176 skill = give_skill_by_name (who, skill_tool->skill); 163 skill = give_skill_by_name (who, skill_tool->skill);
177 link_player_skills (who); 164 link_player_skills (who);
178 } 165 }
166
179 return skill; 167 return skill;
180 } 168 }
169
181 return NULL; 170 return NULL;
182} 171}
183 172
184 173
185/* This returns the skill pointer of the given name (the 174/* This returns the skill pointer of the given name (the
254 * flag has the current meaning: 243 * flag has the current meaning:
255 * 0x1: If set, don't update the range pointer. This is useful when we 244 * 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. 245 * need to ready a new skill, but don't want to clobber range.
257 * return 1 on success, 0 on error 246 * return 1 on success, 0 on error
258 */ 247 */
259
260int 248int
261change_skill (object *who, object *new_skill, int flag) 249change_skill (object *who, object *new_skill, int flag)
262{ 250{
263 int old_range; 251 int old_range;
264 252
265 if (who->type != PLAYER) 253 if (who->type != PLAYER)
266 return 0; 254 return 0;
267 255
268 old_range = who->contr->shoottype; 256 player *pl = who->contr;
269 257
270 if (who->chosen_skill && who->chosen_skill == new_skill) 258 if (pl->ranged_skill && pl->ranged_skill == new_skill)
271 { 259 return 1;
272 /* optimization for changing skill to current skill */
273 if (who->type == PLAYER && !(flag & 0x1))
274 who->contr->shoottype = range_skill;
275 260
261 if (!new_skill)
262 {
263 if (pl->ranged_skill)
264 apply_special (who, pl->ranged_skill, AP_UNAPPLY);
265
266 /* Only goal in this case was to unapply a skill */
276 return 1; 267 return 0;
277 } 268 }
278 269
279 // move skill to front, so it will be preferred next time 270 // move skill to front, so it will be preferred next time
280 new_skill->remove (); 271 new_skill->remove ();
281 who->insert (new_skill); 272 who->insert (new_skill);
282 273
283 if (!new_skill || who->chosen_skill)
284 if (who->chosen_skill)
285 apply_special (who, who->chosen_skill, AP_UNAPPLY);
286
287 /* Only goal in this case was to unapply a skill */
288 if (!new_skill)
289 return 0;
290
291 if (apply_special (who, new_skill, AP_APPLY)) 274 if (apply_special (who, new_skill, AP_APPLY))
292 return 0; 275 return 0;
293 276
294 if (flag & 0x1)
295 who->contr->shoottype = (rangetype)old_range;
296
297 return 1; 277 return 1;
298} 278}
299 279
300/* This function just clears the chosen_skill and range_skill values 280/* This function just clears the chosen_skill and range_skill values
301 * inthe player. 281 * in the player.
302 */ 282 */
303void 283void
304clear_skill (object *who) 284clear_skill (object *who)
305{ 285{
306 who->chosen_skill = NULL; 286 who->chosen_skill = 0;
307 CLEAR_FLAG (who, FLAG_READY_SKILL); 287 CLEAR_FLAG (who, FLAG_READY_SKILL);
288
308 if (who->type == PLAYER) 289 if (who->type == PLAYER)
309 { 290 {
291 if (who->contr->ranged_skill && who->contr->ranged_skill->type == SKILL)
292 {
310 who->contr->ranges[range_skill] = NULL; 293 who->contr->ranged_skill = 0;
311 if (who->contr->shoottype == range_skill) 294 who->contr->ranged_ob = 0;
312 who->contr->shoottype = range_none; 295 }
313 } 296 }
314} 297}
315 298
316/* do_skill() - Main skills use function-similar in scope to cast_spell(). 299/* 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. 300 * We handle all requests for skill use outside of some combat here.
321 * exp - no caller needed that info, but it also prevented the callers 304 * 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 305 * from know if a skill was actually used, as many skills don't
323 * give any exp for their direct use (eg, throwing). 306 * give any exp for their direct use (eg, throwing).
324 * It returns 0 if no skill was used. 307 * It returns 0 if no skill was used.
325 */ 308 */
326
327int 309int
328do_skill (object *op, object *part, object *skill, int dir, const char *string) 310do_skill (object *op, object *part, object *skill, int dir, const char *string)
329{ 311{
330 int success = 0, exp = 0; 312 int success = 0, exp = 0;
331 int did_alc = 0; 313 int did_alc = 0;
570 * op is the object that was 'defeated'. 552 * op is the object that was 'defeated'.
571 * skill is the skill used. If no skill is used, it should just 553 * skill is the skill used. If no skill is used, it should just
572 * point back to who. 554 * point back to who.
573 * 555 *
574 */ 556 */
575
576int 557int
577calc_skill_exp (object *who, object *op, object *skill) 558calc_skill_exp (object *who, object *op, object *skill)
578{ 559{
579 int op_exp = 0, op_lvl = 0; 560 int op_exp = 0, op_lvl = 0;
580 float base, value, lvl_mult = 0.0; 561 float base, value, lvl_mult = 0.0;
669 * This one actually teaches the player the skill as something 650 * This one actually teaches the player the skill as something
670 * they can equip. 651 * they can equip.
671 * Return 0 if the player knows the skill, 1 if the 652 * Return 0 if the player knows the skill, 1 if the
672 * player learns the skill, 2 otherwise. 653 * player learns the skill, 2 otherwise.
673 */ 654 */
674
675int 655int
676learn_skill (object *pl, object *scroll) 656learn_skill (object *pl, object *scroll)
677{ 657{
678 object *tmp; 658 object *tmp;
679 659
876} 856}
877 857
878static bool 858static bool
879hth_skill_p (object *skill) 859hth_skill_p (object *skill)
880{ 860{
881 for (unsigned int i = 0; i < sizeof (unarmed_skills); ++i) 861 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} 862}
887 863
888/* This finds the first unarmed skill the player has, and returns it. 864/* This finds the first unarmed skill the player has, and returns it.
889 */ 865 */
890static object * 866static object *
907 * the damage. 883 * the damage.
908 */ 884 */
909static int 885static int
910do_skill_attack (object *tmp, object *op, const char *string, object *skill) 886do_skill_attack (object *tmp, object *op, const char *string, object *skill)
911{ 887{
912 int success;
913
914 if (INVOKE_OBJECT (SKILL_ATTACK, op, ARG_OBJECT (tmp), ARG_STRING (string), ARG_OBJECT (skill))) 888 if (INVOKE_OBJECT (SKILL_ATTACK, op, ARG_OBJECT (tmp), ARG_STRING (string), ARG_OBJECT (skill)))
915 return RESULT_INT (0); 889 return RESULT_INT (0);
916 890
917 /* For Players only: if there is no ready weapon, and no "attack" skill 891 /* 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. 892 * is readied either then try to find a skill for the player to use.
970 LOG (llevError, "Could not find applied weapon on %s\n", &op->name); 944 LOG (llevError, "Could not find applied weapon on %s\n", &op->name);
971 op->current_weapon = NULL; 945 op->current_weapon = NULL;
972 return 0; 946 return 0;
973 } 947 }
974 else 948 else
975 {
976 op->current_weapon = tmp; 949 op->current_weapon = tmp;
977 }
978 } 950 }
979 951
980 change_skill (op, find_skill_by_name (op, op->current_weapon->skill), 1); 952 change_skill (op, find_skill_by_name (op, op->current_weapon->skill), 1);
981 } 953 }
982 } 954 }
989 op->invisible = 0; 961 op->invisible = 0;
990 op->hide = 0; 962 op->hide = 0;
991 update_object (op, UP_OBJ_CHANGE); 963 update_object (op, UP_OBJ_CHANGE);
992 } 964 }
993 965
994 success = attack_ob (tmp, op); 966 int success = attack_ob (tmp, op);
995 967
996 /* print appropriate messages to the player */ 968 /* print appropriate messages to the player */
997 969
998 if (success && string != NULL && tmp && !QUERY_FLAG (tmp, FLAG_FREED)) 970 if (success && string && tmp && !QUERY_FLAG (tmp, FLAG_FREED))
999 { 971 {
1000 if (op->type == PLAYER) 972 if (op->type == PLAYER)
1001 new_draw_info_format (NDI_UNIQUE, 0, op, "You %s %s!", string, query_name (tmp)); 973 new_draw_info_format (NDI_UNIQUE, 0, op, "You %s %s!", string, query_name (tmp));
1002 else if (tmp->type == PLAYER) 974 else if (tmp->type == PLAYER)
1003 new_draw_info_format (NDI_UNIQUE, 0, tmp, "%s %s you!", query_name (op), string); 975 new_draw_info_format (NDI_UNIQUE, 0, tmp, "%s %s you!", query_name (op), string);
1031 ty = freearr_y[dir]; 1003 ty = freearr_y[dir];
1032 1004
1033 /* If we don't yet have an opponent, find if one exists, and attack. 1005 /* 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() 1006 * Legal opponents are the same as outlined in move_player_attack()
1035 */ 1007 */
1036 1008 if (!tmp)
1037 if (tmp == NULL)
1038 { 1009 {
1039 m = pl->map; 1010 m = pl->map;
1040 tx = pl->x + freearr_x[dir]; 1011 tx = pl->x + freearr_x[dir];
1041 ty = pl->y + freearr_y[dir]; 1012 ty = pl->y + freearr_y[dir];
1042 1013
1052 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->stats.hp >= 0) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || tmp->type == LOCKED_DOOR) 1023 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->stats.hp >= 0) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || tmp->type == LOCKED_DOOR)
1053 { 1024 {
1054 /* Don't attack party members */ 1025 /* Don't attack party members */
1055 if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party)) 1026 if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party))
1056 return 0; 1027 return 0;
1028
1057 break; 1029 break;
1058 } 1030 }
1059 } 1031 }
1032
1060 if (!tmp) 1033 if (!tmp)
1061 { 1034 {
1062 if (pl->type == PLAYER) 1035 if (pl->type == PLAYER)
1063 new_draw_info (NDI_UNIQUE, 0, pl, "There is nothing to attack!"); 1036 new_draw_info (NDI_UNIQUE, 0, pl, "There is nothing to attack!");
1037
1064 return 0; 1038 return 0;
1065 } 1039 }
1066 1040
1067 return do_skill_attack (tmp, pl, string, skill); 1041 return do_skill_attack (tmp, pl, string, skill);
1068} 1042}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines