Exemplo n.º 1
0
unit *addplayer(region * r, faction * f)
{
    unit *u;
    const char * name;

    assert(r->land);
    if (rpeasants(r) < PEASANT_MIN) {
        rsetpeasants(r, PEASANT_MIN + rng_int() % (PEASANT_MAX - PEASANT_MIN));
    }

    assert(f->units == NULL);
    faction_setorigin(f, 0, r->x, r->y);
    u = create_unit(r, f, 1, f->race, 0, NULL, NULL);
    u->thisorder = default_order(f->locale);
    unit_addorder(u, copy_order(u->thisorder));
    name = config_get("rules.equip_first");
    if (!equip_unit(u, name ? name : "first_unit")) {
        /* give every unit enough money to survive the first turn */
        i_change(&u->items, get_resourcetype(R_SILVER)->itype, maintenance_cost(u));
    }
    u->hp = unit_max_hp(u) * u->number;
    fset(u, UFL_ISNEW);
    if (f->race == get_race(RC_DAEMON)) {
        race_t urc;
        const race *rc;
        do {
            urc = (race_t)(rng_int() % MAXRACES);
            rc = get_race(urc);
        } while (rc == NULL || urc == RC_DAEMON || !playerrace(rc));
        u->irace = rc;
    }
    f->lastorders = 0;
    return u;
}
Exemplo n.º 2
0
static void scared_by_monster(unit * u)
{
    int n;

    switch (old_race(u_race(u))) {
    case RC_FIREDRAGON:
        n = rng_int() % 160 * u->number;
        break;
    case RC_DRAGON:
        n = rng_int() % 400 * u->number;
        break;
    case RC_WYRM:
        n = rng_int() % 1000 * u->number;
        break;
    default:
        n = rng_int() % (u->number / 4 + 1);
    }

    if (n > 0) {
        n = lovar(n);
        n = _min(rpeasants(u->region), n);
        if (n > 0) {
            n = scareaway(u->region, n);
            if (n > 0) {
                ADDMSG(&u->region->msgs, msg_message("fleescared",
                                                     "amount unit", n, u));
            }
        }
    }
}
Exemplo n.º 3
0
Arquivo: main.cpp Projeto: CCJY/coliru
int main() {
    int i, numIn, n;
    int state;
    double x, y, pi;

    n = 100000000;
    numIn = 0;

    #pragma omp parallel private(state, x, y) reduction(+:numIn) 
    {
        
        state = 25234 + 17 * omp_get_thread_num();
        #pragma omp for
        for (i = 0; i <= n; i++) {
            state = rng_int(state);
            x = (double)rng_doub(1.0, state);
            state = rng_int(state);
            y = (double)rng_doub(1.0, state);
            if (x*x + y*y <= 1) numIn++;
        }
    }
    pi = 4.*numIn / n;
    printf("asdf pi %f\n", pi);
    return 0;
}
Exemplo n.º 4
0
faction *gm_addquest(const char *email, const char *name, int radius,
  unsigned int flags)
{
  plane *pl;
  watcher *w = calloc(sizeof(watcher), 1);
  region *center;
  bool invalid = false;
  int minx, miny, maxx, maxy, cx, cy;
  int x;
  faction *f;

  /* GM playfield */
  do {
    minx = ((rng_int() % (2 * EXTENSION)) - EXTENSION);
    miny = ((rng_int() % (2 * EXTENSION)) - EXTENSION);
    for (x = 0; !invalid && x <= radius * 2; ++x) {
      int y;
      for (y = 0; !invalid && y <= radius * 2; ++y) {
        region *r = findregion(minx + x, miny + y);
        if (r)
          invalid = true;
      }
    }
  } while (invalid);
  maxx = minx + 2 * radius;
  cx = minx + radius;
  maxy = miny + 2 * radius;
  cy = miny + radius;
  pl = create_new_plane(rng_int(), name, minx, maxx, miny, maxy, flags);
  center = new_region(cx, cy, pl, 0);
  for (x = 0; x <= 2 * radius; ++x) {
    int y;
    for (y = 0; y <= 2 * radius; ++y) {
      region *r = findregion(minx + x, miny + y);
      if (!r) {
        r = new_region(minx + x, miny + y, pl, 0);
      }
      freset(r, RF_ENCOUNTER);
      if (distance(r, center) == radius) {
        terraform_region(r, newterrain(T_FIREWALL));
      } else if (r == center) {
        terraform_region(r, newterrain(T_PLAIN));
      } else {
        terraform_region(r, newterrain(T_OCEAN));
      }
    }
  }

  /* watcher: */
  f = gm_addfaction(email, pl, center);
  w->faction = f;
  w->mode = see_unit;
  w->next = pl->watchers;
  pl->watchers = w;

  return f;
}
Exemplo n.º 5
0
static void terraform_default(struct rawmaterial *res, const region * r)
{
#define SHIFT 70
    double modifier =
        1.0 + ((rng_int() % (SHIFT * 2 + 1)) - SHIFT) * ((rng_int() % (SHIFT * 2 +
        1)) - SHIFT) / 10000.0;
    res->amount = (int)(res->amount * modifier);  /* random adjustment, +/- 91% */
    if (res->amount < 1)
        res->amount = 1;
    unused_arg(r);
}
Exemplo n.º 6
0
/** Talente von Dämonen verschieben sich.
 */
