Re: do_consider

From: George (greerga@circlemud.org)
Date: 01/08/99


On Sat, 9 Jan 1999, Lasse L. Cederstrom wrote:

>If you look at the players and monsters hps, thier ac, and thier
>attacks (and each attacks thaco) - you should be able to figure out
>how many rounds of combat the fight will take, and who would win.

Funny, my (old) code does just that. :)

#define AV_DAM(dice, size)      (((dice * size) - (dice - 1)) / 2)

ACMD(do_consider)
{
  struct obj_data *weapon = GET_EQ(ch, WEAR_WIELD);
  struct char_data *victim;
  int ch_ac = 0, vict_ac = 0, ch_dam = 0, vict_dam = 0;
  float ch_val = 0, vict_val = 0;
  float diff = 0;
  int ch_tohit = 0, vict_tohit = 0;

  one_argument(argument, buf);

  if (!(victim = get_char_room_vis(ch, buf))) {
    send_to_char("Consider killing who?\r\n", ch);
    return;
  }
  if (victim == ch) {
    send_to_char("Easy!  Very easy indeed!\r\n", ch);
    return;
  }
  /* Original command checked level differences, but lets be different
   * and actually figure out the damage potential of both characters
   * and then compare who would theoretically die first
   */

  /* Create averages of damage */
  if ((weapon = GET_EQ(ch, WEAR_WIELD)))
    ch_dam = AV_DAM(GET_OBJ_VAL(weapon, 1), GET_OBJ_VAL(weapon, 2));
  else {
    if (IS_NPC(ch))
      ch_dam = AV_DAM(ch->mob_specials.damnodice,
          ch->mob_specials.damsizedice);
     else
       ch_dam = 1; /* Fist 0-2 */
  }

  if ((weapon = GET_EQ(victim, WEAR_WIELD)))
    vict_dam = AV_DAM(GET_OBJ_VAL(weapon, 1), GET_OBJ_VAL(weapon, 2));
  else {
    if (IS_NPC(victim))
      vict_dam = AV_DAM(victim->mob_specials.damnodice,
        victim->mob_specials.damsizedice);
    else
      vict_dam = 1; /* Fist 0-2 */
  }

  /* Now take into account AC */
  ch_ac = GET_AC(ch) / 10;
  if (AWAKE(ch)) ch_ac += dex_app[GET_DEX(ch)].defensive;
  ch_ac = MAX(-10, ch_ac);

  vict_ac = GET_AC(victim) / 10;
  if (AWAKE(victim)) vict_ac += dex_app[GET_DEX(victim)].defensive;
  vict_ac = MAX(-10, vict_ac);

  /* Now we factor in THAC0 */
  ch_tohit = get_thaco(ch);
  vict_tohit = get_thaco(victim);

  /* Now we know how much damage they do, how well they defend and how
     well they can hit, now lets factor this all in a neat little form-
     ula and see what happens
  */

  if (GET_LEVEL(ch) >= LVL_IMMORT) {
    sprintf(buf, "%s's %d THAC0 + your %d AC yields %d%% chance of hit.\r\n"
                 "Your %d THAC0 + %s's %d AC yields %d%% chance of hit.\r\n",
        GET_NAME(victim), vict_tohit, ch_ac, (100 * (21 - vict_tohit + ch_ac)
        / 20), ch_tohit, GET_NAME(victim), vict_ac, (100 * (21 - ch_tohit +
        vict_ac) / 20));
     send_to_char(buf, ch);
  }

  ch_tohit = MAX(MIN(21 - ch_tohit + vict_ac, 20), 0) * 100;
  vict_tohit = MAX(MIN(21 - vict_tohit + ch_ac, 20), 0) * 100;

  ch_val = ((ch_tohit / 20) * ch_dam * get_num_hits(ch, RNDS_PER_VIOLENCE)) / 100;
  vict_val = ((vict_tohit / 20) * vict_dam * get_num_hits(victim, RNDS_PER_VIOLENCE)) / 100;
  if (ch_val == 0) ch_val = .01;
  if (vict_val == 0) vict_val = .01;

  if (GET_LEVEL(ch) >= LVL_IMMORT) {
    sprintf(buf, "%s's %d%% hit * %d damage * %d hits = %.0f damage value.\r\n"
                 "Your %d%% hit * %d damage * %d hits = %.0f damage value.\r\n",
        GET_NAME(victim), vict_tohit / 20, vict_dam, get_num_hits(victim, RNDS_PER_VIOLENCE),
        vict_val, ch_tohit / 20, ch_dam, get_num_hits(ch, RNDS_PER_VIOLENCE), ch_val);
     send_to_char(buf, ch);
  }

  if (GET_LEVEL(ch) >= LVL_IMMORT) {
    sprintf(buf, "%s's %.0f damage by your %d hps yields %.2f rounds.\r\n"
                 "Your %.0f damage by %s's %d hps yields %.2f rounds.\r\n",
        GET_NAME(victim), vict_val, GET_HIT(ch), (GET_HIT(ch) != 0 ?
        GET_HIT(ch) : 1) / vict_val, ch_val, GET_NAME(victim),
        GET_HIT(victim), (GET_HIT(victim) != 0 ? GET_HIT(victim) : 1) /
        ch_val);
    send_to_char(buf, ch);
  }

  /* Now we have their one round damage potential, lets see who dies first */
  diff = (GET_HIT(victim) / ch_val) - (GET_HIT(ch) / vict_val);

  if (diff < -10)
    sprintf(buf, "So easy it's ridiculous.\r\n");
  else if (diff < -5)
    sprintf(buf, "Not a problem.\r\n");
  else if (diff < -2)
    sprintf(buf, "Easy.\r\n");
  else if (diff < -1)
    sprintf(buf, "Rather easy.\r\n");
  else if (diff < -.25)
    sprintf(buf, "It'll be close, but you should get them.\r\n");
  else if (diff < .25)
    sprintf(buf, "It'll be a close one.\r\n");
  else if (diff < 1)
    sprintf(buf, "It'll be close, but you probably won't make it.\r\n");
  else if (diff < 2)
    sprintf(buf, "Not such a great idea.\r\n");
  else if (diff < 5)
    sprintf(buf, "Feeling lucky today?\r\n");
  else if (diff < 10)
    sprintf(buf, "You've got to be insane.\r\n");
  else if (diff < 100)
    sprintf(buf, "Ha! Good luck in this century.\r\n");
  else
    sprintf(buf, "If you can see this, don't even bother!\r\n");

  send_to_char(buf, ch);
}

That is from my (now retired) MUD code.  I'd release the server but I'd
catch hell from my girlfriend for it. Long story. Just credit me somehow
for it if you like it.  The above code is over a year (or three) old and
I'm not looking for improvements on it though.

--
George Greer
greerga@circlemud.org
http://mouse.van.ml.org/


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



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