hero casts a spell of type spell_otyp, eg. SPE_SLEEP. hero must know the spell (unless force is TRUE). */
| 1382 | /* hero casts a spell of type spell_otyp, eg. SPE_SLEEP. |
| 1383 | hero must know the spell (unless force is TRUE). */ |
| 1384 | int |
| 1385 | spelleffects(int spell_otyp, boolean atme, boolean force) |
| 1386 | { |
| 1387 | int spell = force ? spell_otyp : spell_idx(spell_otyp); |
| 1388 | int energy = 0, damage, n; |
| 1389 | int otyp, skill, role_skill, res = ECMD_OK; |
| 1390 | boolean physical_damage = FALSE; |
| 1391 | struct obj *pseudo; |
| 1392 | coord cc; |
| 1393 | |
| 1394 | if (!force && spelleffects_check(spell, &res, &energy)) |
| 1395 | return res; |
| 1396 | |
| 1397 | u.uen -= energy; |
| 1398 | disp.botl = TRUE; |
| 1399 | exercise(A_WIS, TRUE); |
| 1400 | /* pseudo is a temporary "false" object containing the spell stats */ |
| 1401 | pseudo = mksobj(force ? spell : spellid(spell), FALSE, FALSE); |
| 1402 | pseudo->blessed = pseudo->cursed = 0; |
| 1403 | pseudo->quan = 20L; /* do not let useup get it */ |
| 1404 | /* |
| 1405 | * Find the skill the hero has in a spell type category. |
| 1406 | * See spell_skilltype for categories. |
| 1407 | */ |
| 1408 | otyp = pseudo->otyp; |
| 1409 | skill = spell_skilltype(otyp); |
| 1410 | role_skill = P_SKILL(skill); |
| 1411 | |
| 1412 | switch (otyp) { |
| 1413 | /* |
| 1414 | * At first spells act as expected. As the hero increases in skill |
| 1415 | * with the appropriate spell type, some spells increase in their |
| 1416 | * effects, e.g. more damage, further distance, and so on, without |
| 1417 | * additional cost to the spellcaster. |
| 1418 | */ |
| 1419 | case SPE_FIREBALL: |
| 1420 | case SPE_CONE_OF_COLD: |
| 1421 | if (role_skill >= P_SKILLED) { |
| 1422 | if (throwspell()) { |
| 1423 | cc.x = u.dx; |
| 1424 | cc.y = u.dy; |
| 1425 | n = rnd(8) + 1; |
| 1426 | while (n--) { |
| 1427 | if (!u.dx && !u.dy && !u.dz) { |
| 1428 | if ((damage = zapyourself(pseudo, TRUE)) != 0) { |
| 1429 | char buf[BUFSZ]; |
| 1430 | Sprintf(buf, "zapped %sself with a spell", |
| 1431 | uhim()); |
| 1432 | losehp(damage, buf, NO_KILLER_PREFIX); |
| 1433 | } |
| 1434 | } else { |
| 1435 | explode(u.dx, u.dy, |
| 1436 | otyp - SPE_MAGIC_MISSILE + 10, |
| 1437 | spell_damage_bonus(u.ulevel / 2 + 1), 0, |
| 1438 | (otyp == SPE_CONE_OF_COLD) |
| 1439 | ? EXPL_FROSTY |
| 1440 | : EXPL_FIERY); |
| 1441 | } |
no test coverage detected