コード例 #1
0
ファイル: xor_hash.cpp プロジェクト: KibaAmor/gko_pool
/**
 * @brief xor hash a given length buf
 *
 * @see
 * @note
 *     if hval is not 0, use it as the init hash value
 * @author auxten  <*****@*****.**>
 * @date 2011-8-1
 **/
unsigned xor_hash(const void *key, int len, unsigned hval)
{
#if defined(ROT_XOR_HASH)
    u_char *p = (u_char *) key;
    hval = hval ? hval : 2166136261;
#if defined(HASH_BYTE_NUM_ONCE)
    for (int i = 0; i <= len - HASH_BYTE_NUM_ONCE; i += HASH_BYTE_NUM_ONCE)
    {
        hval = ROLL(hval) ^ p[i];
        hval = ROLL(hval) ^ p[i + 1];
        hval = ROLL(hval) ^ p[i + 2];
        hval = ROLL(hval) ^ p[i + 3];
#if HASH_BYTE_NUM_ONCE == 8
        hval = ROLL(hval) ^ p[i + 4];
        hval = ROLL(hval) ^ p[i + 5];
        hval = ROLL(hval) ^ p[i + 6];
        hval = ROLL(hval) ^ p[i + 7];
#endif /** HASH_BYTE_NUM_ONCE == 8 **/
    }
    /**
     * hash the remained bytes
     **/
    for (int i = len - len % HASH_BYTE_NUM_ONCE; i < len; i++)
    {
        hval = ROLL(hval) ^ p[i];
    }
#else
    for (int i = 0; i < len; i++)
    {
        hval = ROLL(hval) ^ p[i];
    }
#endif

#elif defined(FNV_XOR_HASH)
    u_char *p = (u_char *) key;
    hval = hval ? hval : 2166136261;

    for (int i = 0; i < len; i++)
    {
#if defined(NO_SO_CALLED_FNV_OPTIMIZE)
        hval = (hval * 16777619) ^ p[i];
#else
        hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval
                << 24);
        hval ^= p[i];
#endif
    }

    return hval;
#endif /** ROT_XOR_HASH **/
    return hval;
}
コード例 #2
0
ファイル: main.c プロジェクト: AhmadTux/DragonFlyBSD
void
genchar(int type)
{
	int subscript;			/* used for subscripting into Stattable */
	struct charstats *statptr;	/* for pointing into Stattable */

	subscript = type - '1';

	if (subscript < C_MAGIC || subscript > C_EXPER)
		if (subscript != C_SUPER || !Wizard)
			/* fighter is default */
			subscript = C_FIGHTER;

	statptr = &Stattable[subscript];

	Player.p_quickness =
	    ROLL(statptr->c_quickness.base, statptr->c_quickness.interval);
	Player.p_strength =
	    ROLL(statptr->c_strength.base, statptr->c_strength.interval);
	Player.p_mana =
	    ROLL(statptr->c_mana.base, statptr->c_mana.interval);
	Player.p_maxenergy =
	    Player.p_energy =
	    ROLL(statptr->c_energy.base, statptr->c_energy.interval);
	Player.p_brains =
	    ROLL(statptr->c_brains.base, statptr->c_brains.interval);
	Player.p_magiclvl =
	    ROLL(statptr->c_magiclvl.base, statptr->c_magiclvl.interval);

	Player.p_type = subscript;

	if (Player.p_type == C_HALFLING)
		/* give halfling some experience */
		Player.p_experience = ROLL(600.0, 200.0);
}
コード例 #3
0
ファイル: io.c プロジェクト: a565109863/src
int
inputoption(void)
{
	++Player.p_age;		/* increase age */

	if (Player.p_ring.ring_type != R_SPOILED)
		/* ring ok */
		return (getanswer("T ", TRUE));
	else
		/* bad ring */
	{
		getanswer(" ", TRUE);
		return ((int) ROLL(0.0, 5.0) + '0');
	}
}
コード例 #4
0
ファイル: AI_nest.cpp プロジェクト: Stibbons/FourmiZZ
bool aiNest::needs_a_scout() const
{
  return ROLL(PROBABILITY_NEEDS_A_SCOUT) ;
}
コード例 #5
0
ファイル: AI_nest.cpp プロジェクト: Stibbons/FourmiZZ
bool aiNest::needs_a_harvester() const
{
  return ROLL(PROBABILITY_NEEDS_A_HARVESTER) ;
}
コード例 #6
0
ファイル: main.c プロジェクト: AhmadTux/DragonFlyBSD
void
neatstuff(void)
{
	double temp;	/* for temporary calculations */
	int ch;		/* input */

	switch ((int)ROLL(0.0, 100.0)) {
	case 1:
	case 2:
		if (Player.p_poison > 0.0) {
			mvaddstr(4, 0, "You've found a medic!  How much will you offer to be cured ? ");
			temp = floor(infloat());
			if (temp < 0.0 || temp > Player.p_gold) {
				/* negative gold, or more than available */
				mvaddstr(6, 0, "He was not amused, and made you worse.\n");
				Player.p_poison += 1.0;
			} else if (drandom() / 2.0 > (temp + 1.0) / MAX(Player.p_gold, 1))
				/* medic wants 1/2 of available gold */
				mvaddstr(5, 0, "Sorry, he wasn't interested.\n");
			else {
				mvaddstr(5, 0, "He accepted.");
				Player.p_poison = MAX(0.0, Player.p_poison - 1.0);
				Player.p_gold -= temp;
			}
		}
		break;

	case 3:
		mvaddstr(4, 0, "You've been caught raping and pillaging!\n");
		Player.p_experience += 4000.0;
		Player.p_sin += 0.5;
		break;

	case 4:
		temp = ROLL(10.0, 75.0);
		mvprintw(4, 0, "You've found %.0f gold pieces, want them ? ", temp);
		ch = getanswer("NY", FALSE);

		if (ch == 'Y')
			collecttaxes(temp, 0.0);
		break;

	case 5:
		if (Player.p_sin > 1.0) {
			mvaddstr(4, 0, "You've found a Holy Orb!\n");
			Player.p_sin -= 0.25;
		}
		break;

	case 6:
		if (Player.p_poison < 1.0) {
			mvaddstr(4, 0, "You've been hit with a plague!\n");
			Player.p_poison += 1.0;
		}
		break;

	case 7:
		mvaddstr(4, 0, "You've found some holy water.\n");
		++Player.p_holywater;
		break;

	case 8:
		mvaddstr(4, 0, "You've met a Guru. . .");
		if (drandom() * Player.p_sin > 1.0)
			addstr("You disgusted him with your sins!\n");
		else if (Player.p_poison > 0.0) {
			addstr("He looked kindly upon you, and cured you.\n");
			Player.p_poison = 0.0;
		} else {
			addstr("He rewarded you for your virtue.\n");
			Player.p_mana += 50.0;
			Player.p_shield += 2.0;
		}
		break;

	case 9:
		mvaddstr(4, 0, "You've found an amulet.\n");
		++Player.p_amulets;
		break;

	case 10:
		if (Player.p_blindness) {
			mvaddstr(4, 0, "You've regained your sight!\n");
			Player.p_blindness = FALSE;
		}
		break;

	default:		/* deal with poison */
		if (Player.p_poison > 0.0) {
			temp = Player.p_poison * Statptr->c_weakness
			    * Player.p_maxenergy / 600.0;
			if (Player.p_energy > Player.p_maxenergy / 10.0
			    && temp + 5.0 < Player.p_energy)
				Player.p_energy -= temp;
		}
		break;
	}
}
コード例 #7
0
ファイル: spew.c プロジェクト: pstef/cq410z
/*
 * display is given a class name ( delimited by SLASH, not '\0' ),
 * and will (1) find its class descriptor, by calling lookup
 * (2) pick a definition  (3) output that definition, and
 * recursively display any definitions in it, and convert any escapes.
 * The variant tag after the SLASH is used to pick out the appropriate
 * variants. If that variant tag is '&', the tag 'deftag' is used, which
 * is the active variant of the containing activation.
 */
