Пример #1
0
/* Choose a place to start growing an island from
*/
static int
place_island(int c, int *xp, int *yp)
{
    int d, sx, sy;
    int ssy = roll0(WORLD_Y);
    int ssx = new_x(roll0(WORLD_X / 2) * 2 + ssy % 2);

    if (ssx > WORLD_X - 2)
	ssx = new_x(ssx + 2);
    for (d = di + id; d >= id; --d) {
	sx = ssx;
	sy = ssy;
	*xp = new_x(sx + 2);
	for (*yp = sy; *xp != sx || *yp != sy; *xp += 2) {
	    if (*xp >= WORLD_X) {
		*yp = new_y(*yp + 1);
		*xp = *yp % 2;
		if (*xp == sx && *yp == sy)
		    break;
	    }
	    if (own[*xp][*yp] == -1 && try_to_grow(c, *xp, *yp, d))
		return 1;
	}
    }
    return 0;
}
Пример #2
0
static void
preport(struct nwsstr *np)
{
    char *cp;
    int i;
    char buf[255];
    char num[128];
    char *ptr;

    cp = buf;
    sprintf(buf, "%-16.16s  ", ctime(&np->nws_when));
    cp += strlen(cp);
    ptr = numstr(num, np->nws_ntm);
    /*
     * vary the order of the printing of "%d times "
     */
    if (roll0(4) == 0 && np->nws_ntm > 1) {
	sprintf(cp, "%s times ", ptr);
	cp += strlen(cp);
	np->nws_ntm = 1;
    }
    strcpy(cp, cname(np->nws_ano));
    cp += strlen(cp);
    *cp++ = ' ';
    sprintf(cp, rpt[(int)np->nws_vrb].r_newstory[roll0(NUM_RPTS)],
	    cname(np->nws_vno));
    cp += strlen(cp);
    if (np->nws_ntm != 1) {
	sprintf(cp, " %s times", ptr);
	cp += strlen(cp);
    }
    if (cp - buf > 80) {
	for (i = 80; --i > 60;)
	    if (buf[i] == ' ')
		break;
	buf[i] = '\0';
	pr("%s\n\t\t  %s\n", buf, &buf[i + 1]);
    } else {
	pr("%s\n", buf);
    }
    np->nws_ntm = 0;
    return;
}
Пример #3
0
static int
grow_one_sector(int c)
{
    int done, coast_search, try1, x, y, newx, newy, i, n, sx, sy;

    spike = roll0(100) < sp;
    if ((try1 = new_try(c)) == -1)
	return 0;
    x = sx = sectx[c][try1];
    y = sy = secty[c][try1];
    coast_search = 0;
    done = 0;
    do {
	if (spike) {
	    for (i = roll0(6), n = 0; n < 12 && !done; i = (i + 1) % 6, ++n) {
		newx = new_x(x + dirx[i]);
		newy = new_y(y + diry[i]);
		if (own[newx][newy] == -1 &&
		    (n > 5 ||
		     (own[new_x(x+dirx[(i+5)%6])][new_y(y+diry[(i+5)%6])] == -1 &&
		      own[new_x(x+dirx[(i+1)%6])][new_y(y+diry[(i+1)%6])] == -1)))
		    if (try_to_grow(c, newx, newy, c < nc ? di : id))
			done = 1;
	    }
	} else
	    for (i = roll0(6), n = 0; n < 6 && !done; i = (i + 1) % 6, ++n) {
		newx = new_x(x + dirx[i]);
		newy = new_y(y + diry[i]);
		if (own[newx][newy] == -1)
		    if (try_to_grow(c, newx, newy, c < nc ? di : id))
			done = 1;
	    }
	next_coast(c, x, y, &x, &y);
	++coast_search;
    } while (!done && coast_search < COAST_SEARCH_MAX &&
	     (secs == 1 || x != sx || y != sy));
    if (!done && c < nc) {
	qprint("fairland: error -- continent %c had no room to grow!\n",
	       numletter[c % 62]);
	fl_status |= STATUS_NO_ROOM;
    }
    return done;
}
Пример #4
0
static int
set_oil(int e)
{
    int oil = 0;
    if (e < LANDMIN)
	oil = (LANDMIN - e) * 2 + roll0(2);
    else if (e <= OIL_MAX)
	oil = (120 * (OIL_MAX - e + 1)) / (OIL_MAX - LANDMIN + 1);
    if (oil > 100)
	oil = 100;
    return oil;
}
Пример #5
0
static void
fl_move(int j)
{
    int i, n, newx, newy;

    for (i = roll0(6), n = 0; n < 6; i = (i + 1) % 6, ++n) {
	newx = new_x(capx[j] + dirx[i]);
	newy = new_y(capy[j] + diry[i]);
	if (iso(j, newx, newy) >= iso(j, capx[j], capy[j])) {
	    capx[j] = newx;
	    capy[j] = newy;
	    return;
	}
    }
}
Пример #6
0
/*
 * Given the fact that plague exists, kill off
 * people if in plague state DYING.  Increment
 * the plague time.  Return "current" plague
 * stage.  No reports generated here anymore.
 */
