arena.zip

snippets · 9.2 KB · 2010-03-30

Arena code by a Kyndig.com contributor (arena.c with readme). The author may have missed some steps.

Download   « Back to the snippets list

readme.txt

This is for the Arena code I might have missed some stuff but you should
get the big picture with this code.
if you have questions or comments or general ways to improve it please
mail me at khooghee@marys.smumn.edu
or find me on twist of fate cgl.com 4k


---
In Structs.h
struct char_player_data {
...
   struct char_data *betted_on;
...
   struct obj_data *obj_buffer;/*PC object edit buffer*oeditmod*/
   struct char_data *mob_buf;/*PC mob edit buffer     *meditmod*/
};


#define ROOM_ARENA              (1 << 16)  /*  An Arena Room Fight no die*/
#define PULSE_ARENA     (75 RL_SEC)
struct player_special_data_saved {
...
   int spells_to_learn;         /* How many can you learn yet this level*/
   int bet_amt;
   int spare8;
   ..
}


---
In utils.h 
#define GET_BETTED_ON(ch)    ((ch)->player.betted_on)
#define GET_BET_AMT(ch) ((ch)->player_specials->saved.bet_amt)


------
In constants.c
/* ROOM_x */
const char *room_bits[] = {
  "*",				/* BFS MARK */
  "ARENA",
  "!SCAN",
  "RENT",
  "LORD_R",
  "\n"
};


-----
In Graph.c
ACMD(do_track)
{
  struct char_data *vict;
  int dir, num;


  if (!GET_SKILL(ch, SKILL_TRACK)) {
    send_to_char("You have no idea how.\r\n", ch);
    return;
  }

  if ((ROOM_FLAGGED(IN_ROOM(ch), ROOM_ARENA)) ||
     (ROOM_FLAGGED(IN_ROOM(ch), ROOM_NOTRACK))){
    send_to_char("The ground shows no tracks.\r\n", ch);
        return;
  }


-----
In Act.offensive
ACMD(do_hit)
{
....
   act("$N is just such a good friend, you simply can't hit $M.", FALSE, ch, 0, vict, TO_CHAR);
  else {
    if (!ROOM_FLAGGED(ch->in_room, ROOM_ARENA))
    if (!pk_allowed) {
      if (!IS_NPC(vict) && !IS_NPC(ch) && (subcmd != SCMD_MURDER)) {
	send_to_char("Use 'murder' to hit another player.\r\n", ch);
	return;
      }
    if (IS_AFFECTED(ch, AFF_CHARM) && !IS_NPC(ch->master) && !IS_NPC(vict))
	return;			/* you can't order a charmed pet to attack a
				 * player */
    }
 
  if (ROOM_FLAGGED(ch->in_room, ROOM_PEACEFUL)) {
   send_to_char("This room just has such a peaceful, easy feeling...\r\n", ch);
    return;
  }

   if (ROOM_FLAGGED(ch->in_room, ROOM_ARENA)){
     sprintf(buf2, "%s and %s engage in mortal combat", GET_NAME(ch),
             GET_NAME(vict));
     sportschan(buf2);
   }
   if ((GET_POS(ch) == POS_STANDING) && (vict != FIGHTING(ch))) {
      hit(ch, vict, TYPE_UNDEFINED);
      WAIT_STATE(ch, PULSE_VIOLENCE + 2);
    } else
      send_to_char("You do the best you can!\r\n", ch);
  }
}



ACMD(do_kill)
{
...
 act("$N is such a good friend, you simply can't kill $M.", FALSE, ch, 0, vict, TO_CHAR);
  else {
    if (!ROOM_FLAGGED(ch->in_room, ROOM_ARENA))
    if (!pk_allowed) {
      if (!IS_NPC(vict) && !IS_NPC(ch) && (subcmd != SCMD_MURDER)) {
	send_to_char("Use 'murder' to hit another player.\r\n", ch);
	return;
      }
      if (IS_AFFECTED(ch, AFF_CHARM) && !IS_NPC(ch->master) && !IS_NPC(vict))
	  return; /* you can't order a charmed pet to attack a player */
    }

  if (ROOM_FLAGGED(ch->in_room, ROOM_PEACEFUL)) {
   send_to_char("This room just has such a peaceful, easy feeling...\r\n", ch);
    return;
  } 
 
   if (ROOM_FLAGGED(ch->in_room, ROOM_ARENA)){
     sprintf(buf2, "%s and %s engage in mortal combat", GET_NAME(ch),
             GET_NAME(vict));
     sportschan(buf2);
   }
    if ((GET_POS(ch) == POS_STANDING) && (vict != FIGHTING(ch))) {
      hit(ch, vict, TYPE_UNDEFINED);
      WAIT_STATE(ch, PULSE_VIOLENCE + 2);
    } else
      send_to_char("You do the best you can!\r\n", ch);
  }
}


---
In Act.wizard.c

ACMD(do_show)
{
..
  char any = FALSE;
  void hcontrol_list_houses(struct char_data *ch);
  extern int in_arena, in_start_arena, start_time, game_length,time_to_start;
  extern int time_left_in_game;


  struct show_struct {

    { "arena",          LVL_GRGOD },
    { "\n", 0 }
  };
 case 13:
    send_to_char("Arena Stats\r\n-----------\r\n", ch);
    sprintf(buf, "In_Arena = %-3s            In_start_arena = %-3s\r\n",
            YESNO(in_arena), YESNO(in_start_arena));
    sprintf(buf, "%sStart_time = %-5d        Game_length = %d\r\n", buf,
            start_time, game_length);
    sprintf(buf, "%sTime_to_Start = %-5d     Time_left = %d\r\n", buf,
            time_to_start, time_left_in_game);
    send_to_char(buf, ch);
    break;
  default:
    send_to_char("Sorry, I don't understand that.\r\n", ch);
    break;
  }
}