void display(char *s, int deftag, FILE *fp)
{
  register classrec *cp;
  register defn *dp;
  register char *p;
  classrec *lookup();
  int i, variant, incurly;
  register int c, writing;

  if (CompIn) {              /* input is compressed */
    cp = &Classptr[atoi(s)]; /* explicit class # */
  } else {
    cp = lookup(s);
    if (cp == NULL) { /* none found */
      fprintf(fp, "???");
      while (*s != SLASH)
        putc(*s++, fp);
      fprintf(fp, "???");
      return;
    }
  }
  c = index(s, SLASH)[1]; /* get variant tag */
  if (c != '&')
    deftag = c;                /* use given tag */
  p = index(cp->tags, deftag); /* look it up */
  if (p == NULL) {
    variant = 0;
    fprintf(fp, "?\?/%c??", deftag); /* \? is replaced with ? */
    deftag = ' '; /* for passing as deftag */
  } else
    variant = p - cp->tags;

  i = ROLL(cp->weight);
  dp = cp->list;
  while (dp->cumul <= i) { /* pick one based on cumul. weights */
    dp = dp->next;
  }

  incurly = 0;    /* not in curlies */
  writing = 1;    /* writing */
  p = dp->string; /* this is the string */
  for (;;)
    switch (c = *p++) {
      case '\0':
        return;
      case BSLASH:
        if ((c = *p++) == '\0')
          return; /* ?? */
        else if (c == '!') {
          if (writing)
            putc('\n', fp);      /* \! = newline */
        } else if (isalnum(c)) { /* reference */
          if (writing)
            display(p - 1, deftag, fp); /* recurse */
          while (*p != SLASH)
            ++p;
          p += 2; /* skip variant tag */
        } else {
          if (writing)
            putc(c, fp);
        }
        break;
      case '{':
        if (!incurly) {
          incurly = 1;
          writing = (variant == 0);
        } else {
          if (writing)
            putc('{', fp);
        }
        break;
      case VBAR:
        if (incurly) {
          writing = (variant == incurly++);
        } else {
          putc(VBAR, fp);
        }
        break;
      case '}':
        if (incurly) {
          writing = 1;
          incurly = 0;
        } else
          putc('}', fp);
        break;
      default:
        if (writing)
          putc(c, fp);
    }
}