Exemplo n.º 1
0
static quicklist * get_island(region * root)
{
    quicklist * ql, *result = 0;
    int qi = 0;

    fset(root, RF_MARK);
    ql_push(&result, root);

    for (ql = result, qi = 0; ql; ql_advance(&ql, &qi, 1)) {
        int dir;
        region *r = (region *)ql_get(ql, qi);
        region * next[MAXDIRECTIONS];

        get_neighbours(r, next);

        for (dir = 0; dir != MAXDIRECTIONS; ++dir) {
            region *rn = next[dir];
            if (rn != NULL && rn->land && !fval(rn, RF_MARK)) {
                fset(rn, RF_MARK);
                ql_push(&result, rn);
            }
        }
    }

    for (ql = result, qi = 0; ql; ql_advance(&ql, &qi, 1)) {
        region *r = (region *)ql_get(ql, qi);
        freset(r, RF_MARK);
    }
    return result;
}
Exemplo n.º 2
0
void register_Ray_class() {

    {   //::xfx::Ray
        typedef bp::class_< xfx::Ray > Ray_exposer_t;
        Ray_exposer_t Ray_exposer = Ray_exposer_t( "Ray", bp::init< >() );
        bp::scope Ray_scope( Ray_exposer );
        Ray_exposer.def( bp::init< xfx::Vec3 const &, xfx::Vec3 const & >(( bp::arg("origin"), bp::arg("direction") )) );
        {   //::xfx::Ray::Point

            typedef ::xfx::Vec3 ( ::xfx::Ray::*point_function_type )( float ) const;

            Ray_exposer.def(
                "point"
                , point_function_type( &::xfx::Ray::Point )
                , ( bp::arg("t") ) );

        }
        {   //::xfx::Ray::Transform

            typedef void ( ::xfx::Ray::*transform_function_type )( ::xfx::Mat4 const & ) ;

            Ray_exposer.def(
                "transform"
                , transform_function_type( &::xfx::Ray::Transform )
                , ( bp::arg("m") ) );

        }
        {   //property "origin"[fget=::xfx::Ray::Origin, fset=::xfx::Ray::SetOrigin]

            typedef ::xfx::Vec3 const & ( ::xfx::Ray::*fget )(  ) const;
            typedef void ( ::xfx::Ray::*fset )( ::xfx::Vec3 const & ) ;

            Ray_exposer.add_property(
                "origin"
                , bp::make_function(
                    fget( &::xfx::Ray::Origin )
                    , bp::return_value_policy< bp::copy_const_reference >() )
                , fset( &::xfx::Ray::SetOrigin )
                , "get\\set property, built on top of \"xfx::Vec3 const & xfx::Ray::Origin() const [member function]\" and \"void xfx::Ray::SetOrigin(xfx::Vec3 const & origin) [member function]\"" );

        }
        {   //property "direction"[fget=::xfx::Ray::Direction, fset=::xfx::Ray::SetDirection]

            typedef ::xfx::Vec3 const & ( ::xfx::Ray::*fget )(  ) const;
            typedef void ( ::xfx::Ray::*fset )( ::xfx::Vec3 const & ) ;

            Ray_exposer.add_property(
                "direction"
                , bp::make_function(
                    fget( &::xfx::Ray::Direction )
                    , bp::return_value_policy< bp::copy_const_reference >() )
                , fset( &::xfx::Ray::SetDirection )
                , "get\\set property, built on top of \"xfx::Vec3 const & xfx::Ray::Direction() const [member function]\" and \"void xfx::Ray::SetDirection(xfx::Vec3 const & dir) [member function]\"" );

        }
        bp::register_ptr_to_python< boost::shared_ptr< xfx::Ray const > >( );
        bp::implicitly_convertible< boost::shared_ptr< xfx::Ray >, boost::shared_ptr< xfx::Ray const > >( );
    }

}
Exemplo n.º 3
0
void setguard(unit * u, bool enabled)
{
    if (!enabled) {
        freset(u, UFL_GUARD);
    } else {
        assert(!fval(u, UFL_MOVED));
        assert(u->status < ST_FLEE);
        fset(u, UFL_GUARD);
        fset(u->region, RF_GUARDED);
    }
}
Exemplo n.º 4
0
void register_V3DPluginArgItem_class(){

    { //::V3DPluginArgItem
        typedef bp::class_< V3DPluginArgItem > V3DPluginArgItem_exposer_t;
        V3DPluginArgItem_exposer_t V3DPluginArgItem_exposer = V3DPluginArgItem_exposer_t( "V3DPluginArgItem" );
        bp::scope V3DPluginArgItem_scope( V3DPluginArgItem_exposer );
        { //property "type"[fget=::get_argitem_type, fset=::set_argitem_type]
        
            typedef ::std::string ( *fget )( ::V3DPluginArgItem const & );
            typedef void ( *fset )( ::V3DPluginArgItem &,::std::string const & );
            
            V3DPluginArgItem_exposer.add_property( 
                "type"
                , fget( &::get_argitem_type )
                , fset( &::set_argitem_type ) );
        
        }
        V3DPluginArgItem_exposer.add_property("p",
                    bp::make_function(&get_pluginargitem_pointer,
                        bp::return_internal_reference<>()),
                    bp::make_function(&set_pluginargitem_pointer,
                        bp::with_custodian_and_ward<1,2>() ));
    }

}
Exemplo n.º 5
0
static void melt_iceberg(region * r)
{
  attrib *a;
  unit *u;

  for (u = r->units; u; u = u->next)
    freset(u->faction, FFL_SELECT);
  for (u = r->units; u; u = u->next)
    if (!fval(u->faction, FFL_SELECT)) {
      fset(u->faction, FFL_SELECT);
      ADDMSG(&u->faction->msgs, msg_message("iceberg_melt", "region", r));
    }

  /* driftrichtung löschen */
  a = a_find(r->attribs, &at_iceberg);
  if (a)
    a_remove(&r->attribs, a);

  /* Gebäude löschen */
  while (r->buildings) {
    remove_building(&r->buildings, r->buildings);
  }

  /* in Ozean wandeln */
  terraform_region(r, newterrain(T_OCEAN));

  /* Einheiten, die nicht schwimmen können oder in Schiffen sind,
   * ertrinken */
  drown(r);
}
Exemplo n.º 6
0
void set_group(struct unit *u, struct group *g)
{
    attrib *a = NULL;

    if (fval(u, UFL_GROUP)) {
        a = a_find(u->attribs, &at_group);
    }

    if (a) {
        group *og = (group *)a->data.v;
        if (og == g)
            return;
        --og->members;
    }

    if (g) {
        if (!a) {
            a = a_add(&u->attribs, a_new(&at_group));
            fset(u, UFL_GROUP);
        }
        a->data.v = g;
        g->members++;
    }
    else if (a) {
        a_remove(&u->attribs, a);
        freset(u, UFL_GROUP);
    }
}
Exemplo n.º 7
0
/**
 ** GM: GATE <id> <x> <y>
 ** requires: permission-key "gmgate"
 **/
