Beispiel #1
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;
}
Beispiel #2
0
static int tolua_region_create(lua_State * L)
{
    int x = (int)tolua_tonumber(L, 1, 0);
    int y = (int)tolua_tonumber(L, 2, 0);
    const char *tname = tolua_tostring(L, 3, 0);
    if (tname) {
        plane *pl = findplane(x, y);
        const terrain_type *terrain = get_terrain(tname);
        region *r, *result;
        if (!terrain) {
            return 0;
        }

        assert(!pnormalize(&x, &y, pl));
        r = result = findregion(x, y);

        if (r != NULL && r->units != NULL) {
            /* TODO: error message */
            result = NULL;
        }
        else if (r == NULL) {
            result = new_region(x, y, pl, 0);
        }
        if (result) {
            terraform_region(result, terrain);
            if (result->land) {
                fix_demand(result);
            }
        }

        tolua_pushusertype(L, result, TOLUA_CAST "region");
        return 1;
    }
    return 0;
}
Beispiel #3
0
static void frame_regions(int age, const terrain_type * terrain)
{
    plane *hplane = get_homeplane();
    region *r = regions;
    for (r = regions; r; r = r->next) {
        plane *pl = rplane(r);
        direction_t d;
        if (r->age < age)
            continue;
        if (pl != hplane)
            continue;                 /* only do this on the main world */
        if (r->terrain == terrain)
            continue;

        for (d = 0; d != MAXDIRECTIONS; ++d) {
            region *rn = rconnect(r, d);
            if (rn == NULL) {
                int x = r->x + delta_x[d];
                int y = r->y + delta_y[d];
                pnormalize(&x, &y, pl);
                rn = new_region(x, y, pl, 0);
                terraform_region(rn, terrain);
                rn->age = r->age;
            }
        }
    }
}
Beispiel #4
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;
}
Beispiel #5
0
static void block_create(int x1, int y1, char terrain)
{
  int x, y;
  for (x = 0; x != BLOCKSIZE; ++x) {
    for (y = 0; y != BLOCKSIZE; ++y) {
      region *r = new_region(x1 + x, y1 + y, 0);
      terraform(r, terrain);
    }
  }
}
Beispiel #6
0
struct region *test_create_region(int x, int y, const terrain_type *terrain)
{
  region *r = new_region(x, y, NULL, 0);
  terraform_region(r, terrain);
  rsettrees(r, 0, 0);
  rsettrees(r, 1, 0);
  rsettrees(r, 2, 0);
  rsethorses(r, 0);
  rsetpeasants(r, terrain->size);
  return r;
}
Beispiel #7
0
Region Region::take_tiles(rng::RNG &rng, coord::tile start_point, unsigned int number, double p) {

	tileset_t new_set = this->subset(rng, start_point, number, p);

	// erase from current set
	for (auto &t: new_set) {
		this->tiles.erase(t);
	}

	Region new_region(start_point, new_set);
	new_region.terrain_id = this->terrain_id;
	return new_region;
}
Beispiel #8
0
static void oceans_around(region * r, region * rn[])
{
    int n;
    for (n = 0; n != MAXDIRECTIONS; ++n) {
        region *rx = rn[n];
        if (rx == NULL) {
            plane *pl = rplane(r);
            int x = r->x + delta_x[n];
            int y = r->y + delta_y[n];
            pnormalize(&x, &y, pl);
            rx = new_region(x, y, pl, 0);
            terraform_region(rx, newterrain(T_OCEAN));
            rn[n] = rx;
        }
    }
}
Beispiel #9
0
int json_import(struct stream * out) {
    cJSON *json, *child;
    char buffer[1024], *data = 0;
    size_t sz = 0;
    assert(out && out->api);
    while (!out->api->readln(out->handle, buffer, sizeof(buffer))) {
        size_t len = strlen(buffer);
        data = (char *)realloc(data, sz + len + 1);
        memcpy(data + sz, buffer, len);
        sz += len;
        data[sz] = 0;
    }
    json = cJSON_Parse(data);
    child = cJSON_GetObjectItem(json, "regions");
    if (child && child->type == cJSON_Object) {
        cJSON *j;
        for (j = child->child; j; j = j->next) {
            cJSON *attr;
            unsigned int id = 0;
            int x = 0, y = 0;
            region * r;

            id = (unsigned int)atol(j->string);
            if ((attr = cJSON_GetObjectItem(j, "x")) != 0 && attr->type == cJSON_Number) x = attr->valueint;
            if ((attr = cJSON_GetObjectItem(j, "y")) != 0 && attr->type == cJSON_Number) y = attr->valueint;
            r = new_region(x, y, 0, id);
            if ((attr = cJSON_GetObjectItem(j, "type")) != 0 && attr->type == cJSON_String) {
                const terrain_type *terrain = get_terrain(attr->valuestring);
                terraform_region(r, terrain);
            }
            if ((attr = cJSON_GetObjectItem(j, "name")) != 0 && attr->type == cJSON_String) {
                region_setname(r, attr->valuestring);
            }
        }
    }
    cJSON_Delete(json);
    return 0;
}
Beispiel #10
0
static void test_fix_demand(CuTest *tc) {
    region *r;
    terrain_type *tplain;
    item_type *ltype;

    test_cleanup();
    ltype = test_create_itemtype("balm");
    ltype->rtype->flags |= (RTF_ITEM | RTF_POOLED);
    new_luxurytype(ltype, 0);
    ltype = test_create_itemtype("oint");
    ltype->rtype->flags |= (RTF_ITEM | RTF_POOLED);
    new_luxurytype(ltype, 0);
    tplain = test_create_terrain("plain", LAND_REGION);
    r = new_region(0, 0, NULL, 0);
    CuAssertPtrNotNull(tc, r);
    terraform_region(r, tplain);
    CuAssertPtrNotNull(tc, r->land);
    CuAssertIntEquals(tc, 0, fix_demand(r));
    CuAssertPtrNotNull(tc, r->land->demands);
    CuAssertPtrNotNull(tc, r->land->demands->next);
    CuAssertPtrNotNull(tc, r_luxury(r));
    test_cleanup();
}
Beispiel #11
0
int
random_neighbours(region * r, region_list ** rlist,
const terrain_type * (*terraformer) (direction_t))
{
    int nsize = 0;
    direction_t dir;
    for (dir = 0; dir != MAXDIRECTIONS; ++dir) {
        region *rn = rconnect(r, dir);
        if (rn == NULL) {
            const terrain_type *terrain = terraformer(dir);
            plane *pl = rplane(r);
            int x = r->x + delta_x[dir];
            int y = r->y + delta_y[dir];
            pnormalize(&x, &y, pl);
            rn = new_region(x, y, pl, 0);
            terraform_region(rn, terrain);
            regionqueue_push(rlist, rn);
            if (rn->land) {
                ++nsize;
            }
        }
    }
    return nsize;
}
Beispiel #12
0
static void build_regions( Segmenter *s, const unsigned char *source )
{
    //Span *new_span;
	int x, y, i;
    RegionReference **current_row = &s->regions_under_construction[0];
    RegionReference **previous_row = &s->regions_under_construction[s->width];

    s->region_ref_count = 0;
    s->region_count = 0;
    s->freed_regions_head = 0;

    // top line

    x = 0;
    y = 0;
    current_row[0] = new_region( s, x, y, source[0] );
    current_row[0]->region->flags |= ADJACENT_TO_ROOT_REGION_FLAG;
    for( x=1, y=0, i=1 ; x < s->width; ++x, ++i ){

        if( source[i] == source[i-1] ){
            current_row[x] = current_row[x-1];
        }else{
//			current_row[x-1]->region->last_span->end=i-1;
//			current_row[x-1]->region->area += i-current_row[x-1]->region->last_span->start;
            current_row[x] = new_region( s, x, y, source[i] );
            current_row[x]->region->flags |= ADJACENT_TO_ROOT_REGION_FLAG;
            make_adjacent( s, current_row[x]->region, current_row[x-1]->region );
        }
    }

    // process lines

    for( y=1; y < s->height; ++y ){

        // swap previous and current rows
        RegionReference **temp = previous_row;
        previous_row = current_row;
        current_row = temp;

        i = y * s->width;
        x = 0;

        // left edge

        RESOLVE_REGIONREF_REDIRECTS( previous_row[x], previous_row[x] );
        if( source[i] == previous_row[x]->region->colour ){
            current_row[x] = previous_row[x];
/*
			new_span = LOOKUP_SEGMENTER_SPAN( s,  i );
			new_span->start = i;
			new_span->end = i;
			new_span->next = NULL;
			current_row[x]->region->last_span->next = new_span;
			current_row[x]->region->last_span = new_span;
*/
		}else{ // source[i] != previous_row[x]->colour

            current_row[x] = new_region( s, x, y, source[i] );
            current_row[x]->region->flags |= ADJACENT_TO_ROOT_REGION_FLAG;
            make_adjacent( s, current_row[x]->region, previous_row[x]->region );
        }

        ++i;
        x=1;

        // center span

        for( ; x < s->width; ++x, ++i ){
            //RESOLVE_REGIONREF_REDIRECTS( current_row[x-1], current_row[x-1] );   // this isn't needed because the the west cell's redirect is always up to date
            RESOLVE_REGIONREF_REDIRECTS( previous_row[x], previous_row[x] );

            if( source[i] == source[i-1] ){

                current_row[x] = current_row[x-1];

                if( current_row[x] != previous_row[x]
                        && source[i] == previous_row[x]->region->colour ){

                    // merge the current region into the previous one
                    // this should be more efficient than merging the previous
                    // into the current because it keeps long-lived regions
                    // alive and only frees newer (less connected?) ones
/*
					previous_row[x]->region->last_span->next = current_row[x]->region->first_span;
					previous_row[x]->region->last_span = current_row[x]->region->last_span;
					previous_row[x]->region->area += current_row[x]->region->area;
*/
                    merge_regions( s, previous_row[x]->region, current_row[x]->region );
                    current_row[x]->region->flags = FREE_REGION_FLAG;
                    current_row[x]->region->next = s->freed_regions_head;
                    s->freed_regions_head = current_row[x]->region;
                    current_row[x]->region = 0;
                    current_row[x]->redirect = previous_row[x];
                    current_row[x] = previous_row[x];
                }


            }else{ // source_image_[i] != source_image_[i-1]
/*
				current_row[x-1]->region->last_span->end=i-1; // set the span end, it is more efficient here
				current_row[x-1]->region->area+=i-current_row[x-1]->region->last_span->start;
				
				// mark single pixels fragmented
				if (current_row[x-1]->region->area<=REGION_GATE_AREA) {
					if (((y+1)==s->height) || (source[i-1]!=source[i-1+s->width]))
						make_fragmented(current_row[x-1]->region);
				}
*/
                if( current_row[x-1]->region->right < x - 1 )
                    current_row[x-1]->region->right = (short)( x - 1 );

                if( source[i] == previous_row[x]->region->colour ){
                    current_row[x] = previous_row[x];
                    current_row[x]->region->bottom = (short)y;
/*
					new_span = LOOKUP_SEGMENTER_SPAN( s,  i );
					new_span->start = i;
					new_span->end = i;
					new_span->next = NULL;
					current_row[x]->region->last_span->next = new_span;
					current_row[x]->region->last_span = new_span;
*/
                }else{
                    current_row[x] = new_region( s, x, y, source[i] );
                    make_adjacent( s, current_row[x]->region, previous_row[x]->region );
                    if( current_row[x-1]->region != previous_row[x]->region )
                        make_adjacent( s, current_row[x]->region, current_row[x-1]->region );
                }
            }
        }

        // right edge
        current_row[s->width-1]->region->flags |= ADJACENT_TO_ROOT_REGION_FLAG;
//		current_row[s->width-1]->region->last_span->end=i;
//		current_row[x-1]->region->area+=i-current_row[x-1]->region->last_span->start+2;
    }

    // make regions of bottom row adjacent or merge with root

    for( x = 0; x < s->width; ++x ){
        RESOLVE_REGIONREF_REDIRECTS( current_row[x], current_row[x] );
        current_row[x]->region->flags |= ADJACENT_TO_ROOT_REGION_FLAG;
    }
}
Beispiel #13
0
/** create new island with up to nsize players
 * returns the number of players placed on the new island.
 */