static void demon_skillchanges(void)
{
  region *r;

  for (r = regions; r; r = r->next) {
    unit *u;
    for (u = r->units; u; u = u->next) {
        if (u_race(u) == get_race(RC_DAEMON)) {
        skill *sv = u->skills;
        int upchance = 15;
        int downchance = 10;

        if (fval(u, UFL_HUNGER)) {
          /* hungry demons only go down, never up in skill */
          static int rule_hunger = -1;
          if (rule_hunger < 0) {
            rule_hunger =
              get_param_int(global.parameters, "hunger.demon.skill", 0);
          }
          if (rule_hunger) {
            upchance = 0;
            downchance = 15;
          }
        }

        while (sv != u->skills + u->skill_size) {
          int roll = rng_int() % 100;
          if (sv->level > 0 && roll < upchance + downchance) {
            int weeks = 1 + rng_int() % 3;
            if (roll < downchance) {
              reduce_skill(u, sv, weeks);
              if (sv->level < 1) {
                /* demons should never forget below 1 */
                set_level(u, sv->id, 1);
              }
            } else {
              while (weeks--)
                learn_skill(u, sv->id, 1.0);
            }
            if (sv->old > sv->level) {
              if (verbosity >= 3) {
                log_printf(stdout, "%s dropped from %u to %u:%u in %s\n",
                  unitname(u), sv->old, sv->level, sv->weeks, skillname(sv->id,
                    NULL));
              }
            }
          }
          ++sv;
        }
      }
    }
  }
}
Exemplo n.º 7
0
static void godcurse(void)
{
    region *r;

    for (r = regions; r; r = r->next) {
        if (is_cursed(r->attribs, C_CURSED_BY_THE_GODS, 0)) {
            unit *u;
            for (u = r->units; u; u = u->next) {
                skill *sv = u->skills;
                while (sv != u->skills + u->skill_size) {
                    int weeks = 1 + rng_int() % 3;
                    reduce_skill(u, sv, weeks);
                    ++sv;
                }
            }
            if (fval(r->terrain, SEA_REGION)) {
                ship *sh;
                for (sh = r->ships; sh;) {
                    ship *shn = sh->next;
                    double dmg = config_get_flt("rules.ship.damage.godcurse", 0.1);
                    damage_ship(sh, dmg);
                    if (sh->damage >= sh->size * DAMAGE_SCALE) {
                        unit *u = ship_owner(sh);
                        if (u)
                            ADDMSG(&u->faction->msgs,
                                   msg_message("godcurse_destroy_ship", "ship", sh));
                        remove_ship(&sh->region->ships, sh);
                    }
                    sh = shn;
                }
            }
        }
    }

}
Exemplo n.º 8
0
const terrain_type *random_terrain(const terrain_type * terrains[],
    int distribution[], int size)
{
    int ndistribution = size;
    const terrain_type *terrain;
    int n;

    assert(size > 0);
    if (distribution) {
        ndistribution = 0;
        for (n = 0; n != size; ++n) {
            ndistribution += distribution[n];
        }
    }

    n = rng_int() % ndistribution;
    if (distribution) {
        int i;
        for (i = 0; i != size; ++i) {
            n -= distribution[i];
            if (n < 0)
                break;
        }
        assert(i < size);
        terrain = terrains[i];
    }
    else {
        terrain = terrains[n];
    }
    return terrain;
}
Exemplo n.º 9
0
Arquivo: chaos.c Projeto: stm2/server
static const terrain_type *chaosterrain(void)
{
    static const terrain_type **types;
    static int numtypes;

    if (numtypes == 0) {
        const terrain_type *terrain;
        for (terrain = terrains(); terrain != NULL; terrain = terrain->next) {
            if (fval(terrain, LAND_REGION) && terrain->herbs) {
                ++numtypes;
            }
        }
        if (numtypes > 0) {
            types = malloc(sizeof(terrain_type *) * numtypes);
            numtypes = 0;
            for (terrain = terrains(); terrain != NULL; terrain = terrain->next) {
                if (fval(terrain, LAND_REGION) && terrain->herbs) {
                    types[numtypes++] = terrain;
                }
            }
        }
    }
    if (numtypes > 0) {
        return types[rng_int() % numtypes];
    }
    return NULL;
}
Exemplo n.º 10
0
int sp_shadowcall(struct castorder * co)
{
    fighter * fi = co->magician.fig;
    int level = co->level;
    double power = co->force;
    battle *b = fi->side->battle;
    region *r = b->region;
    unit *mage = fi->unit;
    attrib *a;
    int force = (int)(get_force(power, 3) / 2);
    unit *u;
    const char *races[3] = { "shadowbat", "nightmare", "vampunicorn" };
    const race *rc = rc_find(races[rng_int() % 3]);
    message *msg;

    u = create_unit(r, mage->faction, force, rc, 0, NULL, mage);
    setstatus(u, ST_FIGHT);

    set_level(u, SK_WEAPONLESS, (int)(power / 2));
    set_level(u, SK_STAMINA, (int)(power / 2));
    u->hp = u->number * unit_max_hp(u);

    a = a_new(&at_unitdissolve);
    a->data.ca[0] = 0;
    a->data.ca[1] = 100;
    a_add(&u->attribs, a);

    make_fighter(b, u, fi->side, is_attacker(fi));
    msg =
        msg_message("sp_shadowcall_effect", "mage amount race", mage, u->number,
        u_race(u));
    message_all(b, msg);
    msg_release(msg);
    return level;
}
Exemplo n.º 11
0
void encounters(void)
{
  region *r;

  for (r = regions; r; r = r->next) {
    if (fval(r->terrain, LAND_REGION) && fval(r, RF_ENCOUNTER)) {
      int c = 0;
      unit *u;
      for (u = r->units; u; u = u->next) {
        c += u->number;
      }

      if (c > 0) {
        int i = 0;
        int n = rng_int() % c;

        for (u = r->units; u; u = u->next) {
          if (i + u->number > n)
            break;
          i += u->number;
        }
        assert(u && u->number);
        encounter(r, u);
      }
    }
  }
}
Exemplo n.º 12
0
static unit *random_unit(const region * r)
{
  int c = 0;
  int n;
  unit *u;

  for (u = r->units; u; u = u->next) {
      if (u_race(u) != get_race(RC_SPELL)) {
      c += u->number;
    }
  }

  if (c == 0) {
    return NULL;
  }
  n = rng_int() % c;
  c = 0;
  u = r->units;

  while (u && c < n) {
      if (u_race(u) != get_race(RC_SPELL)) {
      c += u->number;
    }
    u = u->next;
  }

  return u;
}
Exemplo n.º 13
0
static order *monster_learn(unit * u)
{
    int c = 0;
    int n;
    skill *sv;
    const struct locale *lang = u->faction->locale;

    /* can these monsters even study? */
    if (!unit_can_study(u)) {
        return NULL;
    }

    /* Monster lernt ein zufälliges Talent aus allen, in denen es schon
     * Lerntage hat. */
    for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
        if (sv->level > 0)
            ++c;
    }

    if (c == 0)
        return NULL;

    n = rng_int() % c + 1;
    c = 0;

    for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
        if (sv->level > 0) {
            if (++c == n) {
                return create_order(K_STUDY, lang, "'%s'", skillname(sv->id, lang));
            }
        }
    }
    return NULL;
}
Exemplo n.º 14
0
static void arena_weighted_mbind(void *arena, size_t arena_size,
																 uint16_t *weights, size_t nr_weights) {
	/* compute cumulative sum for weights
	 * cumulative sum starts at -1
	 * the method for determining a hit on a weight i is when the generated
	 * random number (modulo sum of weights) <= weights_cumsum[i]
	 */
	int64_t weights_cumsum[nr_weights];
	weights_cumsum[0] = weights[0] - 1;
	for (unsigned int i = 1; i < nr_weights; i++) {
		weights_cumsum[i] = weights_cumsum[i-1] + weights[i];
	}
	const int32_t weight_sum = weights_cumsum[nr_weights-1]+1;
	const int pagesize = getpagesize();

	uint64_t mask = 0;
	char *q = (char *)arena + arena_size;
	rng_init(1);
	for (char *p = arena; p < q; p += pagesize) {
		uint32_t r = rng_int(1<<31) % weight_sum;
		unsigned int node;
		for (node = 0; node < nr_weights; node++) {
			if (weights_cumsum[node] >= r) {
				break;
			}
		}
		mask = 1 << node;
		if (mbind(p, pagesize, MPOL_BIND, &mask, nr_weights, MPOL_MF_STRICT)) {
			perror("mbind");
			exit(1);
		}
		*p = 0;
	}
}
Exemplo n.º 15
0
static int scareaway(region * r, int anzahl)
{
    int n, p, diff = 0, emigrants[MAXDIRECTIONS];
    direction_t d;

    anzahl = _min(_max(1, anzahl), rpeasants(r));

    /* Wandern am Ende der Woche (normal) oder wegen Monster. Die
     * Wanderung wird erst am Ende von demographics () ausgefuehrt.
     * emigrants[] ist local, weil r->newpeasants durch die Monster
     * vielleicht schon hochgezaehlt worden ist. */

    for (d = 0; d != MAXDIRECTIONS; d++)
        emigrants[d] = 0;

    p = rpeasants(r);
    assert(p >= 0 && anzahl >= 0);
    for (n = _min(p, anzahl); n; n--) {
        direction_t dir = (direction_t) (rng_int() % MAXDIRECTIONS);
        region *rc = rconnect(r, dir);

        if (rc && fval(rc->terrain, LAND_REGION)) {
            ++diff;
            rc->land->newpeasants++;
            emigrants[dir]++;
        }
    }
    rsetpeasants(r, p - diff);
    assert(p >= diff);
    return diff;
}
Exemplo n.º 16
0
region *rrandneighbour(region * r)
{
  direction_t i;
  region *rc = NULL;
  int rr, c = 0;

  /* Nachsehen, wieviele Regionen in Frage kommen */

  for (i = 0; i != MAXDIRECTIONS; i++) {
    c++;
  }
  /* Zufällig eine auswählen */

  rr = rng_int() % c;

  /* Durchzählen */

  c = -1;
  for (i = 0; i != MAXDIRECTIONS; i++) {
    rc = rconnect(r, i);
    c++;
    if (c == rr)
      break;
  }
  assert(i != MAXDIRECTIONS);
  return rc;
}
Exemplo n.º 17
0
/** Talente von Daemonen verschieben sich.
*/
void demon_skillchange(unit *u)
{
    skill *sv = u->skills;
    int upchance = 15, downchance = 10;
    static int config;
    static bool rule_hunger;
    static int cfgup, cfgdown;

    if (config_changed(&config)) {
        rule_hunger = config_get_int("hunger.demon.skills", 0) != 0;
        cfgup = config_get_int("skillchange.demon.up", 15);
        cfgdown = config_get_int("skillchange.demon.down", 10);
    }
    if (cfgup == 0) {
        /* feature is disabled */
        return;
    }
    upchance = cfgup;
    downchance = cfgdown;

    if (fval(u, UFL_HUNGER)) {
        /* hungry demons only go down, never up in skill */
        if (rule_hunger) {
            downchance = upchance;
            upchance = 0;
        }
    }

    while (sv != u->skills + u->skill_size) {
        int roll = rng_int() % 100;
        if (sv->level > 0 && roll < upchance + downchance) {
            int weeks = 1 + rng_int() % 3;
            if (roll < downchance) {
                reduce_skill(u, sv, weeks);
                if (sv->level < 1) {
                    /* demons should never forget below 1 */
                    set_level(u, sv->id, 1);
                }
            }
            else {
                learn_skill(u, sv->id, STUDYDAYS * u->number * weeks);
            }
        }
        ++sv;
    }
}
Exemplo n.º 18
0
faction *gm_addfaction(const char *email, plane * p, region * r)
{
  attrib *a;
  unit *u;
  faction *f = calloc(1, sizeof(faction));

  assert(p != NULL);

  /* GM faction */
  a_add(&f->attribs, make_key(atoi36("quest")));
  f->banner = _strdup("quest faction");
  f->name = _strdup("quest faction");
  f->passw = _strdup(itoa36(rng_int()));
  if (set_email(&f->email, email) != 0) {
    log_error("Invalid email address for faction %s: %s\n", itoa36(f->no), email);
  }
  f->race = new_race[RC_TEMPLATE];
  f->age = 0;
  f->lastorders = turn;
  f->alive = true;
  f->locale = default_locale;
  f->options =
    want(O_COMPRESS) | want(O_REPORT) | want(O_COMPUTER) | want(O_ADRESSEN);
  {
    faction *xist;
    int id = atoi36("gm00") - 1;
    do {
      xist = findfaction(++id);
    } while (xist);

    f->no = id;
    addlist(&factions, f);
    fhash(f);
  }

  /* generic permissions */
  a = a_add(&f->attribs, a_new(&at_permissions));
  if (a) {
    attrib *ap = (attrib *) a->data.v;
    const char *keys[] =
      { "gmterf", "gmtele", "gmgive", "gmskil", "gmtake", "gmmsgr", "gmmsgu",
        "gmgate", 0 };
    const char **key_p = keys;
    while (*key_p) {
      add_key(&ap, atoi36(*key_p));
      ++key_p;
    }
    a_add(&ap, make_atgmcreate(resource2item(r_silver)));

    a->data.v = ap;
  }

  /* one initial unit */
  u = create_unit(r, f, 1, new_race[RC_TEMPLATE], 1, "quest master", NULL);
  u->irace = new_race[RC_GNOME];

  return f;
}
Exemplo n.º 19
0
plane *gm_addplane(int radius, unsigned int flags, const char *name)
{
  region *center;
  plane *pl;
  bool invalid = false;
  int minx, miny, maxx, maxy, cx, cy;
  int x;

  /* GM playfield */
  do {
    minx = (rng_int() % (2 * EXTENSION)) - EXTENSION;
    miny = (rng_int() % (2 * EXTENSION)) - EXTENSION;
    for (x = 0; !invalid && x <= radius * 2; ++x) {
      int y;
      for (y = 0; !invalid && y <= radius * 2; ++y) {
        region *r = findregion(minx + x, miny + y);
        if (r)
          invalid = true;
      }
    }
  } while (invalid);
  maxx = minx + 2 * radius;
  cx = minx + radius;
  maxy = miny + 2 * radius;
  cy = miny + radius;
  pl = create_new_plane(rng_int(), name, minx, maxx, miny, maxy, flags);
  center = new_region(cx, cy, pl, 0);
  for (x = 0; x <= 2 * radius; ++x) {
    int y;
    for (y = 0; y <= 2 * radius; ++y) {
      region *r = findregion(minx + x, miny + y);
      if (!r)
        r = new_region(minx + x, miny + y, pl, 0);
      freset(r, RF_ENCOUNTER);
      if (distance(r, center) == radius) {
        terraform_region(r, newterrain(T_FIREWALL));
      } else if (r == center) {
        terraform_region(r, newterrain(T_PLAIN));
      } else {
        terraform_region(r, newterrain(T_OCEAN));
      }
    }
  }
  return pl;
}
Exemplo n.º 20
0
void age_dragon(unit * u)
{
  if (u->number > 0 && rng_int() % 100 < age_chance(u->age, WYRMAGE, 1)) {
    double q = (double)u->hp / (double)(unit_max_hp(u) * u->number);
    u_setrace(u, new_race[RC_WYRM]);
    u->irace = NULL;
    u->hp = (int)(unit_max_hp(u) * u->number * q);
  }
}
Exemplo n.º 21
0
void scale_number(unit * u, int n)
{
  skill_t sk;
  const attrib *a;
  int remain;

  if (n == u->number)
    return;
  if (n && u->number > 0) {
    int full;
    remain = ((u->hp % u->number) * (n % u->number)) % u->number;

    full = u->hp / u->number;   /* wieviel kriegt jede person mindestens */
    u->hp = full * n + (u->hp - full * u->number) * n / u->number;
    assert(u->hp >= 0);
    if ((rng_int() % u->number) < remain)
      ++u->hp;                  /* Nachkommastellen */
  } else {
    remain = 0;
    u->hp = 0;
  }
  if (u->number > 0) {
    for (a = a_find(u->attribs, &at_effect); a && a->type == &at_effect;
      a = a->next) {
      effect_data *data = (effect_data *) a->data.v;
      int snew = data->value / u->number * n;
      if (n) {
        remain = data->value - snew / n * u->number;
        snew += remain * n / u->number;
        remain = (remain * n) % u->number;
        if ((rng_int() % u->number) < remain)
          ++snew;               /* Nachkommastellen */
      }
      data->value = snew;
    }
  }
  if (u->number == 0 || n == 0) {
    for (sk = 0; sk < MAXSKILLS; sk++) {
      remove_skill(u, sk);
    }
  }

  set_number(u, n);
}
Exemplo n.º 22
0
static void eaten_by_monster(unit * u)
{
  /* adjustment for smaller worlds */
  static double multi = 0.0;
  int n = 0;
  int horse = 0;

  if (multi == 0.0) {
    multi = RESOURCE_QUANTITY * newterrain(T_PLAIN)->size / 10000.0;
  }

  switch (old_race(u_race(u))) {
    case RC_FIREDRAGON:
      n = rng_int() % 80 * u->number;
      horse = get_item(u, I_HORSE);
      break;
    case RC_DRAGON:
      n = rng_int() % 200 * u->number;
      horse = get_item(u, I_HORSE);
      break;
    case RC_WYRM:
      n = rng_int() % 500 * u->number;
      horse = get_item(u, I_HORSE);
      break;
    default:
      n = rng_int() % (u->number / 20 + 1);
  }

  n = (int)(n * multi);
  if (n > 0) {
    n = lovar(n);
    n = MIN(rpeasants(u->region), n);

    if (n > 0) {
      deathcounts(u->region, n);
      rsetpeasants(u->region, rpeasants(u->region) - n);
      ADDMSG(&u->region->msgs, msg_message("eatpeasants", "unit amount", u, n));
    }
  }
  if (horse > 0) {
    set_item(u, I_HORSE, 0);
    ADDMSG(&u->region->msgs, msg_message("eathorse", "unit amount", u, horse));
  }
}
Exemplo n.º 23
0
static void encounter(region * r, unit * u)
{
  if (!fval(r, RF_ENCOUNTER))
    return;
  freset(r, RF_ENCOUNTER);
  if (rng_int() % 100 >= ENCCHANCE)
    return;
  switch (rng_int() % 3) {
    case 0:
      find_manual(r, u);
      break;
    case 1:
      get_villagers(r, u);
      break;
    case 2:
      get_allies(r, u);
      break;
  }
}
Exemplo n.º 24
0
void age_firedragon(unit * u)
{
  if (u->number > 0 && rng_int() % 100 < age_chance(u->age, DRAGONAGE, 1)) {
    double q = (double)u->hp / (double)(unit_max_hp(u) * u->number);
    u_setrace(u, new_race[RC_DRAGON]);
    u->irace = NULL;
    scale_number(u, 1);
    u->hp = (int)(unit_max_hp(u) * u->number * q);
  }
}
Exemplo n.º 25
0
void gen_random_permutation(perm_t *perm, size_t nr, size_t base)
{
	size_t i;

	for (i = 0; i < nr; ++i) {
		size_t t = rng_int(i);
		perm[i] = perm[t];
		perm[t] = base + i;
	}
}
Exemplo n.º 26
0
static void use_default(rawmaterial * res, const region * r, int amount)
{
    assert(res->amount > 0 && amount >= 0 && amount <= res->amount);
    res->amount -= amount;
    while (res->amount == 0) {
        double modifier =
            1.0 + ((rng_int() % (SHIFT * 2 + 1)) - SHIFT) * ((rng_int() % (SHIFT * 2 +
            1)) - SHIFT) / 10000.0;
        int i;

        for (i = 0; r->terrain->production[i].type; ++i) {
            if (res->type->rtype == r->terrain->production[i].type)
                break;
        }

        ++res->level;
        update_resource(res, modifier);
    }
}
Exemplo n.º 27
0
Arquivo: races.c Projeto: hochl/server
static void equip_newunits(const struct equipment *eq, struct unit *u)
{
    struct region *r = u->region;
    const struct resource_type *rtype;
    switch (old_race(u_race(u))) {
    case RC_ELF:
        rtype = rt_find("fairyboot");
        set_show_item(u->faction, rtype->itype);
        break;
    case RC_GOBLIN:
        rtype = rt_find("roi");
        set_show_item(u->faction, rtype->itype);
        set_number(u, 10);
    break;
    case RC_HUMAN:
        if (u->building == NULL) {
            const building_type *btype = bt_find("castle");
            if (btype != NULL) {
                building *b = new_building(btype, r, u->faction->locale);
                b->size = 10;
                u_set_building(u, b);
                building_set_owner(u);
            }
        }
        break;
    case RC_CAT:
        rtype = rt_find("roi");
        set_show_item(u->faction, rtype->itype);
        break;
    case RC_AQUARIAN:
        {
            ship *sh = new_ship(st_find("boat"), r, u->faction->locale);
            sh->size = sh->type->construction->maxsize;
            u_set_ship(u, sh);
        }
        break;
    case RC_CENTAUR:
        rsethorses(r, 250 + rng_int() % 51 + rng_int() % 51);
        break;
    default:
        break;
  }
}
Exemplo n.º 28
0
static int
enter_arena(unit * u, const item_type * itype, int amount, order * ord)
{
  skill_t sk;
  region *r = u->region;
  unit *u2;
  int fee = u->faction->score / 5;
  unused(ord);
  unused(amount);
  unused(itype);
  if (fee > 2000)
    fee = 2000;
  if (getplane(r) == arena)
    return -1;
  if (u->number != 1 && enter_fail(u))
    return -1;
  if (get_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT, fee) < fee
    && enter_fail(u))
    return -1;
  for (sk = 0; sk != MAXSKILLS; ++sk) {
    if (get_level(u, sk) > 1 && enter_fail(u))
      return -1;
  }
  for (u2 = r->units; u2; u2 = u2->next)
    if (u2->faction == u->faction)
      break;

  assert(!"not implemented");