static void gm_gate(const void *tnext, struct unit * u, struct order *ord)
{
  const struct plane *pl = rplane(u->region);
  int id = getid();
  int x = rel_to_abs(pl, u->faction, getint(), 0);
  int y = rel_to_abs(pl, u->faction, getint(), 1);
  building *b = findbuilding(id);
  region *r;

  pnormalize(&x, &y, pl);
  r = findregion(x, y);
  if (b == NULL || r == NULL || pl != rplane(b->region) || pl != rplane(r)) {
    mistake(u, ord, "the unit cannot transform this building.");
    return;
  } else {
    /* checking permissions */
    attrib *permissions = a_find(u->faction->attribs, &at_permissions);
    if (permissions && has_permission(permissions, atoi36("gmgate"))) {
      remove_triggers(&b->attribs, "timer", &tt_gate);
      remove_triggers(&b->attribs, "create", &tt_unguard);
      if (r != b->region) {
        add_trigger(&b->attribs, "timer", trigger_gate(b, r));
        add_trigger(&b->attribs, "create", trigger_unguard(b));
        fset(b, BLD_UNGUARDED);
      }
    }
  }
}
Exemplo n.º 8
0
void move_unit(unit * u, region * r, unit ** ulist)
{
  assert(u && r);

  assert(u->faction || !"this unit is dead");
  if (u->region == r)
    return;
  if (!ulist)
    ulist = (&r->units);
  if (u->region) {
    setguard(u, GUARD_NONE);
    fset(u, UFL_MOVED);
    if (u->ship || u->building) {
      /* can_leave must be checked in travel_i */
#ifndef NDEBUG
      bool result = leave(u, false);
      assert(result);
#else
      leave(u, false);
#endif
    }
    translist(&u->region->units, ulist, u);
  } else {
    addlist(ulist, u);
  }

#ifdef SMART_INTERVALS
  update_interval(u->faction, r);
#endif
  u->region = r;
}
Exemplo n.º 9
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.º 10
0
/**
 ** GM: TELL PLANE <string>
 ** requires: permission-key "gmmsgr"
 **/