int autoseed(newfaction ** players, int nsize, int max_agediff)
{
    region *r = NULL;
    region_list *rlist = NULL;
    int rsize = 0, tsize = 0;
    int isize = REGIONS_PER_FACTION;      /* target size for the island */
    int psize = 0;                /* players on this island */
    const terrain_type *volcano_terrain = get_terrain("volcano");
    static int nterrains = -1;
    static const terrain_type **terrainarr = 0;
    static int *distribution;

    assert(players);
    if (nterrains < 0) {
        int n = 0;
        const terrain_type *terrain = terrains();
        for (nterrains = 0; terrain; terrain = terrain->next) {
            if (terrain->distribution) {
                ++nterrains;
            }
        }
        terrainarr = malloc(sizeof(terrain_type *) * nterrains);
        distribution = malloc(sizeof(int) * nterrains);
        for (terrain = terrains(); terrain; terrain = terrain->next) {
            if (terrain->distribution) {
                terrainarr[n] = terrain;
                distribution[n++] = terrain->distribution;
            }
        }
    }
    frame_regions(16, newterrain(T_FIREWALL));

    if (listlen(*players) < MINFACTIONS)
        return 0;

    if (max_agediff > 0) {
        region *rmin = NULL;
        plane *hplane = get_homeplane();
        /* find a spot that's adjacent to the previous island, but virgin.
         * like the last land virgin ocean region adjacent to land.
         */
        for (r = regions; r; r = r->next) {
            struct plane *pl = rplane(r);
            if (r->age <= max_agediff && r->terrain == newterrain(T_OCEAN)
                && pl == hplane && virgin_region(r)) {
                direction_t d;
                for (d = 0; d != MAXDIRECTIONS; ++d) {
                    region *rn = rconnect(r, d);
                    if (rn && rn->land && rn->age <= max_agediff && virgin_region(rn)) {
                        /* only expand islands that aren't single-islands and not too big already */
                        int size, inhabitants, maxage;
                        get_island_info(rn, &size, &inhabitants, &maxage);
                        if (maxage <= max_agediff && size >= 2 && size < MAXISLANDSIZE) {
                            rmin = rn;
                            break;
                        }
                    }
                }
            }
        }
        if (rmin != NULL) {
            faction *f;
            quicklist *ql, *rlist = get_island(rmin);
            int qi;

            for (ql = rlist, qi = 0; ql; ql_advance(&ql, &qi, 1)) {
                region *r = (region *)ql_get(ql, qi);
                unit *u;
                for (u = r->units; u; u = u->next) {
                    f = u->faction;
                    if (!fval(f, FFL_MARK)) {
                        ++psize;
                        fset(f, FFL_MARK);
                    }
                }
            }
            ql_free(rlist);
            if (psize > 0) {
                for (f = factions; f; f = f->next) {
                    freset(f, FFL_MARK);
                }
            }
            if (psize < PLAYERS_PER_ISLAND) {
                r = rmin;
            }
        }
    }
    if (r == NULL) {
        region *rmin = NULL;
        direction_t dmin = MAXDIRECTIONS;
        plane *hplane = get_homeplane();
        /* find an empty spot.
         * rmin = the youngest ocean region that has a missing neighbour
         * dmin = direction in which it's empty
         */
        for (r = regions; r; r = r->next) {
            struct plane *pl = rplane(r);
            if (r->terrain == newterrain(T_OCEAN) && pl == hplane && (rmin == NULL
                || r->age <= max_agediff)) {
                direction_t d;
                for (d = 0; d != MAXDIRECTIONS; ++d) {
                    region *rn = rconnect(r, d);
                    if (rn == NULL)
                        break;
                }
                if (d != MAXDIRECTIONS) {
                    rmin = r;
                    dmin = d;
                }
            }
        }

        /* create a new region where we found the empty spot, and make it the first
         * in our island. island regions are kept in rlist, so only new regions can
         * get populated, and old regions are not overwritten */
        if (rmin != NULL) {
            plane *pl = rplane(rmin);
            int x = rmin->x + delta_x[dmin];
            int y = rmin->y + delta_y[dmin];
            pnormalize(&x, &y, pl);
            assert(virgin_region(rconnect(rmin, dmin)));
            r = new_region(x, y, pl, 0);
            terraform_region(r, newterrain(T_OCEAN));
        }
    }
    if (r != NULL) {
        add_regionlist(&rlist, r);
        fset(r, RF_MARK);
        rsize = 1;
    }

    while (rsize && (nsize || isize >= REGIONS_PER_FACTION)) {
        int i = rng_int() % rsize;
        region_list **rnext = &rlist;
        region_list *rfind;
        direction_t d;
        while (i--)
            rnext = &(*rnext)->next;
        rfind = *rnext;
        r = rfind->data;
        freset(r, RF_MARK);
        *rnext = rfind->next;
        free(rfind);
        --rsize;
        for (d = 0; d != MAXDIRECTIONS; ++d) {
            region *rn = rconnect(r, d);
            if (rn && fval(rn, RF_MARK))
                continue;
            if (rn == NULL) {
                plane *pl = rplane(r);
                int x = r->x + delta_x[d];
                int y = r->y + delta_y[d];
                pnormalize(&x, &y, pl);
                rn = new_region(x, y, pl, 0);
                terraform_region(rn, newterrain(T_OCEAN));
            }
            if (virgin_region(rn)) {
                add_regionlist(&rlist, rn);
                fset(rn, RF_MARK);
                ++rsize;
            }
        }
        if (volcano_terrain != NULL && (rng_int() % VOLCANO_CHANCE == 0)) {
            terraform_region(r, volcano_terrain);
        }
        else if (nsize && (rng_int() % isize == 0 || rsize == 0)) {
            newfaction **nfp, *nextf = *players;
            faction *f;
            unit *u;

            isize += REGIONS_PER_FACTION;
            terraform_region(r, preferred_terrain(nextf->race));
            prepare_starting_region(r);
            ++tsize;
            assert(r->land && r->units == 0);
            u = addplayer(r, addfaction(nextf->email, nextf->password, nextf->race,
                nextf->lang, nextf->subscription));
            f = u->faction;
            fset(f, FFL_ISNEW);
            f->alliance = nextf->allies;

            /* remove duplicate email addresses */
            nfp = &nextf->next;
            while (*nfp) {
                newfaction *nf = *nfp;
                if (strcmp(nextf->email, nf->email) == 0) {
                    *nfp = nf->next;
                    free_newfaction(nf);
                }
                else
                    nfp = &nf->next;
            }
            *players = nextf->next;
            free_newfaction(nextf);

            ++psize;
            --nsize;
            --isize;
            if (psize >= PLAYERS_PER_ISLAND)
                break;
        }
        else {
            terraform_region(r, random_terrain(terrainarr, distribution, nterrains));
            --isize;
        }
    }

    if (nsize != 0) {
        log_error(
            ("Could not place all factions on the same island as requested\n"));
    }

    if (rlist) {
#define MINOCEANDIST 3
#define MAXOCEANDIST 6
#define MAXFILLDIST 10
#define SPECIALCHANCE 80
        region_list **rbegin = &rlist;
        int special = 1;
        int oceandist = MINOCEANDIST + (rng_int() % (MAXOCEANDIST - MINOCEANDIST));
        while (oceandist--) {
            region_list **rend = rbegin;
            while (*rend)
                rend = &(*rend)->next;
            while (rbegin != rend) {
                direction_t d;
                region *r = (*rbegin)->data;
                rbegin = &(*rbegin)->next;
                for (d = 0; d != MAXDIRECTIONS; ++d) {
                    region *rn = rconnect(r, d);
                    if (rn == NULL) {
                        const struct terrain_type *terrain = newterrain(T_OCEAN);
                        plane *pl = rplane(r);
                        int x = r->x + delta_x[d];
                        int y = r->y + delta_y[d];
                        pnormalize(&x, &y, pl);
                        rn = new_region(x, y, pl, 0);
                        if (rng_int() % SPECIALCHANCE < special) {
                            terrain = random_terrain(terrainarr, distribution, nterrains);
                            special = SPECIALCHANCE / 3;      /* 33% chance auf noch eines */
                        }
                        else {
                            special = 1;
                        }
                        terraform_region(rn, terrain);
                        /* the new region has an extra 20% chance to have mallorn */
                        if (rng_int() % 100 < 20)
                            fset(r, RF_MALLORN);
                        add_regionlist(rend, rn);
                    }
                }
            }

        }
        while (*rbegin) {
            region *r = (*rbegin)->data;
            plane *pl = rplane(r);
            direction_t d;
            rbegin = &(*rbegin)->next;
            for (d = 0; d != MAXDIRECTIONS; ++d)
                if (rconnect(r, d) == NULL) {
                    int i;
                    for (i = 1; i != MAXFILLDIST; ++i) {
                        int x = r->x + delta_x[d] * i;
                        int y = r->y + delta_y[d] * i;
                        pnormalize(&x, &y, pl);
                        if (findregion(x, y)) {
                            break;
                        }
                    }
                    if (i != MAXFILLDIST) {
                        while (--i) {
                            region *rn;
                            int x = r->x + delta_x[d] * i;
                            int y = r->y + delta_y[d] * i;
                            pnormalize(&x, &y, pl);
                            rn = new_region(x, y, pl, 0);
                            terraform_region(rn, newterrain(T_OCEAN));
                        }
                    }
                }
        }
        while (rlist) {
            region_list *self = rlist;
            rlist = rlist->next;
            freset(self->data, RF_MARK);
            free(self);
        }
    }
    return tsize;
}
int main(void)
{
	const struct dt_property *names, *ranges;
	struct mem_region *r;
	unsigned int i, l, c;
	uint64_t *rangep;
	const char *name;
	void *buf;

	/* Use malloc for the heap, so valgrind can find issues. */
	skiboot_heap.start = (long)real_malloc(TEST_HEAP_SIZE);
	skiboot_heap.len = TEST_HEAP_SIZE;
	skiboot_os_reserve.len = skiboot_heap.start;

	dt_root = dt_new_root("");
	dt_add_property_cells(dt_root, "#address-cells", 2);
	dt_add_property_cells(dt_root, "#size-cells", 2);

	buf = real_malloc(1024*1024);
	add_mem_node((unsigned long)buf, 1024*1024);

	/* Now convert. */
	mem_region_init();

	/* create our reservations */
	for (i = 0; i < ARRAY_SIZE(test_regions); i++)
		mem_reserve(test_regions[i].name, test_regions[i].addr, 0x1000);

	/* release unused */
	mem_region_release_unused();

	/* and create reservations */
	mem_region_add_dt_reserved();

	/* ensure we can't create further reservations */
	r = new_region("test.4", 0x5000, 0x1000, NULL, REGION_RESERVED);
	assert(!add_region(r));

	/* check dt properties */
	names = dt_find_property(dt_root, "reserved-names");
	ranges = dt_find_property(dt_root, "reserved-ranges");

	assert(names && ranges);

	/* walk through names & ranges properies, ensuring that the test
	 * regions are all present */
	for (name = names->prop, rangep = (uint64_t *)ranges->prop, c = 0;
			name < names->prop + names->len;
			name += l, rangep += 2) {
		uint64_t addr;

		addr = dt_get_number(rangep, 2);
		l = strlen(name) + 1;

		for (i = 0; i < ARRAY_SIZE(test_regions); i++) {
			if (strcmp(test_regions[i].name, name))
				continue;
			assert(test_regions[i].addr == addr);
			assert(!test_regions[i].found);
			test_regions[i].found = true;
			c++;
		}
	}

	assert(c == ARRAY_SIZE(test_regions));

	dt_free(dt_root);
	real_free(buf);
	real_free((void *)(long)skiboot_heap.start);
	return 0;
}
Beispiel #15
0
tracking_window::tracking_window(QWidget *parent,ODFModel* new_handle,bool handle_release_) :
        QMainWindow(parent),handle(new_handle),handle_release(handle_release_),
        ui(new Ui::tracking_window),scene(*this,new_handle),slice(new_handle)

