[CODE] was ...Re Perform_Violence overhauled

From: Phillip Tran (witpens@optushome.com.au)
Date: 10/18/01


----- Original Message -----
From: "MrFONZY" <mrfonzy@yahoo.com>


> Phillip,
> anywho, I never figured out exactly how they got thiers to work, but
I'm very
> interested in trying it out so keep us up to date with what you can
get
> running!:)
>

Well, I have finished the overhaul of perform_violence. The shell of the
code is pasted below - basically replace the version below with what you
have and it will work. You do not need to change anything else! Please
bear in mind, it is a shell - there are places where I have commented to
allow you to make checks for SECOND_ATTACK etc and for weapon speed
checks (you will need to modify your objects to have an extra field for
this), dex checks etc

The basic outline is this:-
From combat_list, scroll through all players and add their multiple
attacks into a new list (top_sort) and calculate their initiatives,
modifiers, weapon speeds etc
eg. combat_list = player 1, player 2, player 3, player 4 (assuming 1,3
has 1 attack each, and 2,4 has 2 attacks)
top_sort = player 1 (initiative value 5), player 2 (iv =3), player 2 (iv
= 8), player 3 (iv = 7), player 4 (iv = 4), player 4 (iv=12)
Then sort in order of initiative value into top_sort_final
top_sort_final = player 2 (iv 3), player 4 (iv 4), player 1 (iv 5),
player 3 (iv 7), player 2 (iv 8), player 4 (iv 12)
then execute all the original perform_violence checks in the
top_sort_final order.

Now, I hope you guys can add extra flavour with the myriads of check
options etc - it should be quite obvious where to adjust it.

PS: I have only made a brief check on the code ;p

Have fun.

Horus,
soon to be revamped Dark Realms III.

void perform_violence(void)
{
  struct char_data *ch;
  bool same_room=FALSE, same_player = FALSE, found_lowest = FALSE;

  struct sort_list {
 struct char_data *pp;
 int speed_roll;
 struct sort_list *next_sort;
 };

  struct sort_list *top_sort = NULL, *top_sort_final= NULL, *new_sort,
*ns, *ns_next, *nn, *nn_next, *nn_prev;

  int initiative;

  for (ch = combat_list; ch; ch = next_combat_list) {
    next_combat_list = ch->next_fighting;

 same_room = FALSE;

 /* CREATING A NEW QUEUE AND DUMP ALL ATTACKS INTO IT */

 CREATE(new_sort, struct sort_list, 1);
 new_sort->next_sort = top_sort;
 new_sort->pp = ch;

 /* CALCULATE SPEED ROLLS ETC CHECK FOR 2ND 3RD 4TH ATTACKS */
 /*  YOU CAN BASICALLY MAKE ANY CHECKS HERE - INCLUDING FOR WEAPON SPEED
ETC */
 initiative = dice (1, 10);
 initiative += 10 - GET_DEX(ch);
 initiative -= GET_CLASS(ch);
 new_sort->speed_roll = initiative;
 top_sort = new_sort;

 if (IS_NPC(ch)) initiative += dice(1,10); /* this is the perfect place
to add speed attacks from mobs */

 /* Adding multi attacks into the top_sort list */
 /* This is just a basic version - its best to check on skills etc */
 if (GET_CLASS(ch) == CLASS_WARRIOR) {
  CREATE(new_sort, struct sort_list, 1);
  new_sort->next_sort = top_sort;
  new_sort->pp = ch;
  new_sort->speed_roll = initiative + 5;
  top_sort = new_sort;
 }
  }

 /* SORT top_sort BASED ON INITIATIVE VALUES */
 for (ns = top_sort; ns; ns = ns_next) {
  ns_next = ns->next_sort;
  found_lowest = FALSE;
  if (!top_sort_final) {
   top_sort_final = ns;
   top_sort_final->next_sort = NULL;
  }
  else if (ns->speed_roll <= top_sort_final->speed_roll) {
   ns->next_sort = top_sort_final;
   top_sort_final = ns;
  }
  else {
   nn_prev = NULL;
   for (nn = top_sort_final; nn && !found_lowest; nn = nn_next) {
    nn_next = nn->next_sort;
    if (ns->speed_roll <= nn->speed_roll) {
     nn_prev->next_sort = ns;
     ns->next_sort = nn;
     found_lowest = TRUE;
    }
    else if (!nn_next) {   /* reached at the end of the list */
     nn->next_sort = ns;
     ns->next_sort = NULL;
    }
    nn_prev = nn;
   }

  }
 }

 /* NOT SURE IF SPELLS ARE PLACED IN COMBAT LIST - needs to be done
later */

 /* LOOP THROUGH FINAL QUEUE TO PROCESS ALL PERFORM_VIOLENCE ROUTINES */

 for (ns = top_sort_final; ns; ns = ns_next) {
  ns_next = ns->next_sort;

  ch = ns->pp;

  if (FIGHTING(ch) == NULL || ch->in_room != FIGHTING(ch)->in_room) {
   stop_fighting(ch);
   continue;
  }

  if (IS_NPC(ch)) {
   if (GET_MOB_WAIT(ch) > 0) {
    GET_MOB_WAIT(ch) -= PULSE_VIOLENCE;
    continue;
   }
   GET_MOB_WAIT(ch) = 0;
   if (GET_POS(ch) < POS_FIGHTING) {
    GET_POS(ch) = POS_FIGHTING;
    act("$n scrambles to $s feet!", TRUE, ch, 0, 0, TO_ROOM);
   }
  }

  if (GET_POS(ch) < POS_FIGHTING) {
   send_to_char("You can't fight while sitting!!\r\n", ch);
   continue;
   }

  hit(ch, FIGHTING(ch), TYPE_UNDEFINED);
    /* XXX: Need to see if they can handle "" instead of NULL. */
  if (MOB_FLAGGED(ch, MOB_SPEC) && mob_index[GET_MOB_RNUM(ch)].func !=
NULL)
   (mob_index[GET_MOB_RNUM(ch)].func) (ch, ch, 0, "");
 }
 /* Clear pointers */
 for (ns = top_sort_final; ns; ns = ns_next) {
  ns_next = ns->next_sort;
  free(ns);
 }
}

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/06/01 PST