static void gm_messageplane(const void *tnext, struct unit *gm, struct order *ord)
{
  const struct plane *p = rplane(gm->region);
  const char *zmsg = getstrtoken();
  if (p == NULL) {
    mistake(gm, ord, "In diese Ebene kann keine Nachricht gesandt werden.");
  } else {
    /* checking permissions */
    attrib *permissions = a_find(gm->faction->attribs, &at_permissions);
    if (!permissions || !has_permission(permissions, atoi36("gmmsgr"))) {
      mistake(gm, ord, "permission denied.");
    } else {
      message *msg = msg_message("msg_event", "string", zmsg);
      faction *f;
      region *r;
      for (f = factions; f; f = f->next) {
        freset(f, FFL_SELECT);
      }
      for (r = regions; r; r = r->next) {
        unit *u;
        if (rplane(r) != p)
          continue;
        for (u = r->units; u; u = u->next)
          if (!fval(u->faction, FFL_SELECT)) {
            f = u->faction;
            fset(f, FFL_SELECT);
            add_message(&f->msgs, msg);
          }
      }
      msg_release(msg);
    }
  }
}
Exemplo n.º 11
0
static void recruit_dracoids(unit * dragon, int size)
{
    faction *f = dragon->faction;
    region *r = dragon->region;
    const struct item *weapon = NULL;
    order *new_order = NULL;
    unit *un = create_unit(r, f, size, get_race(RC_DRACOID), 0, NULL, NULL);

    fset(un, UFL_ISNEW | UFL_MOVED);

    name_unit(un);
    change_money(dragon, -un->number * 50);
    equip_unit(un, get_equipment("recruited_dracoid"));

    setstatus(un, ST_FIGHT);
    for (weapon = un->items; weapon; weapon = weapon->next) {
        const weapon_type *wtype = weapon->type->rtype->wtype;
        if (wtype && (wtype->flags & WTF_MISSILE)) {
            setstatus(un, ST_BEHIND);
        }
        new_order = create_order(K_STUDY, f->locale, "'%s'",
            skillname(weapon->type->rtype->wtype->skill, f->locale));
    }

    if (new_order != NULL) {
        addlist(&un->orders, new_order);
    }
}
Exemplo n.º 12
0
/* Magier weicht dem Kampf aus. Wenn er sich bewegen kann, zieht er in
 * eine Nachbarregion, wobei ein NACH berücksichtigt wird. Ansonsten
 * bleibt er stehen und nimmt nicht weiter am Kampf teil. */
