server/src/mapper/map_region.c

334 lines
7.1 KiB
C
Raw Normal View History

2001-01-25 10:37:55 +01:00
/* vi: set ts=2:
*
*
2001-01-25 10:37:55 +01:00
* Eressea PB(E)M host Copyright (C) 1998-2000
* Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de)
* Henning Peters (faroul@beyond.kn-bremen.de)
* Enno Rehling (enno@eressea-pbem.de)
* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
*
* This program may not be used, modified or distributed without
* prior permission by the authors of Eressea.
*/
#include <config.h>
#include <curses.h>
#include <ctype.h>
2001-01-25 10:37:55 +01:00
#include <eressea.h>
#include "mapper.h"
/* kernel includes */
#include <building.h>
#include <faction.h>
#include <plane.h>
#include <race.h>
#include <region.h>
#include <ship.h>
#include <unit.h>
#include <curse.h>
2001-01-25 10:37:55 +01:00
/* util includes */
#include <base36.h>
/* libc includes */
#include <stdlib.h>
#include <string.h>
void
ncat(int n)
{
static char s[10];
sprintf(s, " %d", n);
sncat(buf, s, BUFSIZE);
}
int rbottom;
dbllist *reglist = NULL;
static dbllist *runten = NULL, *roben = NULL;
#define LASTLINE SY-2
/* Letzte Zeile, in der Regionsinfo bei der Karte kommt */
static void
ClearRegion(void)
2001-01-25 10:37:55 +01:00
{
int line;
refresh();
for (line = 0; line < LASTLINE; line++) {
movexy(SX - 38, line);
clrtoeol();
}
}
void
ScrollRegList(int dir)
{
dbllist *hlp;
int line;
if ((dir == -1 && !runten->next) || (dir == 1 && !roben->prev))
return;
switch (dir) {
case -1:
for (line = 0; line < SY - 4 && runten->next; line++) {
roben = roben->next;
runten = runten->next;
}
ClearRegion();
for (line = 0, hlp = roben; line < LASTLINE && hlp; line++, hlp = hlp->next) {
movexy(SX - 37, line);
addstr(hlp->s);
}
rbottom = line;
break;
case 1:
for (line = 0; line < SY - 4 && roben->prev; line++) {
roben = roben->prev;
runten = runten->prev;
}
ClearRegion();
for (line = 0, hlp = roben; line < LASTLINE && hlp; line++, hlp = hlp->next) {
movexy(SX - 37, line);
addstr(hlp->s);
}
rbottom = line;
break;
}
}
void
saddstr(char *s)
{
if (s[0] < ' ')
s++;
addstr(s);
}
void
DisplayRegList(int neu)
{
int line;
dbllist *hlp;
ClearRegion();
if (!reglist) {
movexy(SX - 30, 0);
addstr("undefiniert");
refresh();
return;
}
if (neu)
runten = reglist;
else
runten = roben;
for (line = 0, hlp = runten; line < LASTLINE && hlp; line++, hlp = hlp->next) {
movexy(SX - 37, line);
saddstr(hlp->s);
if (runten->next)
runten = runten->next;
}
rbottom = line;
if (neu)
roben = reglist;
refresh();
}
void
SpecialFunction(region *r)
{
WINDOW *win;
win = openwin(60, 5, "< Specials Regions >");
wmove(win, 1, 2);
wAddstr("1 - set Godcurse");
wmove(win, 2, 2);
wrefresh(win);
switch(getch()) {
case '1':
if(!is_cursed_internal(r->attribs, C_CURSED_BY_THE_GODS, 0)) {
create_curse(NULL, &r->attribs, C_CURSED_BY_THE_GODS, 0,
100, 100, 0, 0);
set_curseflag(r->attribs, C_CURSED_BY_THE_GODS, 0, CURSE_ISNEW|CURSE_IMMUN);
modified = 1;
break;
}
default:
break;
}
delwin(win);
}
2001-01-25 10:37:55 +01:00
char Tchar[MAXRACES] = "ZEOGMTDIHK~uifdwtbrsz";
void
showregion(region * r, char full)
{
unit *u;
building *b;
ship *sh;
faction *f;
int d,pp=0, ecount[MAXRACES], count[MAXRACES];
char str[256];
if (reglist) {
freelist(reglist);
reglist = NULL;
}
if (!r) return;
memset(ecount, 0, sizeof(ecount));
strncpy(str, rname(r, NULL), 24);
str[24] = 0;
sprintf(buf, "%s (%d,%d)", str, r->x, r->y);
adddbllist(&reglist, buf);
memset(str,'<EFBFBD>',strlen(buf)+1);
str[strlen(buf)+1] = 0;
adddbllist(&reglist, str);
if (r->terrain != T_OCEAN && r->terrain!=T_FIREWALL) {
sprintf(buf, " %hd Runden alt:", r->age);
adddbllist(&reglist, buf);
sprintf(buf, " %d Bauern, %d(%d) Silber", rpeasants(r), rmoney(r), count_all_money(r));
adddbllist(&reglist, buf);
sprintf(buf, " %d Pferde, %d ", rhorses(r), rtrees(r));
if (fval(r,RF_MALLORN))
sncat(buf, "Mallorn", BUFSIZE);
else
sncat(buf, "B<EFBFBD>ume", BUFSIZE);
adddbllist(&reglist, buf);
if (riron(r) > 0 || rlaen(r) > 0) {
2001-01-25 10:37:55 +01:00
sprintf(buf, " %d Eisen, %d Laen", riron(r), rlaen(r));
adddbllist(&reglist, buf);
}
}
if (fval(r, RF_CHAOTIC)) {
adddbllist(&reglist, "chaotisch");
}
if (r->planep) {
strcpy(buf,"Plane: ");
strncpy(str, r->planep->name, 30);
str[30] = 0; sncat(buf, str, BUFSIZE);
sncat(buf, " (", BUFSIZE);
sncat(buf, r->planep->name, BUFSIZE);
sncat(buf, ")", BUFSIZE);
adddbllist(&reglist, buf);
}
NL(reglist);
if (r->terrain != T_OCEAN) {
strcpy(buf, "Burgen:");
if (!r->buildings) {
sncat(buf, " keine", BUFSIZE);
adddbllist(&reglist, buf);
} else if (full) {
adddbllist(&reglist, buf);
for (b = r->buildings; b; b = b->next) {
adddbllist(&reglist, Buildingid(b));
for (u = r->units; u; u = u->next)
if (u->building == b && fval(u, FL_OWNER)) {
strncpy(str, u->name, 27);
str[27] = 0;
sprintf(buf, " %s (%s)", str, unitid(u));
adddbllist(&reglist, buf);
strncpy(str, factionname(u->faction), 34);
str[34] = 0;
sprintf(buf, " %s", str);
adddbllist(&reglist, buf);
break;
}
if (!u)
adddbllist(&reglist, " steht leer");
}
} else {
d = 0;
for (b = r->buildings; b; b = b->next)
d++;
ncat(d);
adddbllist(&reglist, buf);
}
NL(reglist);
}
strcpy(buf, "Schiffe:");
if (!r->ships) {
sncat(buf, " keine", BUFSIZE);
adddbllist(&reglist, buf);
} else if (full) {
adddbllist(&reglist, buf);
for (sh = r->ships; sh; sh = sh->next) {
adddbllist(&reglist, Shipid(sh));
for (u = r->units; u; u = u->next)
if (u->ship == sh && fval(u, FL_OWNER)) {
strncpy(str, u->name, 28);
str[28] = 0;
sprintf(buf, " %s (%s)", str, unitid(u));
adddbllist(&reglist, buf);
sprintf(buf, " %s", factionname(u->faction));
adddbllist(&reglist, buf);
break;
}
if (!u)
adddbllist(&reglist, " ohne Besitzer");
}
} else {
d = 0;
for (sh = r->ships; sh; sh = sh->next)
d++;
ncat(d);
adddbllist(&reglist, buf);
}
NL(reglist);
if (!factions)
return;
strcpy(buf, "Parteien:");
if (!r->units) {
sncat(buf, " keine", BUFSIZE);
adddbllist(&reglist, buf);
} else {
adddbllist(&reglist, buf);
for (f = factions; f; f = f->next)
f->num_people = f->nunits = 0;
for (u = r->units; u; u = u->next) {
if (u->faction) {
u->faction->nunits++;
u->faction->num_people += u->number;
} else
fprintf(stderr,"Unit %s hat keine faction!\n",unitid(u));
}
for (f = factions; f; f = f->next)
if (f->nunits) {
sprintf(buf, " %-29.29s (%s)", f->name, factionid(f));
adddbllist(&reglist, buf);
sprintf(buf, " Einheiten: %d; Leute: %d %c",
f->nunits, f->num_people, Tchar[f->race]);
adddbllist(&reglist, buf);
}
for (d = RC_UNDEAD; d < MAXRACES; d++)
ecount[d] = count[d] = 0;
for (u = r->units; u; u = u->next) {
if (u->race >= RC_UNDEAD)
pp=1;
ecount[u->race]++;
count[u->race] += u->number;
}
if (pp) {
NL(reglist);
adddbllist(&reglist, "Monster, Zauber usw.:");
for (d = RC_UNDEAD; d < MAXRACES; d++) {
if (count[d]) {
sprintf(buf, " %s: %d in %d", race[d].name[0], count[d], ecount[d]);
adddbllist(&reglist, buf);
}
}
}
}
NL(reglist);
}