#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "emlen.h"

void 
do_consider (CHAR_DATA * ch, char *argy)
{
  char arg[SML_LENGTH];
  CHAR_DATA *victim;
  char *msg = '\0';
  int loopcount;
  int ctemp_hps;
  int vtemp_hps;
  DEFINE_COMMAND ("consider", do_consider, POSITION_RESTING, 0, LOG_NORMAL, "This command runs through the battle in your character's mind, and tells you the suspected outcome.")

    one_argy (argy, arg);
  if (arg[0] == '\0')
    {
      send_to_char ("Consider killing whom?\n\r", ch);
      return;
    }
  if ((victim = get_char_room (ch, arg)) == NULL)
    {
      send_to_char ("They're not here.\n\r", ch);
      return;
    }
  act ("You carefully go over the battle in your mind...", ch, NULL, victim, TO_CHAR);
  ctemp_hps = ch->hit;
  vtemp_hps = victim->hit;
  for (loopcount = 0; ((ctemp_hps >= 0) && (vtemp_hps >= 0)); ++loopcount)
    {
      multi_hit (victim, ch, TYPE_UNDEFINED + 10000);
      ctemp_hps -= cons_damage;
      multi_hit (ch, victim, TYPE_UNDEFINED + 10000);
      vtemp_hps -= cons_damage;
    }
/*OKAY... one of them has been simulated as DEAD.. now calc stats */
  if ((vtemp_hps <= 0) && (ctemp_hps <= 0))
    {
      act ("This would be a totally even battle.", ch, NULL, victim, TO_CHAR);
      return;
    }
  if (vtemp_hps == 0)
    vtemp_hps = -1;
  if (ctemp_hps == 0)
    ctemp_hps = 1;
  if ((vtemp_hps <= 0) && (ctemp_hps >= 0))
    {
      if (ctemp_hps < (ch->max_hit / 15))
	msg = "You are almost exactly evenly matched (without offensive magic)";
      else if (ctemp_hps < (ch->max_hit / 10))
	msg = "It would be a close battle without offensive magic.";
      else if (ctemp_hps < (ch->max_hit / 7))
	msg = "It would be a close battle but you would probably win.";
      else if (ctemp_hps < (ch->max_hit / 5))
	msg = "You would probably win unless $N has some tricks up $S sleeve.";
      else if (ctemp_hps < (ch->max_hit / 4))
	msg = "You should be able to beat $N unless $E has some tricks up $S sleeve.";
      else if (ctemp_hps < (ch->max_hit / 2))
	msg = "This should be fairly easy...";
      else if (ctemp_hps < (ch->max_hit - (ch->max_hit / 2)))
	msg = "No sweat... a little work and $N will go down hard...";
      else
	{
	  if (ctemp_hps < (ch->max_hit - 60))
	    msg = "$N stands no chance against you.";
	  else if (ctemp_hps < (ch->max_hit - 25))
	    msg = "Why would you bore yourself killing $N...";
	  else
	    msg = "You will have fun rearranging $N's bodyparts!";
	}
      act (msg, ch, NULL, victim, TO_CHAR);
      return;
    }
  if ((ctemp_hps < 0) && (vtemp_hps > 0))
    {
      if (vtemp_hps < (victim->max_hit / 15))
	msg = "You are almost exactly evenly matched.";
      else if (vtemp_hps < (victim->max_hit / 10))
	msg = "It would be a close battle but you would probably lose.";
      else if (vtemp_hps < (victim->max_hit / 7))
	msg = "You would need a little luck.";
      else if (vtemp_hps < (victim->max_hit / 5))
	msg = "You would need quite a bit of luck.";
      else if (vtemp_hps < (victim->max_hit / 4))
	msg = "$N will probably beat you in a one on one battle.";
      else if (vtemp_hps < (victim->max_hit / 2))
	msg = "You'd probably need a friend or two...";
      else if (vtemp_hps < (victim->max_hit - (victim->max_hit / 2)))
	msg = "You better have brought some friends!";
      else if (vtemp_hps < (victim->max_hit - (victim->max_hit / 3)))
	msg = "You better have brought A LOT of friends!";
      else if (vtemp_hps < (victim->max_hit - (victim->max_hit / 4)))
	msg = "I hope you have an army to back you up!";
      else
	{
	  if (vtemp_hps < (victim->max_hit - 60))
	    msg = "$N will laugh as $E rips you in two.";
	  else if (vtemp_hps < (victim->max_hit - 25))
	    msg = "$N will squish your face into the ground with ease.";
	  else
	    msg = "You truly are a masochist! There is NO WAY!";
	}
      act (msg, ch, NULL, victim, TO_CHAR);
      return;
    }
  return;
}

