/
-------------------------------------------------------------- Introduction ----
 Ever grow tired of combat on your MUD being a neverending fountain of
 meaningless spam?  Can your players eat dinner in the middle of a battle? Then
 this snippet is for you.  This is a turn-based combat engine, loosely based on
 console-style RPG's such as Grandia or Final Fantasy X.  It has been tested,
 and works on stock QuickMUD.  I don't offer support with porting it to other
 codebases, but if you find serious bugs, have questions or comments, feel free
 to email me at eclipsing.souls@gmail.com.  Note: Never install snippets
 without first reading and understanding them.  Please, do not use this snippet
 if you don't intend to do some work; this contains only the very basics, and
 should be expanded upon greatly before getting any widespread use.
                                                              Enjoy! -- Midboss

 08-08-2007 - Re-uploaded in (a hopefully uncorrupted) tarball.
 05-18-2005 - Fixed some small errors with the snippet.
-------------------------------------------------------------------- merc.h ----
 Add these to your typedefs:
typedef struct    combat_data      COMBAT_DATA;
typedef struct    turn_data        TURN_DATA;

 Add the following to struct char_data:
	/* Turn-Based Combat stuff, by Midboss. */
	COMBAT_DATA *      in_battle;
	CHAR_DATA *        next_in_battle;
	TURN_DATA *	       turn;

 Add this macro with your GET_DAMROLL functions and such.  Modify as needed.

#define GET_SPEED(ch) (get_curr_stat (ch, STAT_DEX) + ch->level)

 With the object, char, and descriptor lists, add:
extern  COMBAT_DATA		*	battle_list;

 Define a new AFF_* bit, AFF_KNOCKOUT.

 Add the following structures, anywhere you want:
/*
 * This is the structure for a single battle.
 */
struct combat_data
{
	bool			valid;
	COMBAT_DATA *	next;
	CHAR_DATA *		unit_list;
	TURN_DATA *		turn_list;
	int				turn_count;
};

/*
 * This is the structure for a single turn.
 */
struct turn_data
{
	bool			valid;
	TURN_DATA *		next;
	COMBAT_DATA *	in_battle;
	CHAR_DATA *		unit;
	long			roundtime;
	sh_int			timer;
};

 Add these prototypes among the big block of other prototypes:
/* combat.c by Midboss */
void			combat_update			(void);
void			mobile_turn				(CHAR_DATA * ch);
void			linkdead_turn			(CHAR_DATA * ch);
bool			damage_new				(CHAR_DATA * ch, CHAR_DATA * vch, long dam,
										 int sn, char * damverb, bool hide, bool fKill);
void			kill_unit				(CHAR_DATA * ch);
void			revive_unit				(CHAR_DATA * ch);
void			check_victory			(COMBAT_DATA * battle);
bool			is_fighting				(CHAR_DATA * ch);
bool			is_active				(CHAR_DATA * ch);
void			char_to_combat			(CHAR_DATA * ch, COMBAT_DATA * combat);
void			char_from_combat		(CHAR_DATA * ch);
TURN_DATA *		get_turn_char			(CHAR_DATA * ch);
void			insert_turn				(COMBAT_DATA * combat, TURN_DATA * nTurn);
void			remove_turn				(TURN_DATA * turn);
void			turn_end				(TURN_DATA * turn, int roundtime);
void			skip_turn				(TURN_DATA * turn, bool fWilling);
void			roundtime				(TURN_DATA * turn, int roundtime);
void			swap_turn				(TURN_DATA * aTurn, TURN_DATA * bTurn);
void			nuke_roundtime			(COMBAT_DATA * battle);
void			initiate_combat			(CHAR_DATA * ch, CHAR_DATA * vch);
void			clean_combat			(COMBAT_DATA * battle);
TURN_DATA *		new_turn				(void);
void			free_turn				(TURN_DATA * turn);
COMBAT_DATA *	new_combat				(void);
void			free_combat				(COMBAT_DATA * combat);

---------------------------------------------------------------------- db.c ----
 Add this somewhere at the top, I have it under the WEATHER_DATA.
COMBAT_DATA	* battle_list;
------------------------------------------------------------------ update.c ----
 Add a case for combat_update to update_handler().  I have it right under the
 stock violence_update() call.
------------------------------------------------------------------ interp.* ----
 Add the command prototypes to interp.h, and the command table entries to 
 interp.c:

DECLARE_DO_FUN( do_fight		);
DECLARE_DO_FUN( do_attack		);
DECLARE_DO_FUN( do_turns		);
DECLARE_DO_FUN( do_units		);
DECLARE_DO_FUN( do_wait			);
DECLARE_DO_FUN( do_escape		);

    {"fight",     do_fight,     POS_STANDING,  0,  LOG_NORMAL, 1},
    {"attack",    do_attack,    POS_STANDING,  0,  LOG_NORMAL, 1},
    {"turns",     do_turns,     POS_STANDING,  0,  LOG_NORMAL, 1},
    {"units",     do_units,     POS_STANDING,  0,  LOG_NORMAL, 1},
    {"wait",      do_wait,      POS_STANDING,  0,  LOG_NORMAL, 1},
    {"escape",    do_escape,    POS_STANDING,  0,  LOG_NORMAL, 1},

--------------------------------------------------------------Finishing Touches-
 Drop combat.c and combat_act.c into your /src directory, add them to your
 makefile if neccessary, and do a clean make.

 Add this helpfile.  You may modify as you see fit, but you must keep my name
 and email at the bottom.

-1 COMBAT~
.
  This MUD employs a turn-based combat engine in which the turn order is
determined based on speed, and each character may take one action at a time.
When characters are defeated, they stay on the battlefield until combat ends,
with combat ending when all live characters are members of the same group.

  CTB engine brought to you by Midboss!          (eclipsing.souls@gmail.com)
~
--------------------------------------------------------------------------------

 That's it!  It should work fine, but you'll have to expand it quite a bit.