int
plague_people(struct natstr *np, short *vec,
	      int *pstage, int *ptime, int etus)
{
    int stage;
    double plg_num;
    double plg_denom;
    double pct_left;

    if (opt_NO_PLAGUE)		/* no plague nothing to do */
	return PLG_HEALTHY;
    *ptime -= etus;
    stage = *pstage;
    switch (stage) {
    case PLG_DYING:
	plg_num = 100.0 * etus;
	plg_denom = (np->nat_level[NAT_RLEV] + 100.0) *
	    (*ptime + etus + 1.0);
	pct_left = 1.0 - plg_num / plg_denom;
	if (pct_left < 0.2)
	    pct_left = 0.2;
	vec[I_CIVIL] = vec[I_CIVIL] * pct_left;
	vec[I_MILIT] = vec[I_MILIT] * pct_left;
	vec[I_UW] = vec[I_UW] * pct_left;
	break;
    case PLG_INFECT:
    case PLG_INCUBATE:
	break;
    case PLG_EXPOSED:
	*ptime = 0;
	break;
    default:
	/* bad */
	logerror("plague_people: bad pstage %d", stage);
	*pstage = PLG_HEALTHY;
	*ptime = 0;
	return PLG_HEALTHY;
    }
    if (*ptime <= 0) {
	*pstage -= 1;
	*ptime = etus / 2 + roll0(etus);
    }
    return stage;
}
Пример #7
0
static void
grow_islands(void)
{
    int c, x, y, isiz;

    for (c = nc; c < nc + ni; ++c) {
	secs = 0;
	if (!place_island(c, &x, &y))
	    return;
	isiz = roll(is) + roll0(is);
	do {
	    ++secs;
	    find_coast(c);
	} while (secs < isiz && grow_one_sector(c));
	find_coast(c);
	qprint(" %d(%d)", c - nc + 1, secs);
	isecs[c] = secs;
	ctot++;
    }
}
Пример #8
0
static int
new_try(int c)
{
    int i, starti;

    if (secs == 1) {
	if (sectc[c][0])
	    return 0;
    } else {
	i = starti = (spike && sectc[c][secs - 1]) ? secs - 1 : roll0(secs);
	do {
	    if (sectc[c][i])
		return i;
	    i = (i + 1) % secs;
	} while (i != starti);
	assert(c >= nc);
	return -1;
    }
    return -1;
}
Пример #9
0
/* Decide where the mountains go
*/
static void
elevate_land(void)
{
    int i, mountain_search, k, c, total, ns, nm, highest, where, h, newk,
	r, dk;

    for (c = 0; c < ctot; ++c) {
	total = 0;
	ns = (c < nc) ? sc : isecs[c];
	nm = (pm * ns) / 100;

/* Place the mountains */

	for (i = 0; i < ns; ++i) {
	    dsea[i] = distance_to_sea();
	    weight[i] = (total += (dsea[i] * dsea[i]));
	}

	for (k = nm, mountain_search = 0;
	     k && mountain_search < MOUNTAIN_SEARCH_MAX;
	     ++mountain_search) {
	    r = roll0(total);
	    for (i = 0; i < ns; ++i)
		if (r < weight[i] && ELEV == -INFINITY &&
		    (c >= nc ||
		     ((!(capx[c] == sectx[c][i] &&
			 capy[c] == secty[c][i])) &&
		      (!(new_x(capx[c] + 2) == sectx[c][i] &&
			 capy[c] == secty[c][i]))))) {
		    ELEV = INFINITY;
		    break;
		}
	    --k;
	}

/* Elevate land that is not mountain and not capital */

	for (i = 0; i < ns; ++i)
	    dmoun[i] = distance_to_mountain();
	dk = (ns - nm - ((c < nc) ? 3 : 1) > 0) ?
	  (100 * (HIGHMIN - LANDMIN)) / (ns - nm - ((c < nc) ? 3 : 1)) :
	  100 * INFINITY;
	for (k = 100 * (HIGHMIN - 1);; k -= dk) {
	    highest = -INFINITY;
	    where = -1;
	    for (i = 0; i < ns; ++i) {
		if (ELEV != INFINITY &&
		    (c >= nc || ((!(capx[c] == sectx[c][i] &&
				    capy[c] == secty[c][i])) &&
				 (!(new_x(capx[c] + 2) == sectx[c][i] &&
				    capy[c] == secty[c][i]))))) {
		    h = 3 * (5 - dmoun[i]) + dsea[i];
		    if (h > highest) {
			highest = h;
			where = i;
		    }
		}
	    }
	    if (where == -1)
		break;
	    newk = k / 100;
	    if (newk >= HILLMIN && newk < PLATMIN)
		newk = PLATMIN;
	    if (newk < LANDMIN)
		newk = LANDMIN;
	    elev[sectx[c][where]][secty[c][where]] = newk;
	    dsea[where] = -INFINITY;
	    dmoun[where] = INFINITY;
	}

/* Elevate the mountains and capitals */

	for (i = 0; i < ns; ++i) {
	    if (ELEV == INFINITY) {
		if (dsea[i] == 1)
		    ELEV = HILLMIN + roll0(PLATMIN - HILLMIN);
		else
		    ELEV = HIGHMIN + roll0((256 - HIGHMIN) / 2) +
		      roll0((256 - HIGHMIN) / 2);
	    } else if (c < nc &&
		       (((capx[c] == sectx[c][i] && capy[c] == secty[c][i])) ||
			((new_x(capx[c] + 2) == sectx[c][i] &&
			  capy[c] == secty[c][i]))))
		ELEV = PLATMIN;
	}
    }
}