Fighting Stances

From: Stephen Wolfe (siv@CYBERENET.NET)
Date: 09/02/98


just wanted to drop my stance code to the list..had to condense it a bit
to meet the 200 line quota, but it should still be legible..any comments?
suggestions?

siv

/*  File: stance.c                                              *
 *  Usage: stances and utils..                                  */

#include "conf.h"
#include "sysdep.h"
#include "structs.h"
#include "utils.h"
#include "comm.h"
#include "interpreter.h"
#include "handler.h"
#include "db.h"
#include "spells.h"

#define MAX_STANCE_AFF          4
#define STANCE_NAME_LENGTH      15

struct stance_aff {
  int location;
  int amount; };

struct {
  char name[STANCE_NAME_LENGTH];
  int skill;
  struct stance_aff affs[MAX_STANCE_AFF];
} stances[] = {
  { "normal", -1, {{APPLY_NONE, -1}, {APPLY_NONE, -1},
                  {APPLY_NONE, -1}, {APPLY_NONE, -1}}},
  { "bull", STANCE_BULL, {{APPLY_AC, -30}, {APPLY_HITROLL, 3},
                         {APPLY_DAMROLL, -3}, {APPLY_NONE, -1}}},
  { "viper", STANCE_VIPER, {{APPLY_HITROLL, 4}, {APPLY_DAMROLL, 4},
                           {APPLY_AC, 40}, {APPLY_NONE, -1}}},
  { "monkey", STANCE_MONKEY, {{APPLY_AC, -30}, {APPLY_DEX, 1},
                             {APPLY_NONE,-1}, {APPLY_NONE,-1}}},
  { "drunk", STANCE_DRUNK, {{APPLY_CON, 1}, {APPLY_STR, 1},
                           {APPLY_NONE,-1}, {APPLY_NONE, -1}}},
  { "\n", -1, {{-1,-1},{-1,-1},{-1,-1},{-1,-1}}} };

int find_stance(char *name) {
  int index = -1, ok;
  char *temp, *temp2;
  char first[256], first2[256];
  while (*stances[++index].name != '\n') {
    if (is_abbrev(name, stances[index].name))
      return index;
    ok = 1;
    temp = any_one_arg(stances[index].name, first);
    temp2 = any_one_arg(name, first2);
    while (*first && *first2 && ok) {
      if (!is_abbrev(first2, first))
        ok = 0;
      temp = any_one_arg(temp, first);
      temp2 = any_one_arg(temp2, first2);
    }
    if (ok && !*first2)
      return index;
  }
  return -1;
}

void perform_stance_message(struct char_data *ch) {
  char *message[][2] = {
    {"$n relaxes into the normal fighting stance.",
     "You relax into the normal fighting stance."},
    {"$n crouches low into the bull fighting stance.",
     "You crouch low into the bull fighting stance."},
    {"$n rises into the viper fighting stance.",
     "You rise into the viper fighting stance."},
    {"$n begins using the monkey fighting stance.",
     "You begin using the monkey fighting stance."},
    {"$n staggers into the drunken fighting stance.",
     "You stagger into the drunken fighting stance."} };
  act(message[(int) (GET_STANCE(ch))][0], TRUE, ch, 0, 0, TO_ROOM);
  send_to_char(message[(int) GET_STANCE(ch)][1], ch);
}

void stance_affect(struct char_data *ch, int loc, int mod, bool add)
{
  int maxabil = (IS_NPC(ch) ? 25 : 18);
  if (!add)
    mod = -mod;
  switch (loc) {
  case APPLY_NONE:
    break;
  case APPLY_STR:
    GET_STR(ch) += mod;
    break;
  case APPLY_DEX:
    GET_DEX(ch) += mod;
    break;
  case APPLY_INT:
    GET_INT(ch) += mod;
    break;
  case APPLY_WIS:
    GET_WIS(ch) += mod;
    break;
  case APPLY_CON:
    GET_CON(ch) += mod;
    break;
  case APPLY_CHA:
    GET_CHA(ch) += mod;
    break;
  case APPLY_AGE:
    ch->player.time.birth -= (mod * SECS_PER_MUD_YEAR);
    break;
  case APPLY_CHAR_WEIGHT:
    GET_WEIGHT(ch) += mod;
    break;
  case APPLY_CHAR_HEIGHT:
    GET_HEIGHT(ch) += mod;
    break;
  case APPLY_MANA:
    GET_MAX_MANA(ch) += mod;
    break;
  case APPLY_HIT:
    GET_MAX_HIT(ch) += mod;
    break;
  case APPLY_MOVE:
    GET_MAX_MOVE(ch) += mod;
    break;
  case APPLY_AC:
    GET_AC(ch) += mod;
    break;
  case APPLY_HITROLL:
    GET_HITROLL(ch) += mod;
    break;
  case APPLY_DAMROLL:
    GET_DAMROLL(ch) += mod;
    break;
  case APPLY_SAVING_PARA:
    GET_SAVE(ch, SAVING_PARA) += mod;
    break;
  case APPLY_SAVING_ROD:
    GET_SAVE(ch, SAVING_ROD) += mod;
    break;
  case APPLY_SAVING_PETRI:
    GET_SAVE(ch, SAVING_PETRI) += mod;
    break;
  case APPLY_SAVING_BREATH:
    GET_SAVE(ch, SAVING_BREATH) += mod;
    break;
  case APPLY_SAVING_SPELL:
    GET_SAVE(ch, SAVING_SPELL) += mod;
    break;
  default:
    log("SYSERR: Unknown apply adjust attempt (stance_affect).");
    break;
  }                             /* switch */
}

ACMD(do_stance) {
  int stance, skill, i;
  if (!*arg) {
    send_to_char("You must specify a stance to switch to.\r\n", ch);
    return; }
  stance = find_stance(argument);
  if ((stance < 0) || (stance >= NUM_STANCES)) {
    send_to_char("What stance is THAT??\r\n", ch);
    return; }
  if (stance == GET_STANCE(ch)) {
    send_to_char("You are already using that stance.\r\n", ch);
    return; }
  skill = stances[stance].skill;
  if ((skill > 1) && !GET_SKILL(ch, skill)) {
    send_to_char("You don't know how to use that stance.\r\n", ch);
    return; }
  for (i = 0; i < MAX_STANCE_AFF; i++)
    stance_affect(ch, stances[(int)GET_STANCE(ch)].affs[i].location,
        stances[(int)GET_STANCE(ch)].affs[i].amount, FALSE);
  GET_STANCE(ch) = stance;
  for (i = 0; i < MAX_STANCE_AFF; i++)
    stance_affect(ch, stances[(int)GET_STANCE(ch)].affs[i].location,
        stances[(int)GET_STANCE(ch)].affs[i].amount, FALSE);
  affect_total(ch);
  perform_stance_message(ch);
  return; }


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST