コード例 #1
0
ファイル: bind_region.c プロジェクト: stm2/server
static int tolua_region_get_next(lua_State * L)
{
    region *self = (region *)tolua_tousertype(L, 1, 0);
    direction_t dir = (direction_t)tolua_tonumber(L, 2, 0);

    if (dir >= 0 && dir < MAXDIRECTIONS) {
        tolua_pushusertype(L, (void *)r_connect(self, dir), TOLUA_CAST "region");
        return 1;
    }
    return 0;
}
コード例 #2
0
ファイル: connection.c プロジェクト: hochl/server
void walk_connections(region *r, void(*cb)(connection *, void *), void *data) {
    int key = reg_hashkey(r);
    int d;

    walk_i(r, borders[key], cb, data);
    for (d = 0; d != MAXDIRECTIONS; ++d) {
        region *rn = r_connect(r, d);
        int k = reg_hashkey(rn);
        if (k < key) {
            walk_i(r, borders[k], cb, data);
        }
    }
}
コード例 #3
0
ファイル: tests.c プロジェクト: UweKopf/server
/** creates a small world and some stuff in it.
 * two terrains: 'plain' and 'ocean'
 * one race: 'human'
 * one ship_type: 'boat'
 * one building_type: 'castle'
 * in 0.0 and 1.0 is an island of two plains, around it is ocean.
 */
void test_create_world(void)
{
  terrain_type *t_plain, *t_ocean;
  region *island[2];
  int i;
  const char * names[] = { "horse", "horse_p", "boat", "boat_p", "iron", "iron_p", "stone", "stone_p" };

  make_locale("de");
  init_resources();
  assert(!olditemtype[I_HORSE]);

  olditemtype[I_HORSE] = test_create_itemtype(names+0);
  olditemtype[I_IRON] = test_create_itemtype(names+4);
  olditemtype[I_STONE] = test_create_itemtype(names+6);

  t_plain = test_create_terrain("plain", LAND_REGION | FOREST_REGION | WALK_INTO | CAVALRY_REGION);
  t_plain->size = 1000;
  t_ocean = test_create_terrain("ocean", SEA_REGION | SAIL_INTO | SWIM_INTO);
  t_ocean->size = 0;

  island[0] = test_create_region(0, 0, t_plain);
  island[1] = test_create_region(1, 0, t_plain);
  for (i = 0; i != 2; ++i) {
    int j;
    region *r = island[i];
    for (j = 0; j != MAXDIRECTIONS; ++j) {
      region *rn = r_connect(r, (direction_t)j);
      if (!rn) {
        rn = test_create_region(r->x + delta_x[j], r->y + delta_y[j], t_ocean);
      }
    }
  }

  test_create_race("human");

  test_create_buildingtype("castle");
  test_create_shiptype(names+2);
}