int sp_denyattack(struct castorder * co)
{
  fighter * fi = co->magician.fig;
  int level = co->level;

  const spell * sp = co->sp;
  battle *b = fi->side->battle;
  unit *mage = fi->unit;
  region *r = b->region;
  message *m;

  /* Fliehende Einheiten verlassen auf jeden Fall Gebäude und Schiffe. */
  if (!fval(r->terrain, SEA_REGION)) {
    leave(mage, false);
  }
  /* und bewachen nicht */
  setguard(mage, GUARD_NONE);
  /* irgendwie den langen befehl sperren */
  /* fset(fi, FIG_ATTACKED); */

  /* wir tun so, als wäre die Person geflohen */
  fset(fi, FIG_NOLOOT);
  fi->run.hp = mage->hp;
  fi->run.number = mage->number;
  /* fighter leeren */
  rmfighter(fi, mage->number);

  m = msg_message("cast_escape_effect", "mage spell", fi->unit, sp);
  message_all(b, m);
  msg_release(m);

  return level;
}
Exemplo n.º 13
0
static void test_piracy_cmd_errors(CuTest * tc) {
    race *r;
    faction *f;
    unit *u, *u2;
    ship_type *st_boat;

    test_setup();
    setup_piracy();

    st_boat = st_get_or_create("boat");
    r = test_create_race("pirates");
    u = test_create_unit(f = test_create_faction(r), test_create_region(0, 0, get_or_create_terrain("ocean")));
    f->locale = test_create_locale();
    u->thisorder = create_order(K_PIRACY, f->locale, "");
    assert(u && u->thisorder);

    piracy_cmd(u);
    CuAssertPtrNotNullMsg(tc, "must be on a ship for PIRACY", test_find_messagetype(f->msgs, "error144"));

    test_clear_messages(f);
    fset(r, RCF_SWIM);
    piracy_cmd(u);
    CuAssertPtrEquals_Msg(tc, "swimmers are pirates", 0, test_find_messagetype(f->msgs, "error144"));
    CuAssertPtrEquals_Msg(tc, "swimmers are pirates", 0, test_find_messagetype(f->msgs, "error146"));
    freset(r, RCF_SWIM);
    fset(r, RCF_FLY);
    CuAssertPtrEquals_Msg(tc, "flyers are pirates", 0, test_find_messagetype(f->msgs, "error144"));
    freset(r, RCF_FLY);
    test_clear_messages(f);

    u_set_ship(u, test_create_ship(u->region, st_boat));

    u2 = test_create_unit(u->faction, u->region);
    u2->thisorder = create_order(K_PIRACY, f->locale, "");
    u_set_ship(u2, u->ship);

    test_clear_messages(f);
    piracy_cmd(u2);
    CuAssertPtrNotNullMsg(tc, "must be owner for PIRACY", test_find_messagetype(f->msgs, "error146"));

    test_clear_messages(f);
    piracy_cmd(u);
    CuAssertPtrNotNullMsg(tc, "must specify target for PIRACY", test_find_messagetype(f->msgs, "piratenovictim"));
    CuAssertPtrNotNull(tc, u->thisorder);

    test_teardown();
}
Exemplo n.º 14
0
    void AGAST::detect( FeatureSet& features, const Image& img )
    {
        if( img.format() != IFormat::GRAY_UINT8 )
            throw CVTException( "Input Image format must be GRAY_UINT8" );

        FeatureSetWrapper fset( features );
        _astDetector->detect( img, _threshold, fset, _border );
    }