{

    ODFModel* odf_model = (ODFModel*)handle;
    FibData& fib_data = odf_model->fib_data;

    odf_size = fib_data.fib.odf_table.size();
    odf_face_size = fib_data.fib.odf_faces.size();
    has_odfs = fib_data.fib.has_odfs() ? 1:0;
    // check whether first index is "fa0"
    is_dti = (fib_data.view_item[0].name[0] == 'f');

    ui->setupUi(this);
    {
        setGeometry(10,10,800,600);

        ui->regionDockWidget->setMinimumWidth(0);
        ui->dockWidget->setMinimumWidth(0);
        ui->dockWidget_3->setMinimumWidth(0);
        ui->renderingLayout->addWidget(renderWidget = new RenderingTableWidget(*this,ui->renderingWidgetHolder,has_odfs));
        ui->centralLayout->insertWidget(1,glWidget = new GLWidget(renderWidget->getData("anti_aliasing").toInt(),
                                                                  *this,renderWidget,ui->centralwidget));
        ui->verticalLayout_3->addWidget(regionWidget = new RegionTableWidget(*this,ui->regionDockWidget));
        ui->tractverticalLayout->addWidget(tractWidget = new TractTableWidget(*this,ui->TractWidgetHolder));
        ui->graphicsView->setScene(&scene);
        ui->graphicsView->setCursor(Qt::CrossCursor);
        scene.statusbar = ui->statusbar;
        color_bar.reset(new color_bar_dialog(this));
    }

    // setup fa threshold
    {
        for(int index = 0;index < fib_data.fib.index_name.size();++index)
            ui->tracking_index->addItem((fib_data.fib.index_name[index]+" threshold").c_str());
        ui->tracking_index->setCurrentIndex(0);
        ui->step_size->setValue(fib_data.vs[0]/2.0);
    }

    // setup sliders
    {
        slice_no_update = true;
        ui->SagSlider->setRange(0,slice.geometry[0]-1);
        ui->CorSlider->setRange(0,slice.geometry[1]-1);
        ui->AxiSlider->setRange(0,slice.geometry[2]-1);
        ui->SagSlider->setValue(slice.slice_pos[0]);
        ui->CorSlider->setValue(slice.slice_pos[1]);
        ui->AxiSlider->setValue(slice.slice_pos[2]);

        ui->glSagBox->setRange(0,slice.geometry[0]-1);
        ui->glCorBox->setRange(0,slice.geometry[1]-1);
        ui->glAxiBox->setRange(0,slice.geometry[2]-1);
        ui->glSagBox->setValue(slice.slice_pos[0]);
        ui->glCorBox->setValue(slice.slice_pos[1]);
        ui->glAxiBox->setValue(slice.slice_pos[2]);
        slice_no_update = false;
        on_SliceModality_currentIndexChanged(0);

        for (unsigned int index = 0;index < fib_data.view_item.size(); ++index)
        {
            ui->sliceViewBox->addItem(fib_data.view_item[index].name.c_str());
            if(fib_data.view_item[index].is_overlay)
                ui->overlay->addItem(fib_data.view_item[index].name.c_str());
        }
        ui->sliceViewBox->setCurrentIndex(0);
        ui->overlay->setCurrentIndex(0);
        if(ui->overlay->count() == 1)
           ui->overlay->hide();
    }

    is_qsdr = !handle->fib_data.trans_to_mni.empty();

    // setup atlas
    if(!fa_template_imp.I.empty() && fib_data.vs[0] > 0.5 && !is_qsdr)
    {
        mi3_arg.scaling[0] = slice.voxel_size[0] / std::fabs(fa_template_imp.tran[0]);
        mi3_arg.scaling[1] = slice.voxel_size[1] / std::fabs(fa_template_imp.tran[5]);
        mi3_arg.scaling[2] = slice.voxel_size[2] / std::fabs(fa_template_imp.tran[10]);
        image::reg::align_center(slice.source_images,fa_template_imp.I,mi3_arg);
        mi3.reset(new manual_alignment(this,slice.source_images,fa_template_imp.I,mi3_arg));
        is_qsdr = false;
    }
    else
        ui->actionManual_Registration->setEnabled(false);
    ui->actionConnectometry->setEnabled(handle->fib_data.fib.has_odfs() && is_qsdr);
    for(int index = 0;index < atlas_list.size();++index)
        ui->atlasListBox->addItem(atlas_list[index].name.c_str());


    {
        if(is_dti)
            ui->actionQuantitative_anisotropy_QA->setText("Save FA...");
        for (int index = fib_data.other_mapping_index; index < fib_data.view_item.size(); ++index)
            {
                std::string& name = fib_data.view_item[index].name;
                QAction* Item = new QAction(this);
                Item->setText(QString("Save %1...").arg(name.c_str()));
                Item->setData(QString(name.c_str()));
                Item->setVisible(true);
                connect(Item, SIGNAL(triggered()),tractWidget, SLOT(save_tracts_data_as()));
                ui->menuSave->addAction(Item);
            }
    }

    // opengl
    {
        connect(renderWidget->treemodel,SIGNAL(dataChanged(QModelIndex,QModelIndex)),
                glWidget,SLOT(updateGL()));
        connect(ui->tbDefaultParam,SIGNAL(clicked()),renderWidget,SLOT(setDefault()));
        connect(ui->tbDefaultParam,SIGNAL(clicked()),glWidget,SLOT(updateGL()));

        connect(ui->glSagSlider,SIGNAL(valueChanged(int)),this,SLOT(glSliderValueChanged()));
        connect(ui->glCorSlider,SIGNAL(valueChanged(int)),this,SLOT(glSliderValueChanged()));
        connect(ui->glAxiSlider,SIGNAL(valueChanged(int)),this,SLOT(glSliderValueChanged()));

        connect(ui->glSagCheck,SIGNAL(stateChanged(int)),glWidget,SLOT(updateGL()));
        connect(ui->glCorCheck,SIGNAL(stateChanged(int)),glWidget,SLOT(updateGL()));
        connect(ui->glAxiCheck,SIGNAL(stateChanged(int)),glWidget,SLOT(updateGL()));

        connect(ui->glSagView,SIGNAL(clicked()),this,SLOT(on_SagView_clicked()));
        connect(ui->glCorView,SIGNAL(clicked()),this,SLOT(on_CorView_clicked()));
        connect(ui->glAxiView,SIGNAL(clicked()),this,SLOT(on_AxiView_clicked()));

        connect(ui->addSlices,SIGNAL(clicked()),this,SLOT(on_actionInsert_T1_T2_triggered()));
        connect(ui->actionAdd_surface,SIGNAL(triggered()),glWidget,SLOT(addSurface()));
        connect(ui->SliceModality,SIGNAL(currentIndexChanged(int)),glWidget,SLOT(updateGL()));
        connect(ui->actionSave_Screen,SIGNAL(triggered()),glWidget,SLOT(catchScreen()));
        connect(ui->actionSave_3D_screen_in_high_resolution,SIGNAL(triggered()),glWidget,SLOT(catchScreen2()));
        connect(ui->actionLoad_Camera,SIGNAL(triggered()),glWidget,SLOT(loadCamera()));
        connect(ui->actionSave_Camera,SIGNAL(triggered()),glWidget,SLOT(saveCamera()));
        connect(ui->actionLoad_mapping,SIGNAL(triggered()),glWidget,SLOT(loadMapping()));
        connect(ui->actionSave_mapping,SIGNAL(triggered()),glWidget,SLOT(saveMapping()));
        connect(ui->actionSave_Rotation_Images,SIGNAL(triggered()),glWidget,SLOT(saveRotationSeries()));
        connect(ui->actionSave_Left_Right_3D_Image,SIGNAL(triggered()),glWidget,SLOT(saveLeftRight3DImage()));
    }
    // scene view
    {
        connect(ui->SagSlider,SIGNAL(valueChanged(int)),this,SLOT(SliderValueChanged()));
        connect(ui->CorSlider,SIGNAL(valueChanged(int)),this,SLOT(SliderValueChanged()));
        connect(ui->AxiSlider,SIGNAL(valueChanged(int)),this,SLOT(SliderValueChanged()));


        connect(&scene,SIGNAL(need_update()),&scene,SLOT(show_slice()));
        connect(&scene,SIGNAL(need_update()),glWidget,SLOT(updateGL()));
        connect(ui->fa_threshold,SIGNAL(valueChanged(double)),&scene,SLOT(show_slice()));
        connect(ui->contrast,SIGNAL(valueChanged(int)),&scene,SLOT(show_slice()));
        connect(ui->offset,SIGNAL(valueChanged(int)),&scene,SLOT(show_slice()));
        connect(ui->show_fiber,SIGNAL(clicked()),&scene,SLOT(show_slice()));
        connect(ui->show_pos,SIGNAL(clicked()),&scene,SLOT(show_slice()));
        connect(ui->show_lr,SIGNAL(clicked()),&scene,SLOT(show_slice()));

        connect(ui->zoom,SIGNAL(valueChanged(double)),&scene,SLOT(show_slice()));
        connect(ui->zoom,SIGNAL(valueChanged(double)),&scene,SLOT(center()));


        connect(ui->actionAxial_View,SIGNAL(triggered()),this,SLOT(on_AxiView_clicked()));
        connect(ui->actionCoronal_View,SIGNAL(triggered()),this,SLOT(on_CorView_clicked()));
        connect(ui->actionSagittal_view,SIGNAL(triggered()),this,SLOT(on_SagView_clicked()));


        connect(ui->actionSave_ROI_Screen,SIGNAL(triggered()),&scene,SLOT(catch_screen()));

        connect(ui->actionSave_Anisotrpy_Map_as,SIGNAL(triggered()),&scene,SLOT(save_slice_as()));


        connect(ui->overlay,SIGNAL(currentIndexChanged(int)),this,SLOT(on_sliceViewBox_currentIndexChanged(int)));

    }

    // regions
    {

        connect(regionWidget,SIGNAL(need_update()),&scene,SLOT(show_slice()));
        connect(regionWidget,SIGNAL(need_update()),glWidget,SLOT(updateGL()));



        connect(ui->whole_brain,SIGNAL(clicked()),regionWidget,SLOT(whole_brain()));

        connect(ui->view_style,SIGNAL(currentIndexChanged(int)),&scene,SLOT(show_slice()));

        //atlas
        connect(ui->addRegionFromAtlas,SIGNAL(clicked()),regionWidget,SLOT(add_atlas()));


        connect(ui->actionNewRegion,SIGNAL(triggered()),regionWidget,SLOT(new_region()));
        connect(ui->actionOpenRegion,SIGNAL(triggered()),regionWidget,SLOT(load_region()));
        connect(ui->actionSaveRegionAs,SIGNAL(triggered()),regionWidget,SLOT(save_region()));
        connect(ui->actionSave_Voxel_Data_As,SIGNAL(triggered()),regionWidget,SLOT(save_region_info()));
        connect(ui->actionDeleteRegion,SIGNAL(triggered()),regionWidget,SLOT(delete_region()));
        connect(ui->actionDeleteRegionAll,SIGNAL(triggered()),regionWidget,SLOT(delete_all_region()));


        // actions
        connect(ui->actionShift_X,SIGNAL(triggered()),regionWidget,SLOT(action_shiftx()));
        connect(ui->actionShift_X_2,SIGNAL(triggered()),regionWidget,SLOT(action_shiftnx()));
        connect(ui->actionShift_Y,SIGNAL(triggered()),regionWidget,SLOT(action_shifty()));
        connect(ui->actionShift_Y_2,SIGNAL(triggered()),regionWidget,SLOT(action_shiftny()));
        connect(ui->actionShift_Z,SIGNAL(triggered()),regionWidget,SLOT(action_shiftz()));
        connect(ui->actionShift_Z_2,SIGNAL(triggered()),regionWidget,SLOT(action_shiftnz()));

        connect(ui->actionFlip_X,SIGNAL(triggered()),regionWidget,SLOT(action_flipx()));
        connect(ui->actionFlip_Y,SIGNAL(triggered()),regionWidget,SLOT(action_flipy()));
        connect(ui->actionFlip_Z,SIGNAL(triggered()),regionWidget,SLOT(action_flipz()));

        connect(ui->actionThreshold,SIGNAL(triggered()),regionWidget,SLOT(action_threshold()));



        connect(ui->actionSmoothing,SIGNAL(triggered()),regionWidget,SLOT(action_smoothing()));
        connect(ui->actionErosion,SIGNAL(triggered()),regionWidget,SLOT(action_erosion()));
        connect(ui->actionDilation,SIGNAL(triggered()),regionWidget,SLOT(action_dilation()));
        connect(ui->actionNegate,SIGNAL(triggered()),regionWidget,SLOT(action_negate()));
        connect(ui->actionDefragment,SIGNAL(triggered()),regionWidget,SLOT(action_defragment()));

        connect(ui->actionCheck_all_regions,SIGNAL(triggered()),regionWidget,SLOT(check_all()));
        connect(ui->actionUnckech_all_regions,SIGNAL(triggered()),regionWidget,SLOT(uncheck_all()));

        connect(ui->actionWhole_brain_seeding,SIGNAL(triggered()),regionWidget,SLOT(whole_brain()));
        connect(ui->actionRegion_statistics,SIGNAL(triggered()),regionWidget,SLOT(show_statistics()));


    }
    // tracts
    {
        connect(ui->perform_tracking,SIGNAL(clicked()),tractWidget,SLOT(start_tracking()));
        connect(ui->stopTracking,SIGNAL(clicked()),tractWidget,SLOT(stop_tracking()));

        connect(tractWidget,SIGNAL(need_update()),glWidget,SLOT(makeTracts()));
        connect(tractWidget,SIGNAL(need_update()),glWidget,SLOT(updateGL()));

        connect(glWidget,SIGNAL(edited()),tractWidget,SLOT(edit_tracts()));
        connect(glWidget,SIGNAL(region_edited()),glWidget,SLOT(updateGL()));
        connect(glWidget,SIGNAL(region_edited()),&scene,SLOT(show_slice()));

        connect(ui->actionOpenTract,SIGNAL(triggered()),tractWidget,SLOT(load_tracts()));
        connect(ui->actionMerge_All,SIGNAL(triggered()),tractWidget,SLOT(merge_all()));
        connect(ui->actionCopyTrack,SIGNAL(triggered()),tractWidget,SLOT(copy_track()));
        connect(ui->actionDeleteTract,SIGNAL(triggered()),tractWidget,SLOT(delete_tract()));
        connect(ui->actionDeleteTractAll,SIGNAL(triggered()),tractWidget,SLOT(delete_all_tract()));

        connect(ui->actionOpen_Colors,SIGNAL(triggered()),tractWidget,SLOT(load_tracts_color()));
        connect(ui->actionSave_Tracts_Colors_As,SIGNAL(triggered()),tractWidget,SLOT(save_tracts_color_as()));

        connect(ui->actionUndo,SIGNAL(triggered()),tractWidget,SLOT(undo_tracts()));
        connect(ui->actionRedo,SIGNAL(triggered()),tractWidget,SLOT(redo_tracts()));
        connect(ui->actionTrim,SIGNAL(triggered()),tractWidget,SLOT(trim_tracts()));

        connect(ui->actionSet_Color,SIGNAL(triggered()),tractWidget,SLOT(set_color()));

        connect(ui->actionK_means,SIGNAL(triggered()),tractWidget,SLOT(clustering_kmeans()));
        connect(ui->actionEM,SIGNAL(triggered()),tractWidget,SLOT(clustering_EM()));
        connect(ui->actionHierarchical,SIGNAL(triggered()),tractWidget,SLOT(clustering_hie()));
        connect(ui->actionOpen_Cluster_Labels,SIGNAL(triggered()),tractWidget,SLOT(open_cluster_label()));

        //setup menu
        connect(ui->actionSaveTractAs,SIGNAL(triggered()),tractWidget,SLOT(save_tracts_as()));
        connect(ui->actionSave_All_Tracts_As,SIGNAL(triggered()),tractWidget,SLOT(save_all_tracts_as()));
        connect(ui->actionQuantitative_anisotropy_QA,SIGNAL(triggered()),tractWidget,SLOT(save_fa_as()));
        connect(ui->actionSave_End_Points_As,SIGNAL(triggered()),tractWidget,SLOT(save_end_point_as()));
        connect(ui->actionStatistics,SIGNAL(triggered()),tractWidget,SLOT(show_tracts_statistics()));

        connect(ui->track_up,SIGNAL(clicked()),tractWidget,SLOT(move_up()));
        connect(ui->track_down,SIGNAL(clicked()),tractWidget,SLOT(move_down()));

    }




    // recall the setting
    {

        QSettings settings;
        if(!default_geo.size())
            default_geo = saveGeometry();
        if(!default_state.size())
            default_state = saveState();
        restoreGeometry(settings.value("geometry").toByteArray());
        restoreState(settings.value("state").toByteArray());
        ui->turning_angle->setValue(settings.value("turning_angle",60).toDouble());
        ui->smoothing->setValue(settings.value("smoothing",0.0).toDouble());
        ui->min_length->setValue(settings.value("min_length",0.0).toDouble());
        ui->max_length->setValue(settings.value("max_length",500).toDouble());
        ui->tracking_method->setCurrentIndex(settings.value("tracking_method",0).toInt());
        ui->seed_plan->setCurrentIndex(settings.value("seed_plan",0).toInt());
        ui->initial_direction->setCurrentIndex(settings.value("initial_direction",0).toInt());
        ui->interpolation->setCurrentIndex(settings.value("interpolation",0).toInt());
        ui->tracking_plan->setCurrentIndex(settings.value("tracking_plan",0).toInt());
        ui->track_count->setValue(settings.value("track_count",2000).toInt());
        ui->thread_count->setCurrentIndex(settings.value("thread_count",0).toInt());

        ui->glSagCheck->setChecked(settings.value("SagSlice",1).toBool());
        ui->glCorCheck->setChecked(settings.value("CorSlice",1).toBool());
        ui->glAxiCheck->setChecked(settings.value("AxiSlice",1).toBool());
        ui->RenderingQualityBox->setCurrentIndex(settings.value("RenderingQuality",1).toInt());

        ui->view_style->setCurrentIndex((settings.value("view_style",0).toInt()));
        ui->RAS->setChecked(settings.value("RAS",0).toBool());
    }

    {
        scene.center();
        slice_no_update = false;
        copy_target = 0;
    }

    on_glAxiView_clicked();
    if(scene.neurology_convention)
        on_glAxiView_clicked();
    qApp->installEventFilter(this);
}
Beispiel #16
0
void create_museum(void)
{
#if 0                           /* TODO: move this to Lua. It should be possible. */
    unsigned int museum_id = hashstring("museum");
    plane *museum = getplanebyid(museum_id);
    region *r;
    building *b;
    const terrain_type *terrain_hall = get_terrain("hall1");
    const terrain_type *terrain_corridor = get_terrain("corridor1");

    assert(terrain_corridor && terrain_hall);

    if (!museum) {
        museum = create_new_plane(museum_id, "Museum", 9500, 9550,
            9500, 9550, PFL_MUSEUM);
    }

    if (findregion(9525, 9525) == NULL) {
        /* Eingangshalle */
        r = new_region(9525, 9525, 0);
        terraform_region(r, terrain_hall);
        r->planep = museum;
        rsetname(r, "Eingangshalle");
        rsethorses(r, 0);
        rsetmoney(r, 0);
        rsetpeasants(r, 0);
        set_string(&r->display,
            "Die Eingangshalle des Großen Museum der 1. Welt ist bereits jetzt ein beeindruckender Anblick. Obwohl das Museum noch nicht eröffnet ist, vermittelt sie bereits einen Flair exotischer Welten. In den Boden ist ein großer Kompass eingelassen, der den Besuchern bei Orientierung helfen soll.");
    }

    r = findregion(9526, 9525);
    if (!r) {
        /* Lounge */
        r = new_region(9526, 9525, 0);
        terraform_region(r, terrain_hall);
        r->planep = museum;
        rsetname(r, "Lounge");
        rsethorses(r, 0);
        rsetmoney(r, 0);
        rsetpeasants(r, 0);
        set_string(&r->display,
            "Die Lounge des großen Museums ist ein Platz, in dem sich die Besucher treffen, um die Eindrücke, die sie gewonnen haben, zu verarbeiten. Gemütliche Sitzgruppen laden zum Verweilen ein.");
    }

    r = findregion(9526, 9525);
    if (!r->buildings) {
        const building_type *bt_generic = bt_find("generic");
        b = new_building(bt_generic, r, NULL);
        set_string(&b->name, "Séparée im dämonischen Stil");
        set_string(&b->display,
            "Diese ganz im dämonischen Stil gehaltene Sitzgruppe ist ganz in dunklen Schwarztönen gehalten. Muster fremdartiger Runen bedecken das merkwürdig geformte Mobiliar, das unangenehm lebendig wirkt.");

        b = new_building(bt_generic, r, NULL);
        set_string(&b->name, "Séparée im elfischen Stil");
        set_string(&b->display,
            "Ganz in Grün- und Brauntönen gehalten wirkt die Sitzgruppe fast lebendig. Bei näherer Betrachtung erschließt sich dem Betrachter, daß sie tatsächlich aus lebenden Pflanzen erstellt ist. So ist der Tisch aus einem eizigen Baum gewachsen, und die Polster bestehen aus weichen Grassoden. Ein wunderschön gemusterter Webteppich mit tausenden naturgetreu eingestickter Blumensarten bedeckt den Boden.");

        b = new_building(bt_generic, r, NULL);
        set_string(&b->name, "Séparée im halblingschen Stil");
        set_string(&b->display,
            "Dieses rustikale Mobiliar ist aus einem einzigen, gewaltigen Baum hergestellt worden. Den Stamm haben fleißige Halblinge der Länge nach gevierteilt und aus den vier langen Viertelstämmen die Sitzbänke geschnitzt, während der verbleibende Stumpf als Tisch dient. Schon von weitem steigen dem Besucher die Gerüche der Köstlichkeiten entgegen, die auf dem Tisch stapeln.");

        b = new_building(bt_generic, r, NULL);
        set_string(&b->name, "Séparée im orkischen Stil");
        set_string(&b->display,
            "Grobgeschreinerte, elfenhautbespannte Stühle und ein Tisch aus Knochen, über deren Herkunft man sich lieber keine Gedanken macht, bilden die Sitzgruppe im orkischen Stil. Überall haben Orks ihre Namen, und anderes wenig zitierenswertes in das Holz und Gebein geritzt.");

        b = new_building(bt_generic, r, NULL);
        set_string(&b->name, "Séparée im Meermenschenstil");
        set_string(&b->display,
            "Ganz in Blau- und Grüntönen gehalten, mit Algen und Muscheln verziert wirken die aus altem Meerholz geschnitzten Stühle immer ein wenig feucht. Seltsammerweise hat der schwere aus alten Planken gezimmerte Tisch einen Mast mit kompletten Segel in der Mitte.");

        b = new_building(bt_generic, r, NULL);
        set_string(&b->name, "Séparée im Katzenstil");
        set_string(&b->display,
            "Die Wände dieses Séparée sind aus dunklem Holz. Was aus der Ferne wie ein chaotisch durchbrochenes Flechtwerk wirkt, entpuppt sich bei näherer Betrachtung als eine bis in winzige Details gestaltete dschungelartige Landschaft, in die eine Vielzahl von kleinen Bildergeschichten eingewoben sind. Wie es scheint hat sich der Künstler Mühe gegeben wirklich jedes Katzenvolk Eresseas zu porträtieren. Das schummrige Innere wird von einem Kamin dominiert, vor dem einige Sessel und weiche Kissen zu einem gemütlichen Nickerchen einladen. Feiner Anduner Sisal bezieht die Lehnen der Sessel und verlockt dazu, seine Krallen hinein zu versenken. Auf einem kleinen Ecktisch steht ein großer Korb mit roten Wollknäulen und grauen und braunen Spielmäusen.");
    } else {
        for (b = r->buildings; b; b = b->next) {
            b->size = b->type->maxsize;
        }
    }

    r = findregion(9524, 9526);
    if (!r) {
        r = new_region(9524, 9526, 0);
        terraform_region(r, terrain_corridor);
        r->planep = museum;
        rsetname(r, "Nördliche Promenade");
        rsethorses(r, 0);
        rsetmoney(r, 0);
        rsetpeasants(r, 0);
        set_string(&r->display,
            "Die Nördliche Promenade führt direkt in den naturgeschichtlichen Teil des Museums.");
    }
    r = findregion(9525, 9524);
    if (!r) {
        r = new_region(9525, 9524, 0);
        terraform_region(r, terrain_corridor);
        r->planep = museum;
        rsetname(r, "Südliche Promenade");
        rsethorses(r, 0);
        rsetmoney(r, 0);
        rsetpeasants(r, 0);
        set_string(&r->display,
            "Die Südliche Promenade führt den Besucher in den kulturgeschichtlichen Teil des Museums.");
    }
#endif
}
Beispiel #17
0
/* E3A island generation */
int build_island_e3(newfaction ** players, int x, int y, int numfactions, int minsize)
{
#define MIN_QUALITY 1000
    int nfactions = 0;
    region_list *rlist = NULL;
    region_list *island = NULL;
    plane *pl = findplane(x, y);
    region *r = findregion(x, y);
    int nsize = 1;
    int q, maxq = INT_MIN, minq = INT_MAX;

    if (!r)
        r = new_region(x, y, pl, 0);
    assert(!r->units);
    do {
        terraform_region(r, random_terrain_e3(NODIRECTION));
    } while (!r->land);

    while (r) {
        fset(r, RF_MARK);
        if (r->land) {
            if (nsize < minsize) {
                nsize += random_neighbours(r, &rlist, &random_terrain_e3);
            }
            else {
                nsize += random_neighbours(r, &rlist, &get_ocean);
            }
        }
        regionqueue_push(&island, r);
        r = regionqueue_pop(&rlist);
    }

    smooth_island(island);

    if (nsize > minsize / 2) {
        for (rlist = island; rlist; rlist = rlist->next) {
            r = rlist->data;
            if (r->land && fval(r, RF_MARK)) {
                region *rn[MAXDIRECTIONS];

                get_neighbours(r, rn);
                q = region_quality(r, rn);
                if (q >= MIN_QUALITY && nfactions < numfactions && *players) {
                    starting_region(players, r, rn);
                    minq = _min(minq, q);
                    maxq = _max(maxq, q);
                    ++nfactions;
                }
            }
        }

        for (rlist = island; rlist && nfactions < numfactions; rlist = rlist->next) {
            r = rlist->data;
            if (!r->land && fval(r, RF_MARK)) {
                region *rn[MAXDIRECTIONS];
                get_neighbours(r, rn);
                q = region_quality(r, rn);
                if (q >= MIN_QUALITY * 4 / 3 && nfactions < numfactions && *players) {
                    starting_region(players, r, rn);
                    minq = _min(minq, q);
                    maxq = _max(maxq, q);
                    ++nfactions;
                }
            }
        }
    }

    for (rlist = island; rlist; rlist = rlist->next) {
        r = rlist->data;
        if (r->units) {
            region *rn[MAXDIRECTIONS];
            get_neighbours(r, rn);
            q = region_quality(r, rn);
            if (q - minq > (maxq - minq) * 2 / 3) {
                terraform_region(r, newterrain(T_HIGHLAND));
                prepare_starting_region(r);
            }
            r->land->money = 50000;   /* 2% = 1000 silver */
        }
        else if (r->land) {
            r->land->money *= 4;
        }
    }
    return nfactions;
}