void 
do_group_consider (CHAR_DATA * ch, char *argy)
{
  char arg[SML_LENGTH];
  CHAR_DATA *victim;
  CHAR_DATA *attacker;
  char *msg = '\0';
  int loopcount;
  int ctemp_hps;
  int vtemp_hps;
  DEFINE_COMMAND ("gconsider", do_group_consider, POSITION_RESTING, 0, LOG_NORMAL, "This command runs through the battle in your character's mind as if you were the tank for your group, and tells you the suspected outcome.")
    one_argy (argy, arg);
  if (chars_in_group (ch) < 2)
    {
      send_to_char ("But you aren't in a group!!\n\r", ch);
      return;
    }
  if (arg[0] == '\0')
    {
      send_to_char ("Group-Consider killing whom?\n\r", ch);
      return;
    }
  if ((victim = get_char_room (ch, arg)) == NULL)
    {
      send_to_char ("They're not here.\n\r", ch);
      return;
    }
  act ("You carefully go over the battle in your mind...", ch, NULL, victim, TO_CHAR);
  ctemp_hps = ch->hit;
  vtemp_hps = victim->hit;
  check_room_more (ch->in_room);
  for (loopcount = 0; ((ctemp_hps >= 0) && (vtemp_hps >= 0)); ++loopcount)
    {
      multi_hit (victim, ch, TYPE_UNDEFINED + 10000);
      ctemp_hps -= cons_damage;
      for (attacker = ch->in_room->more->people; attacker != NULL; attacker = attacker->next_in_room)
	{
	  if (attacker == ch || is_same_group (attacker, ch))
	    {
	      multi_hit (attacker, victim, TYPE_UNDEFINED + 10000);
	      vtemp_hps -= cons_damage;
	    }
	}
    }
/*OKAY... one of them has been simulated as DEAD.. now calc stats */
  if ((vtemp_hps <= 0) && (ctemp_hps <= 0))
    {
      act ("This would be a totally even battle.", ch, NULL, victim, TO_CHAR);
      return;
    }
  if (vtemp_hps == 0)
    vtemp_hps = -1;
  if (ctemp_hps == 0)
    ctemp_hps = 1;
  if ((vtemp_hps <= 0) && (ctemp_hps >= 0))
    {
      if (ctemp_hps < (ch->max_hit / 15))
	msg = "Your group and the mob are almost exactly evenly matched.";
      else if (ctemp_hps < (ch->max_hit / 10))
	msg = "It would be a close battle without offensive magic.";
      else if (ctemp_hps < (ch->max_hit / 7))
	msg = "It would be a close battle but your group would probably win.";
      else if (ctemp_hps < (ch->max_hit / 5))
	msg = "Your group would probably win but it might be close.";
      else if (ctemp_hps < (ch->max_hit / 4))
	msg = "Your group should be able to beat $N.";
      else if (ctemp_hps < (ch->max_hit / 2))
	msg = "This should be fairly easy...";
      else if (ctemp_hps < (ch->max_hit - (ch->max_hit / 2)))
	msg = "A little teamwork and $N will go down hard...";
      else
	{
	  if (ctemp_hps < (ch->max_hit - 60))
	    msg = "$N stands no chance against your group.";
	  else if (ctemp_hps < (ch->max_hit - 25))
	    msg = "Why would your group bore itself with $N...";
	  else
	    msg = "Your group will have fun ripping off $N's bodyparts!";
	}
      act (msg, ch, NULL, victim, TO_CHAR);
      return;
    }
  if ((ctemp_hps < 0) && (vtemp_hps > 0))
    {
      if (vtemp_hps < (victim->max_hit / 15))
	msg = "The mob might take you out before your group wins.";
      else if (vtemp_hps < (victim->max_hit / 10))
	msg = "You will probably die, but your group should win.";
      else if (vtemp_hps < (victim->max_hit / 7))
	msg = "You would need a little luck tanking this foe.";
      else if (vtemp_hps < (victim->max_hit / 5))
	msg = "Your group probably will win, but you will might die in the process.";
      else if (vtemp_hps < (victim->max_hit / 4))
	msg = "Your group may win, but you will probably die in the battle.";
      else if (vtemp_hps < (victim->max_hit / 2))
	msg = "You will probably die, but your group still stands a small chance.";
      else if (vtemp_hps < (victim->max_hit - (victim->max_hit / 2)))
	msg = "You will probably have to flee, as will others in your group.";
      else if (vtemp_hps < (victim->max_hit - (victim->max_hit / 3)))
	msg = "Your group probably will have to flee unless you get lucky.";
      else if (vtemp_hps < (victim->max_hit - (victim->max_hit / 4)))
	msg = "$N will probably triumph over your group!";
      else
	{
	  if (vtemp_hps < (victim->max_hit - 60))
	    msg = "$N will laugh as $E rips all of you apart.";
	  else if (vtemp_hps < (victim->max_hit - 25))
	    msg = "$N will crush your group with ease.";
	  else
	    msg = "$N could destroy your group with ease!";
	}
      act (msg, ch, NULL, victim, TO_CHAR);
      return;
    }
  return;
}