/*
	for (res=0;res!=MAXRESOURCES;++res) if (res!=R_SILVER && res!=R_ARENA_GATE && (is_item(res) || is_herb(res) || is_potion(res))) {
		int x = get_resource(u, res);
		if (x) {
			if (u2) {
				change_resource(u2, res, x);
				change_resource(u, res, -x);
			}
			else if (enter_fail(u)) return -1;
		}
	}
*/
  if (get_money(u) > fee) {
    if (u2)
      change_money(u2, get_money(u) - fee);
    else if (enter_fail(u))
      return -1;
  }
  ADDMSG(&u->faction->msgs, msg_message("arena_enter_fail", "region unit",
      u->region, u));
  use_pooled(u, itype->rtype, GET_SLACK | GET_RESERVE, 1);
  use_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT, fee);
  set_money(u, 109);
  fset(u, UFL_ANON_FACTION);
  move_unit(u, start_region[rng_int() % 6], NULL);
  return 0;
}
Exemplo n.º 29
0
void age_ghoul(unit * u)
{
  if (is_monsters(u->faction) && rng_int() % 100 < age_chance(u->age, 27, 1)) {
    int n = _max(1, u->number / 2);
    double q = (double)u->hp / (double)(unit_max_hp(u) * u->number);
    u_setrace(u, get_race(RC_GHOUL_LORD));
    u->irace = NULL;
    scale_number(u, n);
    u->hp = (int)(unit_max_hp(u) * u->number * q);
  }
}
Exemplo n.º 30
0
static direction_t random_neighbour(region * r, unit * u)
{
    int i;
    region *rc;
    region * next[MAXDIRECTIONS];
    int rr, c = 0, c2 = 0;

    get_neighbours(r, next);
    /* Nachsehen, wieviele Regionen in Frage kommen */

    for (i = 0; i != MAXDIRECTIONS; i++) {
        rc = next[i];
        if (rc && can_survive(u, rc)) {
            if (room_for_race_in_region(rc, u_race(u))) {
                c++;
            }
            c2++;
        }
    }

    if (c == 0) {
        if (c2 == 0) {
            return NODIRECTION;
        }
        else {
            c = c2;
            c2 = 0;                   /* c2 == 0 -> room_for_race nicht beachten */
        }
    }

    /* Zufällig eine auswählen */

    rr = rng_int() % c;

    /* Durchzählen */

    c = -1;
    for (i = 0; i != MAXDIRECTIONS; i++) {
        rc = next[i];
        if (rc && can_survive(u, rc)) {
            if (c2 == 0) {
                c++;
            }
            else if (room_for_race_in_region(rc, u_race(u))) {
                c++;
            }
            if (c == rr)
                return (direction_t)i;
        }
    }

    assert(1 == 0);               /* Bis hierhin sollte er niemals kommen. */
    return NODIRECTION;
}