예제 #1
0
파일: bind_region.c 프로젝트: stm2/server
static int tolua_region_get_terrainname(lua_State * L)
{
    region *self = (region *)tolua_tousertype(L, 1, 0);
    attrib *a = a_find(self->attribs, &at_racename);
    if (a) {
        tolua_pushstring(L, get_racename(a));
        return 1;
    }
    return 0;
}
예제 #2
0
파일: randenc.c 프로젝트: hochl/server
static void get_allies(region * r, unit * u)
{
  unit *newunit = NULL;
  const char *name;
  const char *equip;
  int number;
  message *msg;

  assert(u->number);

  switch (rterrain(r)) {
    case T_PLAIN:
      if (!r_isforest(r)) {
        if (get_money(u) / u->number < 100 + rng_int() % 200)
          return;
        name = "random_plain_men";
        equip = "random_plain";
        number = rng_int() % 8 + 2;
        break;
      } else {
        if (eff_skill(u, SK_LONGBOW, r) < 3
          && eff_skill(u, SK_HERBALISM, r) < 2
          && eff_skill(u, SK_MAGIC, r) < 2) {
          return;
        }
        name = "random_forest_men";
        equip = "random_forest";
        number = rng_int() % 6 + 2;
      }
      break;

    case T_SWAMP:
      if (eff_skill(u, SK_MELEE, r) <= 1) {
        return;
      }
      name = "random_swamp_men";
      equip = "random_swamp";
      number = rng_int() % 6 + 2;
      break;

    case T_DESERT:
      if (eff_skill(u, SK_RIDING, r) <= 2) {
        return;
      }
      name = "random_desert_men";
      equip = "random_desert";
      number = rng_int() % 12 + 2;
      break;

    case T_HIGHLAND:
      if (eff_skill(u, SK_MELEE, r) <= 1) {
        return;
      }
      name = "random_highland_men";
      equip = "random_highland";
      number = rng_int() % 8 + 2;
      break;

    case T_MOUNTAIN:
      if (eff_skill(u, SK_MELEE, r) <= 1 || eff_skill(u, SK_TRADE, r) <= 2) {
        return;
      }
      name = "random_mountain_men";
      equip = "random_mountain";
      number = rng_int() % 6 + 2;
      break;

    case T_GLACIER:
      if (eff_skill(u, SK_MELEE, r) <= 1 || eff_skill(u, SK_TRADE, r) <= 1) {
        return;
      }
      name = "random_glacier_men";
      equip = "random_glacier";
      number = rng_int() % 4 + 2;
      break;

    default:
      return;
  }

  newunit =
    create_unit(r, u->faction, number, u->faction->race, 0,
    LOC(u->faction->locale, name), u);
  equip_unit(newunit, get_equipment(equip));

  u_setfaction(newunit, u->faction);
  set_racename(&newunit->attribs, get_racename(u->attribs));
  if (u_race(u)->flags & RCF_SHAPESHIFT) {
    newunit->irace = u->irace;
  }
  if (fval(u, UFL_ANON_FACTION))
    fset(newunit, UFL_ANON_FACTION);
  fset(newunit, UFL_ISNEW);

  msg = msg_message("encounter_allies", "unit name", u, name);
  r_addmessage(r, u->faction, msg);
  msg_release(msg);
}
예제 #3
0
파일: unit.c 프로젝트: UweKopf/server
/** creates a new unit.
*
* @param dname: name, set to NULL to get a default.
* @param creator: unit to inherit stealth, group, building, ship, etc. from
*/
unit *create_unit(region * r, faction * f, int number, const struct race *urace,
  int id, const char *dname, unit * creator)
{
  unit *u = (unit *)calloc(1, sizeof(unit));

  assert(urace);
  if (f) {
    assert(f->alive);
    u_setfaction(u, f);

    if (f->locale) {
      order *deford = default_order(f->locale);
      if (deford) {
        set_order(&u->thisorder, NULL);
        addlist(&u->orders, deford);
      }
    }
  }
  u_seteffstealth(u, -1);
  u_setrace(u, urace);
  u->irace = NULL;

  set_number(u, number);

  /* die nummer der neuen einheit muss vor name_unit generiert werden,
   * da der default name immer noch 'Nummer u->no' ist */
  createunitid(u, id);

  /* zuerst in die Region setzen, da zb Drachennamen den Regionsnamen
   * enthalten */
  if (r)
    move_unit(u, r, NULL);

  /* u->race muss bereits gesetzt sein, wird für default-hp gebraucht */
  /* u->region auch */
  u->hp = unit_max_hp(u) * number;

  if (!dname) {
    name_unit(u);
  } else {
    u->name = _strdup(dname);
  }

  if (creator) {
    attrib *a;

    /* erbt Kampfstatus */
    setstatus(u, creator->status);

    /* erbt Gebäude/Schiff */
    if (creator->region == r) {
      if (creator->building) {
        u_set_building(u, creator->building);
      }
      if (creator->ship && fval(u_race(u), RCF_CANSAIL)) {
        u_set_ship(u, creator->ship);
      }
    }

    /* Tarnlimit wird vererbt */
    if (fval(creator, UFL_STEALTH)) {
      attrib *a = a_find(creator->attribs, &at_stealth);
      if (a) {
        int stealth = a->data.i;
        a = a_add(&u->attribs, a_new(&at_stealth));
        a->data.i = stealth;
      }
    }

    /* Temps von parteigetarnten Einheiten sind wieder parteigetarnt */
    if (fval(creator, UFL_ANON_FACTION)) {
      fset(u, UFL_ANON_FACTION);
    }
    /* Daemonentarnung */
    set_racename(&u->attribs, get_racename(creator->attribs));
    if (fval(u_race(u), RCF_SHAPESHIFT) && fval(u_race(creator), RCF_SHAPESHIFT)) {
      u->irace = creator->irace;
    }

    /* Gruppen */
    if (creator->faction == f && fval(creator, UFL_GROUP)) {
      a = a_find(creator->attribs, &at_group);
      if (a) {
        group *g = (group *) a->data.v;
        set_group(u, g);
      }
    }
    a = a_find(creator->attribs, &at_otherfaction);
    if (a) {
      a_add(&u->attribs, make_otherfaction(get_otherfaction(a)));
    }

    a = a_add(&u->attribs, a_new(&at_creator));
    a->data.v = creator;
  }

  return u;
}