Exemplo n.º 15
0
static void move_icebergs(void)
{
  region *r;

  for (r = regions; r; r = r->next) {
    if (r->terrain == newterrain(T_ICEBERG) && !fval(r, RF_SELECT)) {
      int select = rng_int() % 10;
      if (select < 4) {
        /* 4% chance */
        fset(r, RF_SELECT);
        melt_iceberg(r);
      } else if (select < 64) {
        /* 60% chance */
        fset(r, RF_SELECT);
        move_iceberg(r);
      }
    }
  }
}
Exemplo n.º 16
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.º 17
0
static void
get_island_info(region * root, int *size_p, int *inhabited_p, int *maxage_p)
{
    int qi, size = 0, maxage = 0, inhabited = 0;
    quicklist *ql, *island = NULL;

    ql_push(&island, root);
    fset(root, RF_MARK);

    for (ql = island, qi = 0; ql; ql_advance(&ql, &qi, 1)) {
        int d;
        region *r = (region *)ql_get(ql, qi);
        if (r->units) {
            unit *u;
            for (u = r->units; u; u = u->next) {
                if (!fval(u->faction, FFL_NOIDLEOUT) && u->faction->age > maxage) {
                    maxage = u->faction->age;
                }
            }
            ++inhabited;
        }
        ++size;
        for (d = 0; d != MAXDIRECTIONS; ++d) {
            region *rn = rconnect(r, d);
            if (rn && !fval(rn, RF_MARK) && rn->land) {
                ql_push(&island, rn);
                fset(rn, RF_MARK);
            }
        }
    }
    for (ql = island, qi = 0; ql; ql_advance(&ql, &qi, 1)) {
        region *r = (region *)ql_get(ql, qi);
        freset(r, RF_MARK);
    }
    ql_free(island);
    if (size_p)
        *size_p = size;
    if (inhabited_p)
        *inhabited_p = inhabited;
    if (maxage_p)
        *maxage_p = maxage;
}
FontFileLister::CollectionResult FontConfigFontFileLister::GetFontPaths(std::string const& facename, int bold, bool italic, std::set<wxUniChar> const& characters) {
	CollectionResult ret;

	std::string family(facename);
	if (family[0] == '@')
		family.erase(0, 1);
	boost::to_lower(family);

	int weight = bold == 0 ? 80 :
	             bold == 1 ? 200 :
	                         bold;
	int slant  = italic ? 110 : 0;

	// Create a fontconfig pattern to match the desired weight/slant
	agi::scoped_holder<FcPattern*> pat(FcPatternCreate(), FcPatternDestroy);
	if (!pat) return ret;

	FcPatternAddBool(pat, FC_OUTLINE, true);
	FcPatternAddInteger(pat, FC_SLANT, slant);
	FcPatternAddInteger(pat, FC_WEIGHT, weight);

	FcDefaultSubstitute(pat);
	if (!FcConfigSubstitute(config, pat, FcMatchPattern)) return ret;

	// Create a font set with only correctly named fonts
	// This is needed because the patterns returned by font matching only
	// include the first family and fullname, so we can't always verify that
	// we got the actual font we were asking for after the fact
	agi::scoped_holder<FcFontSet*> fset(FcFontSetCreate(), FcFontSetDestroy);
	find_font(FcConfigGetFonts(config, FcSetApplication), fset, family);
	find_font(FcConfigGetFonts(config, FcSetSystem), fset, family);

	// Get the best match from fontconfig
	FcResult result;
	FcFontSet *sets[] = { (FcFontSet*)fset };
	agi::scoped_holder<FcPattern*> match(FcFontSetMatch(config, sets, 1, pat, &result), FcPatternDestroy);
	if (!match)
		return ret;

	FcChar8 *file;
	if(FcPatternGetString(match, FC_FILE, 0, &file) != FcResultMatch)
		return ret;

	FcCharSet *charset;
	if (FcPatternGetCharSet(match, FC_CHARSET, 0, &charset) == FcResultMatch) {
		for (wxUniChar chr : characters) {
			if (!FcCharSetHasChar(charset, chr))
				ret.missing += chr;
		}
	}

	ret.paths.emplace_back((const char *)file);
	return ret;
}
Exemplo n.º 19
0
static int do_potion(unit * u, region *r, const potion_type * ptype, int amount)
{
  if (ptype == oldpotiontype[P_LIFE]) {
    int holz = 0;
    static int tree_type = -1;
    static int tree_count = -1;
    if (tree_type < 0) {
      tree_type = get_param_int(global.parameters, "rules.magic.wol_type", 1);
      tree_count =
        get_param_int(global.parameters, "rules.magic.wol_effect", 10);
    }
    /* mallorn is required to make mallorn forests, wood for regular ones */
    if (fval(r, RF_MALLORN)) {
      holz = use_pooled(u, rt_find("mallorn"),
        GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, tree_count * amount);
    } else {
      holz = use_pooled(u, rt_find("log"),
        GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, tree_count * amount);
    }
    if (r->land == 0)
      holz = 0;
    if (holz < tree_count * amount) {
      int x = holz / tree_count;
      if (holz % tree_count)
        ++x;
      if (x < amount)
        amount = x;
    }
    rsettrees(r, tree_type, rtrees(r, tree_type) + holz);
    ADDMSG(&u->faction->msgs, msg_message("growtree_effect",
        "mage amount", u, holz));
  } else if (ptype == oldpotiontype[P_HEILWASSER]) {
    u->hp = _min(unit_max_hp(u) * u->number, u->hp + 400 * amount);
  } else if (ptype == oldpotiontype[P_PEOPLE]) {
    attrib *a = (attrib *) a_find(r->attribs, &at_peasantluck);
    if (!a)
      a = a_add(&r->attribs, a_new(&at_peasantluck));
    a->data.i += amount;
  } else if (ptype == oldpotiontype[P_HORSE]) {
    attrib *a = (attrib *) a_find(r->attribs, &at_horseluck);
    if (!a)
      a = a_add(&r->attribs, a_new(&at_horseluck));
    a->data.i += amount;
  } else if (ptype == oldpotiontype[P_WAHRHEIT]) {
    fset(u, UFL_DISBELIEVES);
    amount = 1;
  } else if (ptype == oldpotiontype[P_MACHT]) {
    /* Verfünffacht die HP von max. 10 Personen in der Einheit */
    u->hp += _min(u->number, 10 * amount) * unit_max_hp(u) * 4;
  } else {
    change_effect(u, ptype, 10 * amount);
  }
  return amount;
}
Exemplo n.º 20
0
static void test_monsters_waiting(CuTest * tc)
{
    faction *f, *f2;
    unit *u, *m;

    create_monsters(&f, &f2, &u, &m);
    setguard(m, true);
    fset(m, UFL_ISNEW);
    monster_attacks(m, false, false);
    CuAssertPtrEquals(tc, 0, find_order("attack 1", m));
    test_cleanup();
}
Exemplo n.º 21
0
static void test_give_new_unit(CuTest * tc) {
    struct give env = { 0 };

    test_setup_ex(tc);
    env.f1 = test_create_faction(NULL);
    env.f2 = test_create_faction(NULL);
    setup_give(&env);
    env.dst->number = 0;
    fset(env.dst, UFL_ISNEW);
    CuAssertPtrEquals(tc, NULL, check_give(env.src, env.dst, NULL));
    test_teardown();
}
Exemplo n.º 22
0
faction *get_or_create_monsters(void)
{
    faction *f = findfaction(MONSTER_ID);
    if (!f) {
        const race *rc = rc_get_or_create("dragon");
        const char *email = get_param(global.parameters, "monster.email");
        f = addfaction(email ? email : "*****@*****.**", NULL, rc, default_locale, 0);
        renumber_faction(f, MONSTER_ID);
        faction_setname(f, "Monster");
        fset(f, FFL_NPC | FFL_NOIDLEOUT);
    }
    return f;
}
Exemplo n.º 23
0
static void test_monsters_waiting(CuTest * tc)
{
    faction *f, *f2;
    region *r;
    unit *u, *m;

    create_monsters(&f, &f2, &r, &u, &m);
    guard(m, GUARD_TAX);
    fset(m, UFL_ISNEW);
    monster_attacks(m, false, false);
    CuAssertPtrEquals(tc, 0, find_order("ATTACKIERE 1", m));
    test_cleanup();
}
Exemplo n.º 24
0
/** Drachen und Seeschlangen können entstehen */
void spawn_dragons(void)
{
    region *r;
    faction *monsters = get_or_create_monsters();

    for (r = regions; r; r = r->next) {
        unit *u;

        if (fval(r->terrain, SEA_REGION) && rng_int() % 10000 < 1) {
            u = create_unit(r, monsters, 1, get_race(RC_SEASERPENT), 0, NULL, NULL);
            fset(u, UFL_ISNEW | UFL_MOVED);
            equip_unit(u, get_equipment("monster_seaserpent"));
        }

        if ((r->terrain == newterrain(T_GLACIER)
            || r->terrain == newterrain(T_SWAMP)
            || r->terrain == newterrain(T_DESERT))
            && rng_int() % 10000 < (5 + 100 * chaosfactor(r))) {
            if (chance(0.80)) {
                u = create_unit(r, monsters, nrand(60, 20) + 1, get_race(RC_FIREDRAGON), 0, NULL, NULL);
            }
            else {
                u = create_unit(r, monsters, nrand(30, 20) + 1, get_race(RC_DRAGON), 0, NULL, NULL);
            }
            fset(u, UFL_ISNEW | UFL_MOVED);
            equip_unit(u, get_equipment("monster_dragon"));

            log_debug("spawning %d %s in %s.\n", u->number,
                LOC(default_locale,
                rc_name_s(u_race(u), (u->number == 1) ? NAME_SINGULAR : NAME_PLURAL)), regionname(r, NULL));

            name_unit(u);

            /* add message to the region */
            ADDMSG(&r->msgs,
                msg_message("sighting", "region race number", r, u_race(u), u->number));
        }
    }
}
Exemplo n.º 25
0
void create_icebergs(void)
{
  region *r;

  for (r = regions; r; r = r->next) {
    if (r->terrain == newterrain(T_ICEBERG_SLEEP) && chance(0.05)) {
      bool has_ocean_neighbour = false;
      direction_t dir;
      region *rc;
      unit *u;

      freset(r, RF_SELECT);
      for (dir = 0; dir < MAXDIRECTIONS; dir++) {
        rc = rconnect(r, dir);
        if (rc && fval(rc->terrain, SEA_REGION)) {
          has_ocean_neighbour = true;
          break;
        }
      }
      if (!has_ocean_neighbour)
        continue;

      rsetterrain(r, T_ICEBERG);

      fset(r, RF_SELECT);
      move_iceberg(r);

      for (u = r->units; u; u = u->next) {
        freset(u->faction, FFL_SELECT);
      }
      for (u = r->units; u; u = u->next) {
        if (!fval(u->faction, FFL_SELECT)) {
          fset(u->faction, FFL_SELECT);
          ADDMSG(&u->faction->msgs, msg_message("iceberg_create", "region", r));
        }
      }
    }
  }
}
Exemplo n.º 26
0
faction *get_or_create_monsters(void)
{
    faction *f = findfaction(MONSTER_ID);
    if (!f) {
        const race *rc = rc_get_or_create("dragon");
        const char *email = config_get("monster.email");
        f = addfaction(email, NULL, rc, default_locale);
        renumber_faction(f, MONSTER_ID);
        faction_setname(f, "Monster");
        fset(f, FFL_NPC | FFL_NOIDLEOUT);
    }
    return f;
}
Exemplo n.º 27
0
static void setup_pirate(unit **pirate, int p_r_flags, int p_rc_flags, const char *p_shiptype,
    unit **victim, int v_r_flags, const char *v_shiptype) {
    terrain_type *vterrain;
    ship_type *st_boat = NULL;
    race *rc;
    faction *f;

    setup_piracy();
    vterrain = get_or_create_terrain("terrain1");
    fset(vterrain, v_r_flags);
    *victim = test_create_unit(test_create_faction(NULL), test_create_region(1, 0, vterrain));
    assert(*victim);

    if (v_shiptype) {
        st_boat = st_get_or_create(v_shiptype);
        u_set_ship(*victim, test_create_ship((*victim)->region, st_boat));
        free(st_boat->coasts);
        st_boat->coasts = (struct terrain_type **)calloc(2, sizeof(struct terrain_type *));
        st_boat->coasts[0] = vterrain;
        st_boat->coasts[1] = 0;
    }

    *pirate = create_unit(test_create_region(0, 0, get_or_create_terrain("terrain2")), f = test_create_faction(NULL), 1, rc = rc_get_or_create("pirate"), 0, 0, 0);
    fset(rc, p_rc_flags);
    assert(f && *pirate);

    if (p_shiptype) {
        st_boat = st_get_or_create(p_shiptype);
        u_set_ship(*pirate, test_create_ship((*pirate)->region, st_boat));
        free(st_boat->coasts);
        st_boat->coasts = (struct terrain_type **)calloc(2, sizeof(struct terrain_type *));
        st_boat->coasts[0] = vterrain;
        st_boat->coasts[1] = 0;
    }

    f->locale = get_or_create_locale("de");
    (*pirate)->thisorder = create_order(K_PIRACY, f->locale, "%s", itoa36((*victim)->faction->no));
}
Exemplo n.º 28
0
static int unguard_handle(trigger * t, void *data)
{
    building *b = (building *)t->data.v;

    if (b) {
        fset(b, BLD_UNGUARDED);
    }
    else {
        log_error("could not perform unguard::handle()\n");
        return -1;
    }
    unused_arg(data);
    return 0;
}
Exemplo n.º 29
0
static void test_buildingtype_exists(CuTest * tc)
{
    region *r;
    building *b;
    building_type *btype, *btype2;

    test_setup();

    btype2 = test_create_buildingtype("castle");
    assert(btype2);
    btype = test_create_buildingtype("lighhouse");
    btype->maxsize = 10;

    r = test_create_plain(0, 0);
    b = test_create_building(r, btype);
    CuAssertPtrNotNull(tc, b);
    b->size = 10;

    CuAssertTrue(tc, !buildingtype_exists(r, NULL, false));
    CuAssertTrue(tc, !buildingtype_exists(r, btype2, false));

    CuAssertTrue(tc, buildingtype_exists(r, btype, false));
    b->size = 9;
    fset(b, BLD_MAINTAINED);
    CuAssertTrue(tc, !buildingtype_exists(r, btype, false));
    btype->maxsize = 0;
    freset(b, BLD_MAINTAINED);
    CuAssertTrue(tc, buildingtype_exists(r, btype, false));
    btype->maxsize = 10;
    b->size = 10;

    fset(b, BLD_MAINTAINED);
    CuAssertTrue(tc, buildingtype_exists(r, btype, true));
    freset(b, BLD_MAINTAINED);
    CuAssertTrue(tc, !buildingtype_exists(r, btype, true));
    test_teardown();
}
Exemplo n.º 30
0
static void
volcano_destruction(region * volcano, region * r, region * rn,
  const char *damage)
{
  attrib *a;
  unit **up;
  int percent = 25, time = 6 + rng_int() % 12;

  rsettrees(r, 2, 0);
  rsettrees(r, 1, 0);
  rsettrees(r, 0, 0);

  a = a_find(r->attribs, &at_reduceproduction);
  if (!a) {
    a = make_reduceproduction(percent, time);
  } else {
    /* Produktion vierteln ... */
    a->data.sa[0] = (short)percent;
    /* Für 6-17 Runden */
    a->data.sa[1] = (short)(a->data.sa[1] + time);
  }

  /* Personen bekommen 4W10 Punkte Schaden. */

  for (up = &r->units; *up;) {
    unit *u = *up;
    if (u->number) {
      int dead = damage_unit(u, damage, true, false);
      if (dead) {
        ADDMSG(&u->faction->msgs, msg_message("volcano_dead",
            "unit region dead", u, volcano, dead));
      }
      if (r == volcano && !fval(u->faction, FFL_SELECT)) {
        fset(u->faction, FFL_SELECT);
        if (rn) {
          ADDMSG(&u->faction->msgs, msg_message("volcanooutbreak",
              "regionv regionn", r, rn));
        } else {
          ADDMSG(&u->faction->msgs, msg_message("volcanooutbreaknn",
              "region", r));
        }
      }
    }
    if (u == *up)
      up = &u->next;
  }

  remove_empty_units_in_region(r);
}