----
in Comm.c


top of file
/* for arena */
void start_arena();
void do_game();
extern int in_start_arena;

extern int in_arena;


   if (!(pulse % PULSE_VIOLENCE))
      perform_violence();

    if(in_start_arena)
      if(!(pulse % PULSE_ARENA))
        start_arena();

    if(in_arena)
      if(!(pulse % PULSE_ARENA))
        do_game();




-----
In Fight.c

void check_killer(struct char_data * ch, struct char_data * vict)
{
 
  if (ROOM_FLAGGED(ch->in_room, ROOM_ARENA)) 
   return;

  if (!PLR_FLAGGED(vict, PLR_KILLER) && !PLR_FLAGGED(vict, PLR_THIEF)
...
}


void raw_kill(struct char_data * ch)
{
  if (FIGHTING(ch))
    stop_fighting(ch);

  while (ch->affected)
    affect_remove(ch, ch->affected);

  death_cry(ch);

  if (ROOM_FLAGGED(ch->in_room, ROOM_ARENA)){
   if(IS_NPC(ch)){ 
     act("$n's body glows brightly for an instant and then slowly fades away"
        , FALSE, ch, 0, 0, TO_ROOM);
   }else
    act("$n is magically whisked away.", FALSE, ch, 0, 0, TO_ROOM);     
   char_from_room(ch);
   char_to_room(ch, r_mortal_start_room);
   look_at_room(ch, 0); 
   act("$n falls from the sky.", FALSE, ch, 0, 0, TO_ROOM);
   act("$n looks like he had a bad day", FALSE, ch, 0, 0, TO_ROOM);
   GET_HIT(ch) = GET_MAX_HIT(ch);
   GET_MANA(ch) = GET_MAX_MANA(ch);
   GET_MOVE(ch) = GET_MAX_MOVE(ch);
  if (ch->affected)
    while (ch->affected)
      affect_remove(ch, ch->affected);
  GET_POS(ch) = POS_STANDING;
  }else{
    make_corpse(ch);
    extract_char(ch);
  }
}


void die(struct char_data * ch)
{
  if (!ROOM_FLAGGED(ch->in_room, ROOM_ARENA))
    gain_exp(ch, -(GET_EXP(ch) >> 1));
  if (!IS_NPC(ch))
    REMOVE_BIT(PLR_FLAGS(ch), PLR_KILLER | PLR_THIEF);
  raw_kill(ch);
}


void perform_group_gain(struct char_data * ch, int base,
			     struct char_data * victim)
{
  int share;
 
  if (ROOM_FLAGGED(ch->in_room, ROOM_ARENA))
    return;
}


void damage(struct char_data * ch, struct char_data * victim, int dam,
	    int attacktype)
{
 ...
 
    if (victim->master == ch)
    stop_follower(victim);

  if (IS_AFFECTED(ch, AFF_INVISIBLE | AFF_HIDE))
    appear(ch);

  if (IS_AFFECTED(victim, AFF_SANCTUARY))
    dam >>= 1;		/* 1/2 damage when sanctuary */

  if (!pk_allowed) {
    check_killer(ch, victim);

    if (PLR_FLAGGED(ch, PLR_KILLER) && (ch != victim))
      dam = 0;
 
 ....
 
  if (!ROOM_FLAGGED(ch->in_room, ROOM_ARENA))
  if (ch != victim)
    gain_exp(ch, GET_LEVEL(victim) * dam);

  update_pos(victim);

  /*
   * skill_message sends a message from the messages file in lib/misc.
   * dam_message just sends a generic "You hit $n extremely hard.".
   * skill_message is preferable to dam_message because it is more
   * descriptive.
   * 
   * If we are _not_ attacking with a weapon (i.e. a spell), always use
   * skill_message. If we are attacking with a weapon: If this is a miss or a
   * death blow, send a skill_message if one exists; if not, default to a
   * dam_message. Otherwise, always send a dam_message.
   */
  0, 0, TO_ROOM);
    send_to_char("You are incapacitated an will slowly die, if not aided.\r\n", victim);
    break;
  case POS_STUNNED:
    act("$n is stunned, but will probably regain consciousness again.", TRUE, victim, 0, 0, TO_ROOM);
    send_to_char("You're stunned, but will probably regain consciousness again.\r\n", victim);
    break;
  case POS_DEAD:
    act("\x1B[1;31m$n is dead!  R.I.P.\x1B[1;0m", FALSE, victim, 0, 0, TO_ROOM);
    send_to_char("\x1B[1;31mYou are dead!  Sorry...\x1B[1;0m\r\n", victim);
    if(!IS_NPC(victim)){
     *buf2 = '\0';
      sprintf(buf2, "%s killed by %s in %s (%d)", GET_NAME(victim),
       GET_NAME(ch), world[ch->in_room].name, world[ch->in_room].number);
      deathlog(buf2, FALSE);
	*buf2 = '\0';
	  sprintf(buf2, "%s killed by %s", GET_NAME(victim), GET_NAME(ch));
	  do_info(ch, buf2, 0 ,0 );
    }
	
    if (ROOM_FLAGGED(victim->in_room, ROOM_ARENA)){
     sprintf(buf2, "%s has been defeated by %s", GET_NAME(victim), 
             GET_NAME(ch));
     sportschan(buf2);
    }
    break;

  default:			/* >= POSITION SLEEPING */
    if (dam > (GET_MAX_HIT(victim) >> 2))
      act("That really did HURT!", FALSE, victim, 0, 0, TO_CHAR);

    if (GET_HIT(victim) < (GET_MAX_HIT(victim) >> 2)) {
      sprintf(buf2, "%sYou wish that your wounds would stop \x1B[0;31mBLEEDING\x1B[1;0m so much!%s\r\n",
	      CCRED(victim, C_SPR), CCNRM(victim, C_SPR));
      send_to_char(buf2, victim);
      if (MOB_FLAGGED(victim, MOB_WIMPY) && (ch != victim))
	do_flee(victim, "", 0, 0);
    }
    if (!IS_NPC(victim) && GET_WIMP_LEV(victim) && (victim != ch) &&
	GET_HIT(victim) < GET_WIMP_LEV(victim)) {
      send_to_char("You loose your control, and attempt to flee!\r\n", victim);
      do_flee(victim, "", 0, 0);
    }
    break;
  }

  if (!IS_NPC(victim) && !(victim->desc)) {
    do_flee(victim, "", 0, 0);
    if (!FIGHTING(victim)) {
      act("$n is rescued by divine forces.", FALSE, victim, 0, 0, TO_ROOM);
      GET_WAS_IN(victim) = victim->in_room;
      char_from_room(victim);
      char_to_room(victim, 0);
    }
  }
  if (!AWAKE(victim))
    if (FIGHTING(victim))
      stop_fighting(victim);

  if (GET_POS(victim) == POS_DEAD) {
    if (IS_NPC(victim) || victim->desc)
      if (IS_AFFECTED(ch, AFF_GROUP))
	group_gain(ch, victim);
      else {
	exp = MIN(max_exp_gain, GET_EXP(victim) / 3);

	/* Calculate level-difference bonus */
	if (IS_NPC(ch))
	  exp += MAX(0, (exp * MIN(4, (GET_LEVEL(victim) - GET_LEVEL(ch)))) >> 3);
	else
	  exp += MAX(0, (exp * MIN(8, (GET_LEVEL(victim) - GET_LEVEL(ch)))) >> 3);
	exp = MAX(exp, 1);
        if (!ROOM_FLAGGED(ch->in_room, ROOM_ARENA))
	if (exp > 1) {
	  sprintf(buf2, "You receive %d experience points.\r\n", exp);
	  send_to_char(buf2, ch);
	} else
	  send_to_char("You receive one lousy experience point.\r\n", ch);
	 if (!ROOM_FLAGGED(ch->in_room, ROOM_ARENA)) 
           gain_exp(ch, exp);
	 change_alignment(ch, victim);
      }
    if (!IS_NPC(victim)) {
      if (MOB_FLAGGED(ch, MOB_MEMORY))
    	forget(ch, victim);
    }
    die(victim);
  }
}




Archive contents (3 files)

FileSize
arena.c19.1 KB
readme.txt10.5 KB
ftp.kyndig.com935 B

Site Stats

Snippets: 1791
Codebases: 571