| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "global.h" |
| 20 |
|
| 21 |
#include <stdlib.h> |
| 22 |
#include <string.h> |
| 23 |
|
| 24 |
#include "commands.h" |
| 25 |
#include "shared/newclient.h" |
| 26 |
#include "skills.h" |
| 27 |
#include "spells.h" |
| 28 |
#include "sproto.h" |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
void command_invoke(object *op, const char *params) { |
| 39 |
command_cast_spell(op, params, 'i'); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
void command_cast(object *op, const char *params) { |
| 51 |
command_cast_spell(op, params, 'c'); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
void command_prepare(object *op, const char *params) { |
| 64 |
command_cast_spell(op, params, 'p'); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
static void show_matching_spells(object *op, const char *params) { |
| 79 |
char spell_sort[NROFREALSPELLS][MAX_BUF], tmp[MAX_BUF], *cp; |
| 80 |
int num_found = 0, i; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
FOR_INV_PREPARE(op, spell) { |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
if (spell->type == SPELL |
| 92 |
&& (*params == '\0' || !strncmp(params, spell->name, strlen(params)))) { |
| 93 |
if (spell->path_attuned&op->path_denied) { |
| 94 |
snprintf(spell_sort[num_found++], sizeof(spell_sort[0]), |
| 95 |
"%s:%-30s %3s %3s", spell->skill ? spell->skill : "generic", |
| 96 |
spell->name, "den", "den"); |
| 97 |
} else { |
| 98 |
snprintf(spell_sort[num_found++], sizeof(spell_sort[0]), |
| 99 |
"%s:%-30s %3d %3d", spell->skill ? spell->skill : "generic", |
| 100 |
spell->name, spell->level, |
| 101 |
SP_level_spellpoint_cost(op, spell, SPELL_HIGHEST)); |
| 102 |
} |
| 103 |
} |
| 104 |
} FOR_INV_FINISH(); |
| 105 |
if (!num_found) { |
| 106 |
if (*params != '\0') |
| 107 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR, |
| 108 |
"You know no spells like '%s'.", params); |
| 109 |
else |
| 110 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR, |
| 111 |
"You know no spells."); |
| 112 |
|
| 113 |
return; |
| 114 |
} |
| 115 |
|
| 116 |
if (*params != '\0') |
| 117 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS, |
| 118 |
"You know the following '%s' spells:", params); |
| 119 |
else |
| 120 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS, |
| 121 |
"You know the following spells:"); |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
qsort(spell_sort, num_found, MAX_BUF, (int (*)(const void *, const void *))strcmp); |
| 129 |
strcpy(tmp, "asdfg"); |
| 130 |
for (i = 0; i < num_found; i++) { |
| 131 |
|
| 132 |
if (strncmp(tmp, spell_sort[i], strlen(tmp))) { |
| 133 |
strcpy(tmp, spell_sort[i]); |
| 134 |
cp = strchr(tmp, ':'); |
| 135 |
*cp = '\0'; |
| 136 |
|
| 137 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS, |
| 138 |
"\n[fixed]%s spells %.*s <lvl> <sp>", |
| 139 |
tmp, (int)(20-strlen(tmp)), " "); |
| 140 |
} |
| 141 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS, |
| 142 |
"[fixed]%s", |
| 143 |
strchr(spell_sort[i], ':')+1); |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
void command_cast_spell(object *op, const char *params, char command) { |
| 160 |
int castnow = 0; |
| 161 |
char *cp, cpy[MAX_BUF]; |
| 162 |
object *spob; |
| 163 |
|
| 164 |
safe_strncpy(cpy, params, sizeof(cpy)); |
| 165 |
|
| 166 |
if (command == 'i') |
| 167 |
castnow = 1; |
| 168 |
|
| 169 |
if (*cpy != '\0') { |
| 170 |
tag_t spellnumber = 0; |
| 171 |
if ((spellnumber = atoi(cpy)) != 0) |
| 172 |
spob = object_find_by_tag(op, spellnumber); |
| 173 |
else |
| 174 |
spob = lookup_spell_by_name(op, cpy); |
| 175 |
|
| 176 |
if (spob && spob->type == SPELL) { |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
if (spellnumber) { |
| 181 |
|
| 182 |
cp = strchr(cpy, ' '); |
| 183 |
if (cp) { |
| 184 |
cp++; |
| 185 |
if (!strncmp(cp, "of ", 3)) |
| 186 |
cp += 3; |
| 187 |
} |
| 188 |
} else if (strlen(cpy) > strlen(spob->name)) { |
| 189 |
cp = cpy+strlen(spob->name); |
| 190 |
*cp = 0; |
| 191 |
cp++; |
| 192 |
if (!strncmp(cp, "of ", 3)) |
| 193 |
cp += 3; |
| 194 |
} else |
| 195 |
cp = NULL; |
| 196 |
|
| 197 |
if (spob->skill && !find_skill_by_name(op, spob->skill)) { |
| 198 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_MISSING, |
| 199 |
"You need the skill %s to cast %s!", |
| 200 |
spob->skill, spob->name); |
| 201 |
return; |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
if (op->contr->ranges[range_golem] != NULL) { |
| 206 |
if (op->contr->golem_count == op->contr->ranges[range_golem]->count) { |
| 207 |
remove_friendly_object(op->contr->ranges[range_golem]); |
| 208 |
object_remove(op->contr->ranges[range_golem]); |
| 209 |
object_free_drop_inventory(op->contr->ranges[range_golem]); |
| 210 |
} |
| 211 |
op->contr->ranges[range_golem] = NULL; |
| 212 |
op->contr->golem_count = 0; |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
op->spell = spob; |
| 217 |
if (castnow) { |
| 218 |
cast_spell(op, op, op->facing, spob, cp); |
| 219 |
} else { |
| 220 |
|
| 221 |
sstring required = object_get_value(spob, "casting_requirements"); |
| 222 |
op->contr->ranges[range_magic] = spob; |
| 223 |
op->contr->shoottype = range_magic; |
| 224 |
|
| 225 |
if (cp != NULL) { |
| 226 |
strncpy(op->contr->spellparam, cp, MAX_BUF); |
| 227 |
op->contr->spellparam[MAX_BUF-1] = '\0'; |
| 228 |
} else { |
| 229 |
op->contr->spellparam[0] = '\0'; |
| 230 |
} |
| 231 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS, |
| 232 |
"You ready the spell %s%s%s", |
| 233 |
spob->name, required ? " which consumes for each invocation " : "", required ? required : ""); |
| 234 |
} |
| 235 |
return; |
| 236 |
} |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
show_matching_spells(op, cpy); |
| 243 |
} |
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
int legal_range(object *op, int r) { |
| 265 |
switch (r) { |
| 266 |
case range_none: |
| 267 |
return 1; |
| 268 |
|
| 269 |
case range_bow: |
| 270 |
case range_misc: |
| 271 |
case range_magic: |
| 272 |
if (op->contr->ranges[r]) |
| 273 |
return 1; |
| 274 |
else |
| 275 |
return 0; |
| 276 |
|
| 277 |
case range_golem: |
| 278 |
if (op->contr->ranges[range_golem] |
| 279 |
&& op->contr->ranges[range_golem]->count == op->contr->golem_count) |
| 280 |
return 1; |
| 281 |
else |
| 282 |
return 0; |
| 283 |
|
| 284 |
case range_skill: |
| 285 |
if (op->chosen_skill) |
| 286 |
return 1; |
| 287 |
else |
| 288 |
return 0; |
| 289 |
} |
| 290 |
|
| 291 |
return 0; |
| 292 |
} |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
static void change_spell(object *op, char k) { |
| 303 |
char name[MAX_BUF]; |
| 304 |
|
| 305 |
do { |
| 306 |
op->contr->shoottype += ((k == '+') ? 1 : -1); |
| 307 |
if (op->contr->shoottype >= range_size) |
| 308 |
op->contr->shoottype = range_none; |
| 309 |
else if (op->contr->shoottype <= range_bottom) |
| 310 |
op->contr->shoottype = (rangetype)(range_size-1); |
| 311 |
} while (!legal_range(op, op->contr->shoottype)); |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
switch (op->contr->shoottype) { |
| 318 |
case range_none: |
| 319 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR, |
| 320 |
"No ranged attack chosen."); |
| 321 |
break; |
| 322 |
|
| 323 |
case range_golem: |
| 324 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS, |
| 325 |
"You regain control of your golem."); |
| 326 |
break; |
| 327 |
|
| 328 |
case range_bow: |
| 329 |
query_name(op->contr->ranges[range_bow], name, MAX_BUF); |
| 330 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS, |
| 331 |
"Switched to %s and %s.", |
| 332 |
name, |
| 333 |
op->contr->ranges[range_bow]->race ? op->contr->ranges[range_bow]->race : "nothing"); |
| 334 |
break; |
| 335 |
|
| 336 |
case range_magic: |
| 337 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS, |
| 338 |
"Switched to spells (%s).", |
| 339 |
op->contr->ranges[range_magic]->name); |
| 340 |
break; |
| 341 |
|
| 342 |
case range_misc: |
| 343 |
query_base_name(op->contr->ranges[range_misc], 0, name, MAX_BUF); |
| 344 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS, |
| 345 |
"Switched to %s.", |
| 346 |
name); |
| 347 |
break; |
| 348 |
|
| 349 |
case range_skill: |
| 350 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_SUCCESS, |
| 351 |
"Switched to skill: %s", |
| 352 |
op->chosen_skill ? op->chosen_skill->name : "none"); |
| 353 |
break; |
| 354 |
|
| 355 |
default: |
| 356 |
break; |
| 357 |
} |
| 358 |
} |
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
void command_rotateshoottype(object *op, const char *params) { |
| 369 |
if (*params == '\0') |
| 370 |
change_spell(op, '+'); |
| 371 |
else |
| 372 |
change_spell(op, params[0]); |
| 373 |
} |