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.32 by root, Sun Apr 29 21:44:35 2007 UTC vs.
Revision 1.33 by root, Mon Apr 30 04:25:30 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# define def(uc, flags) flags,
51 * automatically applying one for the player. 51# include "skillinc.h"
52 */ 52# undef def
53static uint8 unarmed_skills[] = {
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}; 53};
64 54
65static int attack_hth (object *pl, int dir, const char *string, object *skill); 55static 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); 56static int attack_melee_weapon (object *op, int dir, const char *string, object *skill);
67 57
70 * subtypes. 60 * subtypes.
71 */ 61 */
72void 62void
73init_skills (void) 63init_skills (void)
74{ 64{
75 int i;
76 archetype *at;
77
78 for (at = first_archetype; at != NULL; at = at->next) 65 for (archetype *at = first_archetype; at; at = at->next)
79 if (at->clone.type == SKILL) 66 if (at->clone.type == SKILL)
80 { 67 {
81 if (skill_names[at->clone.subtype] != NULL) 68 if (skill_names[at->clone.subtype])
82 LOG (llevError, "init_skills: multiple skill using same subtype %d, %s, %s\n", 69 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); 70 at->clone.subtype, &skill_names[at->clone.subtype], &at->clone.skill);
84 else 71 else
85 skill_names[at->clone.subtype] = at->clone.skill; 72 skill_names[at->clone.subtype] = at->clone.skill;
86 } 73 }
87 74
88 /* This isn't really an error if there is no skill subtype set, but 75 /* This isn't really an error if there is no skill subtype set, but
89 * checking for this may catch some user errors. 76 * checking for this may catch some user errors.
90 */ 77 */
91 for (i = 1; i < NUM_SKILLS; i++) 78 for (int i = 1; i < NUM_SKILLS; i++)
92 {
93 if (!skill_names[i]) 79 if (!skill_names[i])
94 LOG (llevError, "init_skills: skill subtype %d doesn't have a name?\n", i); 80 LOG (llevError, "init_skills: skill subtype %d doesn't have a name?\n", i);
95 }
96} 81}
97 82
98/* This function goes through the player inventory and sets 83/* This function goes through the player inventory and sets
99 * up the last_skills[] array in the player object. 84 * up the last_skills[] array in the player object.
100 * the last_skills[] is used to more quickly lookup skills - 85 * the last_skills[] is used to more quickly lookup skills -
169 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) 154 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED))
170 { 155 {
171 if (apply_special (who, skill_tool, 0)) 156 if (apply_special (who, skill_tool, 0))
172 return NULL; 157 return NULL;
173 } 158 }
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 NULL;
182} 170}
183 171
184 172
185/* This returns the skill pointer of the given name (the 173/* This returns the skill pointer of the given name (the
262 int old_range; 250 int old_range;
263 251
264 if (who->type != PLAYER) 252 if (who->type != PLAYER)
265 return 0; 253 return 0;
266 254
267 old_range = who->contr->shoottype;
268
269 if (who->chosen_skill && who->chosen_skill == new_skill) 255 if (who->chosen_skill && who->chosen_skill == new_skill)
270 { 256 {
271 /* optimization for changing skill to current skill */ 257 //who->contr->combat_skill = who->chosen_skill;
272 if (!(flag & 0x1))
273 who->contr->set_range (range_skill);
274
275 return 1; 258 return 1;
259 }
260
261 if (!new_skill)
262 {
263 if (who->chosen_skill)
264 apply_special (who, who->chosen_skill, AP_UNAPPLY);
265
266 /* Only goal in this case was to unapply a skill */
267 return 0;
276 } 268 }
277 269
278 // move skill to front, so it will be preferred next time 270 // move skill to front, so it will be preferred next time
279 new_skill->remove (); 271 new_skill->remove ();
280 who->insert (new_skill); 272 who->insert (new_skill);
281 273
282 if (!new_skill)
283 {
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 return 0;
289 }
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->set_range ((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.
569 * op is the object that was 'defeated'. 552 * op is the object that was 'defeated'.
570 * 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
571 * point back to who. 554 * point back to who.
572 * 555 *
573 */ 556 */
574
575int 557int
576calc_skill_exp (object *who, object *op, object *skill) 558calc_skill_exp (object *who, object *op, object *skill)
577{ 559{
578 int op_exp = 0, op_lvl = 0; 560 int op_exp = 0, op_lvl = 0;
579 float base, value, lvl_mult = 0.0; 561 float base, value, lvl_mult = 0.0;
668 * This one actually teaches the player the skill as something 650 * This one actually teaches the player the skill as something
669 * they can equip. 651 * they can equip.
670 * Return 0 if the player knows the skill, 1 if the 652 * Return 0 if the player knows the skill, 1 if the
671 * player learns the skill, 2 otherwise. 653 * player learns the skill, 2 otherwise.
672 */ 654 */
673
674int 655int
675learn_skill (object *pl, object *scroll) 656learn_skill (object *pl, object *scroll)
676{ 657{
677 object *tmp; 658 object *tmp;
678 659
875} 856}
876 857
877static bool 858static bool
878hth_skill_p (object *skill) 859hth_skill_p (object *skill)
879{ 860{
880 for (unsigned int i = 0; i < sizeof (unarmed_skills); ++i) 861 return (skill_flags [skill->subtype] & (SF_COMBAT | SF_NEED_WEAPON)) == SF_COMBAT;
881 if (skill->subtype == unarmed_skills[i])
882 return 1;
883
884 return 0;
885} 862}
886 863
887/* 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.
888 */ 865 */
889static object * 866static object *

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines