2015-07-06 21:31:27 +02:00
/*
2015-01-30 22:10:29 +01:00
Copyright ( c ) 1998 - 2015 , Enno Rehling < enno @ eressea . de >
2014-08-17 00:14:50 +02:00
Katja Zedel < katze @ felidae . kn - bremen . de
Christian Schlittchen < corwin @ amber . kn - bremen . de >
2010-08-08 10:06:34 +02:00
Permission to use , copy , modify , and / or distribute this software for any
purpose with or without fee is hereby granted , provided that the above
copyright notice and this permission notice appear in all copies .
THE SOFTWARE IS PROVIDED " AS IS " AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS . IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT , INDIRECT , OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE , DATA OR PROFITS , WHETHER IN AN
ACTION OF CONTRACT , NEGLIGENCE OR OTHER TORTIOUS ACTION , ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE .
* */
# define ECHECK_VERSION "4.01"
# include <platform.h>
# include <kernel/config.h>
2014-08-27 06:40:18 +02:00
# include "reports.h"
2014-11-01 12:09:56 +01:00
# include "laws.h"
2014-11-11 16:53:56 +01:00
# include "monster.h"
2010-08-08 10:06:34 +02:00
/* modules includes */
# include <modules/score.h>
/* attributes includes */
# include <attributes/overrideroads.h>
# include <attributes/otherfaction.h>
# include <attributes/reduceproduction.h>
/* gamecode includes */
2014-08-31 08:58:55 +02:00
# include "alchemy.h"
2010-08-08 10:06:34 +02:00
# include "economy.h"
2014-08-27 06:40:18 +02:00
# include "move.h"
2014-08-31 08:58:55 +02:00
# include "upkeep.h"
2014-08-27 21:09:39 +02:00
# include "vortex.h"
2010-08-08 10:06:34 +02:00
/* kernel includes */
2012-06-30 20:07:28 +02:00
# include <kernel/ally.h>
2010-08-08 10:06:34 +02:00
# include <kernel/connection.h>
# include <kernel/build.h>
# include <kernel/building.h>
# include <kernel/calendar.h>
2012-06-03 22:39:42 +02:00
# include <kernel/curse.h>
2010-08-08 10:06:34 +02:00
# include <kernel/faction.h>
# include <kernel/group.h>
# include <kernel/item.h>
2014-06-09 18:54:48 +02:00
# include <kernel/messages.h>
2010-08-08 10:06:34 +02:00
# include <kernel/objtypes.h>
# include <kernel/order.h>
# include <kernel/plane.h>
# include <kernel/pool.h>
# include <kernel/race.h>
# include <kernel/region.h>
# include <kernel/render.h>
# include <kernel/resources.h>
# include <kernel/save.h>
# include <kernel/ship.h>
2012-05-26 08:31:37 +02:00
# include <kernel/spell.h>
2012-05-25 07:10:18 +02:00
# include <kernel/spellbook.h>
2010-08-08 10:06:34 +02:00
# include <kernel/teleport.h>
# include <kernel/terrain.h>
# include <kernel/terrainid.h>
# include <kernel/unit.h>
# include <kernel/alliance.h>
/* util includes */
# include <util/attrib.h>
# include <util/base36.h>
# include <util/bsdstring.h>
# include <util/goodies.h>
# include <util/language.h>
# include <util/lists.h>
# include <util/log.h>
# include <util/message.h>
# include <util/nrmessage.h>
2012-05-31 04:55:17 +02:00
# include <quicklist.h>
2010-08-08 10:06:34 +02:00
# include <util/rng.h>
2015-05-13 04:25:50 +02:00
# include <filestream.h>
2010-08-08 10:06:34 +02:00
/* libc includes */
# include <assert.h>
# include <ctype.h>
# include <errno.h>
# include <string.h>
# include <stddef.h>
# include <stdio.h>
# include <time.h>
# include <math.h>
# include <limits.h>
# include <stdlib.h>
extern int verbosity ;
extern int * storms ;
2011-03-07 08:02:35 +01:00
extern int weeks_per_month ;
extern int months_per_year ;
static char * gamedate_season ( const struct locale * lang )
2010-08-08 10:06:34 +02:00
{
2014-08-24 22:54:40 +02:00
static char buf [ 256 ] ; // FIXME: static return value
2014-08-17 00:14:50 +02:00
gamedate gd ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
get_gamedate ( turn , & gd ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
sprintf ( buf , ( const char * ) LOC ( lang , " nr_calendar_season " ) ,
LOC ( lang , weeknames [ gd . week ] ) ,
LOC ( lang , monthnames [ gd . month ] ) ,
gd . year ,
agename ? LOC ( lang , agename ) : " " , LOC ( lang , seasonnames [ gd . season ] ) ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
return buf ;
2010-08-08 10:06:34 +02:00
}
2015-05-13 04:25:50 +02:00
void newline ( stream * out ) {
sputs ( " " , out ) ;
2010-08-08 10:06:34 +02:00
}
2015-05-19 08:26:44 +02:00
void write_spaces ( stream * out , size_t num ) {
static const char spaces [ REPORTWIDTH ] = " " ;
while ( num > 0 ) {
size_t bytes = ( num > REPORTWIDTH ) ? REPORTWIDTH : num ;
swrite ( spaces , sizeof ( char ) , bytes , out ) ;
num - = bytes ;
}
}
2010-08-08 10:06:34 +02:00
2015-05-13 05:36:00 +02:00
static void centre ( stream * out , const char * s , bool breaking )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
/* Bei Namen die genau 80 Zeichen lang sind, kann es hier Probleme
* geben . Seltsamerweise wird i dann auf MAXINT oder aehnlich
* initialisiert . Deswegen keine Strings die laenger als REPORTWIDTH
* sind ! */
if ( breaking & & REPORTWIDTH < strlen ( s ) ) {
strlist * T , * SP = 0 ;
sparagraph ( & SP , s , 0 , 0 ) ;
T = SP ;
while ( SP ) {
2015-05-13 05:36:00 +02:00
centre ( out , SP - > s , false ) ;
2014-08-17 00:14:50 +02:00
SP = SP - > next ;
}
freestrlist ( T ) ;
}
else {
2015-05-19 08:26:44 +02:00
write_spaces ( out , ( REPORTWIDTH - strlen ( s ) + 1 ) / 2 ) ;
2015-05-13 05:36:00 +02:00
sputs ( s , out ) ;
2014-08-17 00:14:50 +02:00
}
2010-08-08 10:06:34 +02:00
}
static void
2015-05-13 04:25:50 +02:00
paragraph ( stream * out , const char * str , ptrdiff_t indent , int hanging_indent ,
char marker )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
size_t length = REPORTWIDTH ;
2015-05-13 04:25:50 +02:00
const char * end , * begin , * mark = 0 ;
2014-08-17 00:14:50 +02:00
if ( ! str ) return ;
/* find out if there's a mark + indent already encoded in the string. */
2015-05-13 04:25:50 +02:00
if ( ! marker ) {
2014-08-17 00:14:50 +02:00
const char * x = str ;
while ( * x = = ' ' )
+ + x ;
indent + = x - str ;
if ( x [ 0 ] & & indent & & x [ 1 ] = = ' ' ) {
indent + = 2 ;
2015-05-13 04:25:50 +02:00
mark = x ;
2014-08-17 00:14:50 +02:00
str = x + 2 ;
hanging_indent - = 2 ;
}
2015-05-13 04:25:50 +02:00
}
else {
mark = & marker ;
2010-08-08 10:06:34 +02:00
}
2014-08-17 00:14:50 +02:00
begin = end = str ;
do {
const char * last_space = begin ;
if ( mark & & indent > = 2 ) {
2015-05-19 08:26:44 +02:00
write_spaces ( out , indent - 2 ) ;
2015-05-13 04:25:50 +02:00
swrite ( mark , sizeof ( char ) , 1 , out ) ;
2015-05-19 08:26:44 +02:00
write_spaces ( out , 1 ) ;
2014-08-17 00:14:50 +02:00
mark = 0 ;
}
else if ( begin = = str ) {
2015-05-19 08:26:44 +02:00
write_spaces ( out , indent ) ;
2014-08-17 00:14:50 +02:00
}
else {
2015-05-19 08:26:44 +02:00
write_spaces ( out , indent + hanging_indent ) ;
2014-08-17 00:14:50 +02:00
}
while ( * end & & end < = begin + length - indent ) {
if ( * end = = ' ' ) {
last_space = end ;
}
+ + end ;
}
if ( * end = = 0 )
last_space = end ;
if ( last_space = = begin ) {
/* there was no space in this line. clip it */
last_space = end ;
}
2015-05-13 04:25:50 +02:00
swrite ( begin , sizeof ( char ) , last_space - begin , out ) ;
2014-08-17 00:14:50 +02:00
begin = last_space ;
while ( * begin = = ' ' ) {
+ + begin ;
}
if ( begin > end )
begin = end ;
2015-05-13 04:25:50 +02:00
sputs ( " " , out ) ;
2014-08-17 00:14:50 +02:00
} while ( * begin ) ;
2010-08-08 10:06:34 +02:00
}
2012-07-09 00:40:37 +02:00
static size_t write_spell_modifier ( spell * sp , int flag , const char * str , bool cont , char * bufp , size_t size ) {
2014-08-17 00:14:50 +02:00
if ( sp - > sptyp & flag ) {
size_t bytes = 0 ;
if ( cont ) {
bytes = strlcpy ( bufp , " , " , size ) ;
}
else {
bytes = strlcpy ( bufp , " " , size ) ;
}
bytes + = strlcpy ( bufp + bytes , str , size - bytes ) ;
return bytes ;
}
return 0 ;
2012-07-09 00:40:37 +02:00
}
2015-05-13 05:36:00 +02:00
static void nr_spell ( stream * out , spellbook_entry * sbe , const struct locale * lang )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
int bytes , k , itemanz , costtyp ;
char buf [ 4096 ] ;
char * startp , * bufp = buf ;
size_t size = sizeof ( buf ) - 1 ;
spell * sp = sbe - > sp ;
const char * params = sp - > parameter ;
2010-08-08 10:06:34 +02:00
2015-05-13 05:36:00 +02:00
newline ( out ) ;
centre ( out , spell_name ( sp , lang ) , true ) ;
newline ( out ) ;
paragraph ( out , LOC ( lang , " nr_spell_description " ) , 0 , 0 , 0 ) ;
paragraph ( out , spell_info ( sp , lang ) , 2 , 0 , 0 ) ;
2012-07-09 00:40:37 +02:00
2014-08-17 00:14:50 +02:00
bytes = ( int ) strlcpy ( bufp , LOC ( lang , " nr_spell_type " ) , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
if ( size ) {
* bufp + + = ' ' ;
- - size ;
2012-07-09 00:40:37 +02:00
}
2014-08-17 00:14:50 +02:00
if ( sp - > sptyp & PRECOMBATSPELL ) {
bytes = ( int ) strlcpy ( bufp , LOC ( lang , " sptype_precombat " ) , size ) ;
}
else if ( sp - > sptyp & COMBATSPELL ) {
bytes = ( int ) strlcpy ( bufp , LOC ( lang , " sptype_combat " ) , size ) ;
}
else if ( sp - > sptyp & POSTCOMBATSPELL ) {
bytes = ( int ) strlcpy ( bufp , LOC ( lang , " sptype_postcombat " ) , size ) ;
}
else {
bytes = ( int ) strlcpy ( bufp , LOC ( lang , " sptype_normal " ) , size ) ;
}
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
* bufp = 0 ;
2015-05-13 05:36:00 +02:00
paragraph ( out , buf , 0 , 0 , 0 ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
sprintf ( buf , " %s %d " , LOC ( lang , " nr_spell_level " ) , sbe - > level ) ;
2015-05-13 05:36:00 +02:00
paragraph ( out , buf , 0 , 0 , 0 ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
sprintf ( buf , " %s %d " , LOC ( lang , " nr_spell_rank " ) , sp - > rank ) ;
2015-05-13 05:36:00 +02:00
paragraph ( out , buf , 0 , 0 , 0 ) ;
2011-03-07 08:02:35 +01:00
2015-05-13 05:36:00 +02:00
paragraph ( out , LOC ( lang , " nr_spell_components " ) , 0 , 0 , 0 ) ;
2014-08-17 00:14:50 +02:00
for ( k = 0 ; sp - > components [ k ] . type ; + + k ) {
const resource_type * rtype = sp - > components [ k ] . type ;
itemanz = sp - > components [ k ] . amount ;
costtyp = sp - > components [ k ] . cost ;
if ( itemanz > 0 ) {
size = sizeof ( buf ) - 1 ;
bufp = buf ;
if ( sp - > sptyp & SPELLLEVEL ) {
bytes =
_snprintf ( bufp , size , " %d %s " , itemanz , LOC ( lang , resourcename ( rtype ,
itemanz ! = 1 ) ) ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
if ( costtyp = = SPC_LEVEL | | costtyp = = SPC_LINEAR ) {
bytes = _snprintf ( bufp , size , " * %s " , LOC ( lang , " nr_level " ) ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
}
else {
bytes = _snprintf ( bufp , size , " %d %s " , itemanz , LOC ( lang , resourcename ( rtype , itemanz ! = 1 ) ) ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 ) {
WARN_STATIC_BUFFER ( ) ;
}
}
* bufp = 0 ;
2015-05-13 05:36:00 +02:00
paragraph ( out , buf , 2 , 2 , ' - ' ) ;
2014-08-17 00:14:50 +02:00
}
}
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
size = sizeof ( buf ) - 1 ;
bufp = buf ;
bytes = ( int ) strlcpy ( buf , LOC ( lang , " nr_spell_modifiers " ) , size ) ;
2011-03-07 08:02:35 +01:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2014-08-17 00:14:50 +02:00
WARN_STATIC_BUFFER ( ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
startp = bufp ;
bytes = ( int ) write_spell_modifier ( sp , FARCASTING , LOC ( lang , " smod_far " ) , startp ! = bufp , bufp , size ) ;
if ( bytes & & wrptr ( & bufp , & size , bytes ) ! = 0 ) {
2011-03-07 08:02:35 +01:00
WARN_STATIC_BUFFER ( ) ;
2014-08-17 00:14:50 +02:00
}
bytes = ( int ) write_spell_modifier ( sp , OCEANCASTABLE , LOC ( lang , " smod_sea " ) , startp ! = bufp , bufp , size ) ;
if ( bytes & & wrptr ( & bufp , & size , bytes ) ! = 0 ) {
2011-03-07 08:02:35 +01:00
WARN_STATIC_BUFFER ( ) ;
2014-08-17 00:14:50 +02:00
}
bytes = ( int ) write_spell_modifier ( sp , ONSHIPCAST , LOC ( lang , " smod_ship " ) , startp ! = bufp , bufp , size ) ;
if ( bytes & & wrptr ( & bufp , & size , bytes ) ! = 0 ) {
2011-03-07 08:02:35 +01:00
WARN_STATIC_BUFFER ( ) ;
2014-08-17 00:14:50 +02:00
}
bytes = ( int ) write_spell_modifier ( sp , NOTFAMILIARCAST , LOC ( lang , " smod_nofamiliar " ) , startp ! = bufp , bufp , size ) ;
if ( bytes & & wrptr ( & bufp , & size , bytes ) ! = 0 ) {
2011-03-07 08:02:35 +01:00
WARN_STATIC_BUFFER ( ) ;
2014-08-17 00:14:50 +02:00
}
if ( startp = = bufp ) {
bytes = ( int ) write_spell_modifier ( sp , NOTFAMILIARCAST , LOC ( lang , " smod_none " ) , startp ! = bufp , bufp , size ) ;
if ( bytes & & wrptr ( & bufp , & size , bytes ) ! = 0 ) {
WARN_STATIC_BUFFER ( ) ;
}
}
* bufp = 0 ;
2015-05-13 05:36:00 +02:00
paragraph ( out , buf , 0 , 0 , 0 ) ;
paragraph ( out , LOC ( lang , " nr_spell_syntax " ) , 0 , 0 , 0 ) ;
2014-08-17 00:14:50 +02:00
bufp = buf ;
size = sizeof ( buf ) - 1 ;
if ( sp - > sptyp & ISCOMBATSPELL ) {
bytes = ( int ) strlcpy ( bufp , LOC ( lang , keyword ( K_COMBATSPELL ) ) , size ) ;
}
else {
bytes = ( int ) strlcpy ( bufp , LOC ( lang , keyword ( K_CAST ) ) , size ) ;
}
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
/* Reihenfolge beachten: Erst REGION, dann STUFE! */
if ( sp - > sptyp & FARCASTING ) {
bytes = _snprintf ( bufp , size , " [%s x y] " , LOC ( lang , parameters [ P_REGION ] ) ) ;
2011-03-07 08:02:35 +01:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2014-08-17 00:14:50 +02:00
WARN_STATIC_BUFFER ( ) ;
}
if ( sp - > sptyp & SPELLLEVEL ) {
bytes = _snprintf ( bufp , size , " [%s n] " , LOC ( lang , parameters [ P_LEVEL ] ) ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
bytes = ( int ) _snprintf ( bufp , size , " \" %s \" " , spell_name ( sp , lang ) ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
while ( params & & * params ) {
typedef struct starget {
param_t param ;
int flag ;
const char * vars ;
} starget ;
starget targets [ ] = {
2015-01-30 20:37:14 +01:00
{ P_REGION , REGIONSPELL , NULL } ,
{ P_UNIT , UNITSPELL , " par_unit " } ,
{ P_SHIP , SHIPSPELL , " par_ship " } ,
{ P_BUILDING , BUILDINGSPELL , " par_building " } ,
{ 0 , 0 , NULL }
2014-08-17 00:14:50 +02:00
} ;
starget * targetp ;
char cp = * params + + ;
int i , maxparam = 0 ;
const char * locp ;
const char * syntaxp = sp - > syntax ;
if ( cp = = ' u ' ) {
targetp = targets + 1 ;
locp = LOC ( lang , targetp - > vars ) ;
bytes = ( int ) _snprintf ( bufp , size , " <%s> " , locp ) ;
if ( * params = = ' + ' ) {
+ + params ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) _snprintf ( bufp , size , " [<%s> ...] " , locp ) ;
}
2011-03-07 08:02:35 +01:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2014-08-17 00:14:50 +02:00
WARN_STATIC_BUFFER ( ) ;
}
else if ( cp = = ' s ' ) {
targetp = targets + 2 ;
2010-08-08 10:06:34 +02:00
locp = LOC ( lang , targetp - > vars ) ;
2014-08-17 00:14:50 +02:00
bytes = ( int ) _snprintf ( bufp , size , " <%s> " , locp ) ;
if ( * params = = ' + ' ) {
+ + params ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) _snprintf ( bufp , size , " [<%s> ...] " , locp ) ;
}
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
else if ( cp = = ' r ' ) {
bytes = ( int ) strlcpy ( bufp , " <x> <y> " , size ) ;
2011-03-07 08:02:35 +01:00
if ( * params = = ' + ' ) {
2014-08-17 00:14:50 +02:00
+ + params ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) strlcpy ( bufp , " [<x> <y> ...] " , size ) ;
}
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2011-03-07 08:02:35 +01:00
WARN_STATIC_BUFFER ( ) ;
2014-08-17 00:14:50 +02:00
}
else if ( cp = = ' b ' ) {
targetp = targets + 3 ;
locp = LOC ( lang , targetp - > vars ) ;
bytes = ( int ) _snprintf ( bufp , size , " <%s> " , locp ) ;
if ( * params = = ' + ' ) {
+ + params ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) _snprintf ( bufp , size , " [<%s> ...] " , locp ) ;
2010-08-08 10:06:34 +02:00
}
2014-08-17 00:14:50 +02:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
else if ( cp = = ' k ' ) {
if ( * params = = ' c ' ) {
/* skip over a potential id */
+ + params ;
}
for ( targetp = targets ; targetp - > flag ; + + targetp ) {
if ( sp - > sptyp & targetp - > flag )
+ + maxparam ;
}
if ( maxparam > 1 ) {
bytes = ( int ) strlcpy ( bufp , " ( " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
i = 0 ;
for ( targetp = targets ; targetp - > flag ; + + targetp ) {
if ( sp - > sptyp & targetp - > flag ) {
if ( i + + ! = 0 ) {
bytes = ( int ) strlcpy ( bufp , " | " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
if ( targetp - > param ) {
locp = LOC ( lang , targetp - > vars ) ;
bytes =
( int ) _snprintf ( bufp , size , " %s <%s> " , parameters [ targetp - > param ] ,
locp ) ;
if ( * params = = ' + ' ) {
+ + params ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) _snprintf ( bufp , size , " [<%s> ...] " , locp ) ;
}
}
else {
bytes =
( int ) _snprintf ( bufp , size , " %s " , parameters [ targetp - > param ] ) ;
}
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
}
if ( maxparam > 1 ) {
bytes = ( int ) strlcpy ( bufp , " ) " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
}
else if ( cp = = ' i ' | | cp = = ' c ' ) {
const char * cstr ;
assert ( syntaxp ) ;
cstr = strchr ( syntaxp , ' : ' ) ;
if ( ! cstr ) {
locp = LOC ( lang , mkname ( " spellpar " , syntaxp ) ) ;
}
else {
char substr [ 32 ] ;
strncpy ( substr , syntaxp , cstr - syntaxp ) ;
substr [ cstr - syntaxp ] = 0 ;
locp = LOC ( lang , mkname ( " spellpar " , substr ) ) ;
syntaxp = substr + 1 ;
}
bytes = ( int ) _snprintf ( bufp , size , " <%s> " , locp ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2010-08-08 10:06:34 +02:00
}
}
2014-08-17 00:14:50 +02:00
* bufp = 0 ;
2015-05-13 05:36:00 +02:00
paragraph ( out , buf , 2 , 0 , 0 ) ;
newline ( out ) ;
2010-08-08 10:06:34 +02:00
}
static void
2015-05-13 13:12:46 +02:00
nr_curses_i ( stream * out , int indent , const faction * viewer , objtype_t typ , const void * obj , attrib * a , int self )
2010-08-08 10:06:34 +02:00
{
2015-05-13 04:25:50 +02:00
for ( ; a ; a = a - > next ) {
char buf [ 4096 ] ;
message * msg ;
if ( fval ( a - > type , ATF_CURSE ) ) {
curse * c = ( curse * ) a - > data . v ;
if ( c - > type - > cansee ) {
self = c - > type - > cansee ( viewer , obj , typ , c , self ) ;
}
msg = msg_curse ( c , obj , typ , self ) ;
if ( msg ) {
newline ( out ) ;
nr_render ( msg , viewer - > locale , buf , sizeof ( buf ) , viewer ) ;
paragraph ( out , buf , indent , 2 , 0 ) ;
msg_release ( msg ) ;
}
}
else if ( a - > type = = & at_effect & & self ) {
effect_data * data = ( effect_data * ) a - > data . v ;
if ( data - > value > 0 ) {
msg = msg_message ( " nr_potion_effect " , " potion left " ,
data - > type - > itype - > rtype , data - > value ) ;
nr_render ( msg , viewer - > locale , buf , sizeof ( buf ) , viewer ) ;
paragraph ( out , buf , indent , 2 , 0 ) ;
msg_release ( msg ) ;
}
}
}
}
static void nr_curses ( stream * out , int indent , const faction * viewer , objtype_t typ , const void * obj )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
int self = 0 ;
2015-05-13 04:25:50 +02:00
attrib * a = NULL ;
2014-08-17 00:14:50 +02:00
region * r ;
/* Die Sichtbarkeit eines Zaubers und die Zaubermeldung sind bei
2015-07-06 21:31:27 +02:00
* Gebäuden und Schiffen je nach , ob man Besitzer ist , verschieden .
2015-05-13 04:25:50 +02:00
* Bei Einheiten sieht man Wirkungen auf eigene Einheiten immer .
2015-07-06 21:31:27 +02:00
* Spezialfälle ( besonderes Talent , verursachender Magier usw . werde
2015-05-13 04:25:50 +02:00
* bei jedem curse gesondert behandelt . */
2014-08-17 00:14:50 +02:00
if ( typ = = TYP_SHIP ) {
ship * sh = ( ship * ) obj ;
unit * owner = ship_owner ( sh ) ;
a = sh - > attribs ;
r = sh - > region ;
if ( owner ) {
if ( owner - > faction = = viewer ) {
self = 2 ;
}
else { /* steht eine person der Partei auf dem Schiff? */
unit * u = NULL ;
for ( u = r - > units ; u ; u = u - > next ) {
if ( u - > ship = = sh ) {
self = 1 ;
break ;
}
}
}
2010-08-08 10:06:34 +02:00
}
}
2014-08-17 00:14:50 +02:00
else if ( typ = = TYP_BUILDING ) {
building * b = ( building * ) obj ;
unit * owner ;
a = b - > attribs ;
r = b - > region ;
if ( ( owner = building_owner ( b ) ) ! = NULL ) {
if ( owner - > faction = = viewer ) {
self = 2 ;
}
else { /* steht eine Person der Partei in der Burg? */
unit * u = NULL ;
for ( u = r - > units ; u ; u = u - > next ) {
if ( u - > building = = b ) {
self = 1 ;
break ;
}
}
}
2010-08-08 10:06:34 +02:00
}
}
2014-08-17 00:14:50 +02:00
else if ( typ = = TYP_UNIT ) {
unit * u = ( unit * ) obj ;
a = u - > attribs ;
r = u - > region ;
if ( u - > faction = = viewer ) {
self = 2 ;
}
}
else if ( typ = = TYP_REGION ) {
r = ( region * ) obj ;
a = r - > attribs ;
}
else {
2015-05-13 04:25:50 +02:00
log_error ( " get_attribs: invalid object type %d " , typ ) ;
assert ( ! " invalid object type " ) ;
2010-08-08 10:06:34 +02:00
}
2015-05-13 13:12:46 +02:00
nr_curses_i ( out , indent , viewer , typ , obj , a , self ) ;
2010-08-08 10:06:34 +02:00
}
2015-05-13 05:36:00 +02:00
static void rps_nowrap ( stream * out , const char * s )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
const char * x = s ;
size_t indent = 0 ;
2015-05-13 05:36:00 +02:00
if ( ! x | | ! * x ) return ;
2014-08-17 00:14:50 +02:00
while ( * x + + = = ' ' ) ;
indent = x - s - 1 ;
if ( * ( x - 1 ) & & indent & & * x = = ' ' )
indent + = 2 ;
x = s ;
while ( * s ) {
if ( s = = x ) {
x = strchr ( x + 1 , ' ' ) ;
if ( ! x )
x = s + strlen ( s ) ;
}
2015-05-13 05:36:00 +02:00
swrite ( s + + , sizeof ( char ) , 1 , out ) ;
2014-08-17 00:14:50 +02:00
}
2010-08-08 10:06:34 +02:00
}
static void
2015-05-13 04:25:50 +02:00
nr_unit ( stream * out , const faction * f , const unit * u , int indent , int mode )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
attrib * a_otherfaction ;
char marker ;
int dh ;
bool isbattle = ( bool ) ( mode = = see_battle ) ;
char buf [ 8192 ] ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
if ( fval ( u_race ( u ) , RCF_INVISIBLE ) )
return ;
2010-08-08 10:06:34 +02:00
2015-05-13 04:25:50 +02:00
newline ( out ) ;
dh = bufunit ( f , u , indent , mode , buf , sizeof ( buf ) ) ;
2014-08-17 00:14:50 +02:00
a_otherfaction = a_find ( u - > attribs , & at_otherfaction ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
if ( u - > faction = = f ) {
marker = ' * ' ;
2010-08-08 10:06:34 +02:00
}
2014-12-09 14:14:35 +01:00
else if ( is_allied ( u - > faction , f ) ) {
2014-08-17 00:14:50 +02:00
marker = ' o ' ;
}
else if ( a_otherfaction & & f ! = u - > faction
& & get_otherfaction ( a_otherfaction ) = = f & & ! fval ( u , UFL_ANON_FACTION ) ) {
marker = ' ! ' ;
}
else {
if ( dh & & ! fval ( u , UFL_ANON_FACTION ) ) {
marker = ' + ' ;
}
else {
marker = ' - ' ;
}
}
2015-05-13 04:25:50 +02:00
paragraph ( out , buf , indent , 0 , marker ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
if ( ! isbattle ) {
2015-05-13 04:25:50 +02:00
nr_curses ( out , indent , f , TYP_UNIT , u ) ;
2014-08-17 00:14:50 +02:00
}
2010-08-08 10:06:34 +02:00
}
static void
2015-05-13 05:36:00 +02:00
rp_messages ( stream * out , message_list * msgs , faction * viewer , int indent ,
2014-08-17 00:14:50 +02:00
bool categorized )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
nrsection * section ;
2015-05-13 05:36:00 +02:00
2014-08-17 00:14:50 +02:00
if ( ! msgs )
return ;
for ( section = sections ; section ; section = section - > next ) {
int k = 0 ;
struct mlist * m = msgs - > begin ;
while ( m ) {
/* messagetype * mt = m->type; */
if ( ! categorized | | strcmp ( nr_section ( m - > msg ) , section - > name ) = = 0 ) {
char lbuf [ 8192 ] ;
if ( ! k & & categorized ) {
const char * section_title ;
char cat_identifier [ 24 ] ;
2015-05-13 05:36:00 +02:00
newline ( out ) ;
2014-08-17 00:14:50 +02:00
sprintf ( cat_identifier , " section_%s " , section - > name ) ;
section_title = LOC ( viewer - > locale , cat_identifier ) ;
2015-05-13 05:36:00 +02:00
centre ( out , section_title , true ) ;
newline ( out ) ;
2014-08-17 00:14:50 +02:00
k = 1 ;
}
nr_render ( m - > msg , viewer - > locale , lbuf , sizeof ( lbuf ) , viewer ) ;
2015-05-13 05:36:00 +02:00
paragraph ( out , lbuf , indent , 2 , 0 ) ;
2014-08-17 00:14:50 +02:00
}
m = m - > next ;
}
if ( ! categorized )
break ;
2010-08-08 10:06:34 +02:00
}
}
2015-05-13 05:36:00 +02:00
static void rp_battles ( stream * out , faction * f )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
if ( f - > battles ! = NULL ) {
struct bmsg * bm = f - > battles ;
2015-05-13 05:36:00 +02:00
newline ( out ) ;
centre ( out , LOC ( f - > locale , " section_battle " ) , false ) ;
newline ( out ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
while ( bm ) {
char buf [ 256 ] ;
RENDER ( f , buf , sizeof ( buf ) , ( " battle::header " , " region " , bm - > r ) ) ;
2015-05-13 05:36:00 +02:00
newline ( out ) ;
centre ( out , buf , true ) ;
newline ( out ) ;
rp_messages ( out , bm - > msgs , f , 0 , false ) ;
2014-08-17 00:14:50 +02:00
bm = bm - > next ;
}
2010-08-08 10:06:34 +02:00
}
}
2015-05-13 04:57:08 +02:00
static void prices ( stream * out , const region * r , const faction * f )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
const luxury_type * sale = NULL ;
struct demand * dmd ;
message * m ;
int bytes , n = 0 ;
char buf [ 4096 ] , * bufp = buf ;
size_t size = sizeof ( buf ) - 1 ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
if ( r - > land = = NULL | | r - > land - > demands = = NULL )
return ;
for ( dmd = r - > land - > demands ; dmd ; dmd = dmd - > next ) {
if ( dmd - > value = = 0 )
sale = dmd - > type ;
else if ( dmd - > value > 0 )
n + + ;
}
assert ( sale ! = NULL ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
m = msg_message ( " nr_market_sale " , " product price " ,
sale - > itype - > rtype , sale - > price ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
bytes = ( int ) nr_render ( m , f - > locale , bufp , size , f ) ;
2011-03-07 08:02:35 +01:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2014-08-17 00:14:50 +02:00
WARN_STATIC_BUFFER ( ) ;
msg_release ( m ) ;
2011-03-07 08:02:35 +01:00
2014-08-17 00:14:50 +02:00
if ( n > 0 ) {
bytes = ( int ) strlcpy ( bufp , " " , size ) ;
2011-03-07 08:02:35 +01:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2014-08-17 00:14:50 +02:00
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , " nr_trade_intro " ) , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2011-03-07 08:02:35 +01:00
WARN_STATIC_BUFFER ( ) ;
2014-08-17 00:14:50 +02:00
bytes = ( int ) strlcpy ( bufp , " " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2011-03-07 08:02:35 +01:00
WARN_STATIC_BUFFER ( ) ;
2014-08-17 00:14:50 +02:00
2015-01-30 20:43:40 +01:00
for ( dmd = r - > land - > demands ; dmd ; dmd = dmd - > next ) {
2014-08-17 00:14:50 +02:00
if ( dmd - > value > 0 ) {
2015-01-30 20:37:14 +01:00
m = msg_message ( " nr_market_price " , " product price " ,
dmd - > type - > itype - > rtype , dmd - > value * dmd - > type - > price ) ;
bytes = ( int ) nr_render ( m , f - > locale , bufp , size , f ) ;
2014-08-17 00:14:50 +02:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2015-01-30 20:37:14 +01:00
msg_release ( m ) ;
n - - ;
if ( n = = 0 ) {
2015-01-30 20:43:40 +01:00
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , " nr_trade_end " ) ,
size ) ;
2015-01-30 20:37:14 +01:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2015-05-13 04:25:50 +02:00
}
else if ( n = = 1 ) {
2015-01-30 20:37:14 +01:00
bytes = ( int ) strlcpy ( bufp , " " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2015-01-30 20:43:40 +01:00
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , " nr_trade_final " ) ,
size ) ;
2015-01-30 20:37:14 +01:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) strlcpy ( bufp , " " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2015-05-13 04:25:50 +02:00
}
else {
2015-01-30 20:43:40 +01:00
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , " nr_trade_next " ) ,
size ) ;
2015-01-30 20:37:14 +01:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) strlcpy ( bufp , " " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
2014-08-17 00:14:50 +02:00
}
2015-02-01 12:24:19 +01:00
}
2014-08-17 00:14:50 +02:00
}
/* Schreibe Paragraphen */
* bufp = 0 ;
2015-05-13 04:57:08 +02:00
paragraph ( out , buf , 0 , 0 , 0 ) ;
2010-08-08 10:06:34 +02:00
}
2012-06-24 07:41:07 +02:00
bool see_border ( const connection * b , const faction * f , const region * r )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
bool cs = b - > type - > fvisible ( b , f , r ) ;
2010-08-08 10:06:34 +02:00
if ( ! cs ) {
2014-08-17 00:14:50 +02:00
cs = b - > type - > rvisible ( b , r ) ;
if ( ! cs ) {
const unit * us = r - > units ;
while ( us & & ! cs ) {
if ( us - > faction = = f ) {
cs = b - > type - > uvisible ( b , us ) ;
if ( cs )
break ;
}
us = us - > next ;
}
2010-08-08 10:06:34 +02:00
}
}
2014-08-17 00:14:50 +02:00
return cs ;
2010-08-08 10:06:34 +02:00
}
2015-05-13 04:25:50 +02:00
static void describe ( stream * out , const seen_region * sr , faction * f )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
const region * r = sr - > r ;
int n ;
bool dh ;
direction_t d ;
int trees ;
int saplings ;
attrib * a ;
const char * tname ;
struct edge {
struct edge * next ;
char * name ;
bool transparent ;
bool block ;
bool exist [ MAXDIRECTIONS ] ;
direction_t lastd ;
} * edges = NULL , * e ;
bool see [ MAXDIRECTIONS ] ;
char buf [ 8192 ] ;
char * bufp = buf ;
size_t size = sizeof ( buf ) ;
int bytes ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
for ( d = 0 ; d ! = MAXDIRECTIONS ; d + + ) {
/* Nachbarregionen, die gesehen werden, ermitteln */
region * r2 = rconnect ( r , d ) ;
connection * b ;
see [ d ] = true ;
if ( ! r2 )
continue ;
for ( b = get_borders ( r , r2 ) ; b ; ) {
struct edge * e = edges ;
bool transparent = b - > type - > transparent ( b , f ) ;
const char * name = b - > type - > name ( b , r , f , GF_DETAILED | GF_ARTICLE ) ;
if ( ! transparent )
see [ d ] = false ;
if ( ! see_border ( b , f , r ) ) {
b = b - > next ;
continue ;
}
while ( e & & ( e - > transparent ! = transparent | | strcmp ( name , e - > name ) ) )
e = e - > next ;
if ( ! e ) {
e = calloc ( sizeof ( struct edge ) , 1 ) ;
e - > name = _strdup ( name ) ;
e - > transparent = transparent ;
e - > next = edges ;
edges = e ;
}
e - > lastd = d ;
e - > exist [ d ] = true ;
b = b - > next ;
2010-08-08 10:06:34 +02:00
}
}
2014-08-17 00:14:50 +02:00
bytes = ( int ) f_regionid ( r , f , bufp , size ) ;
2011-03-07 08:02:35 +01:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2014-08-17 00:14:50 +02:00
if ( sr - > mode = = see_travel ) {
bytes = _snprintf ( bufp , size , " (%s) " , LOC ( f - > locale , " see_travel " ) ) ;
2011-03-07 08:02:35 +01:00
}
2014-08-17 00:14:50 +02:00
else if ( sr - > mode = = see_neighbour ) {
bytes = _snprintf ( bufp , size , " (%s) " , LOC ( f - > locale , " see_neighbour " ) ) ;
}
else if ( sr - > mode = = see_lighthouse ) {
bytes = _snprintf ( bufp , size , " (%s) " , LOC ( f - > locale , " see_lighthouse " ) ) ;
}
else {
bytes = 0 ;
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2014-08-17 00:14:50 +02:00
WARN_STATIC_BUFFER ( ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
/* Terrain */
bytes = ( int ) strlcpy ( bufp , " , " , size ) ;
2011-03-07 08:02:35 +01:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2014-08-17 00:14:50 +02:00
WARN_STATIC_BUFFER ( ) ;
2011-03-07 08:02:35 +01:00
2014-08-17 00:14:50 +02:00
tname = terrain_name ( r ) ;
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , tname ) , size ) ;
2011-03-07 08:02:35 +01:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
/* Trees */
trees = rtrees ( r , 2 ) ;
saplings = rtrees ( r , 1 ) ;
if ( production ( r ) ) {
if ( trees > 0 | | saplings > 0 ) {
bytes = _snprintf ( bufp , size , " , %d/%d " , trees , saplings ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
if ( fval ( r , RF_MALLORN ) ) {
if ( trees = = 1 ) {
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , " nr_mallorntree " ) , size ) ;
}
else {
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , " nr_mallorntree_p " ) , size ) ;
}
}
else if ( trees = = 1 ) {
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , " nr_tree " ) , size ) ;
}
else {
2015-07-06 21:31:27 +02:00
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , " nr_tree_p " ) , size ) ; //TODO: V595 http://www.viva64.com/en/V595 The 'f' pointer was utilized before it was verified against nullptr. Check lines: 948, 956.
2014-08-17 00:14:50 +02:00
}
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
2010-08-08 10:06:34 +02:00
}
2014-08-17 00:14:50 +02:00
/* iron & stone */
if ( sr - > mode = = see_unit & & f ! = ( faction * ) NULL ) {
resource_report result [ MAX_RAWMATERIALS ] ;
int n , numresults = report_resources ( sr , result , MAX_RAWMATERIALS , f ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
for ( n = 0 ; n < numresults ; + + n ) {
if ( result [ n ] . number > = 0 & & result [ n ] . level > = 0 ) {
bytes = _snprintf ( bufp , size , " , %d %s/%d " , result [ n ] . number ,
LOC ( f - > locale , result [ n ] . name ) , result [ n ] . level ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
}
2010-08-08 10:06:34 +02:00
}
2014-08-17 00:14:50 +02:00
/* peasants & silver */
if ( rpeasants ( r ) ) {
int n = rpeasants ( r ) ;
bytes = _snprintf ( bufp , size , " , %d " , n ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
if ( r - > land - > ownership ) {
const char * str =
2015-01-08 20:55:29 +01:00
LOC ( f - > locale , mkname ( " morale " , itoa10 ( r - > land - > morale ) ) ) ;
2014-08-17 00:14:50 +02:00
bytes = _snprintf ( bufp , size , " %s " , str ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
if ( fval ( r , RF_ORCIFIED ) ) {
2011-03-07 08:02:35 +01:00
bytes = ( int ) strlcpy ( bufp , " " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2014-08-17 00:14:50 +02:00
WARN_STATIC_BUFFER ( ) ;
bytes =
( int ) strlcpy ( bufp , LOC ( f - > locale , n = = 1 ? " rc_orc " : " rc_orc_p " ) ,
size ) ;
}
else {
bytes = ( int ) strlcpy ( bufp , " " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes =
( int ) strlcpy ( bufp , LOC ( f - > locale , n = = 1 ? " peasant " : " peasant_p " ) ,
size ) ;
}
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2011-03-07 08:02:35 +01:00
WARN_STATIC_BUFFER ( ) ;
2014-08-17 00:14:50 +02:00
if ( is_mourning ( r , turn + 1 ) ) {
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , " nr_mourning " ) , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
}
if ( rmoney ( r ) & & sr - > mode > = see_travel ) {
bytes = _snprintf ( bufp , size , " , %d " , rmoney ( r ) ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2011-03-07 08:02:35 +01:00
WARN_STATIC_BUFFER ( ) ;
2014-08-17 00:14:50 +02:00
bytes =
( int ) strlcpy ( bufp , LOC ( f - > locale , resourcename ( get_resourcetype ( R_SILVER ) ,
rmoney ( r ) ! = 1 ) ) , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2011-03-07 08:02:35 +01:00
WARN_STATIC_BUFFER ( ) ;
2014-08-17 00:14:50 +02:00
}
/* Pferde */
if ( rhorses ( r ) ) {
bytes = _snprintf ( bufp , size , " , %d " , rhorses ( r ) ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2011-03-07 08:02:35 +01:00
WARN_STATIC_BUFFER ( ) ;
2014-08-17 00:14:50 +02:00
bytes =
( int ) strlcpy ( bufp , LOC ( f - > locale , resourcename ( get_resourcetype ( R_HORSE ) ,
( rhorses ( r ) > 1 ) ? GR_PLURAL : 0 ) ) , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2011-03-07 08:02:35 +01:00
WARN_STATIC_BUFFER ( ) ;
2010-08-08 10:06:34 +02:00
}
2014-08-17 00:14:50 +02:00
bytes = ( int ) strlcpy ( bufp , " . " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2011-03-07 08:02:35 +01:00
WARN_STATIC_BUFFER ( ) ;
2014-08-17 00:14:50 +02:00
if ( r - > display & & r - > display [ 0 ] ) {
bytes = ( int ) strlcpy ( bufp , " " , size ) ;
2011-03-07 08:02:35 +01:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2014-08-17 00:14:50 +02:00
bytes = ( int ) strlcpy ( bufp , r - > display , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
n = r - > display [ strlen ( r - > display ) - 1 ] ;
if ( n ! = ' ! ' & & n ! = ' ? ' & & n ! = ' . ' ) {
bytes = ( int ) strlcpy ( bufp , " . " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2010-08-08 10:06:34 +02:00
}
}
2014-08-17 00:14:50 +02:00
if ( rule_region_owners ( ) ) {
const faction * owner = region_get_owner ( r ) ;
2015-01-30 20:43:40 +01:00
message * msg ;
2015-01-14 16:13:08 +01:00
2014-08-17 00:14:50 +02:00
if ( owner ! = NULL ) {
2015-01-30 20:43:40 +01:00
msg = msg_message ( " nr_region_owner " , " faction " , owner ) ;
bytes = ( int ) nr_render ( msg , f - > locale , bufp , size , f ) ;
msg_release ( msg ) ;
2014-08-17 00:14:50 +02:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
}
a = a_find ( r - > attribs , & at_overrideroads ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
if ( a ) {
bytes = ( int ) strlcpy ( bufp , " " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) strlcpy ( bufp , ( char * ) a - > data . v , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
else {
int nrd = 0 ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
/* Nachbarregionen, die gesehen werden, ermitteln */
for ( d = 0 ; d ! = MAXDIRECTIONS ; d + + ) {
if ( see [ d ] & & rconnect ( r , d ) )
nrd + + ;
}
/* list directions */
dh = false ;
2014-08-27 21:09:39 +02:00
for ( d = 0 ; d ! = MAXDIRECTIONS ; d + + ) {
2014-08-17 00:14:50 +02:00
if ( see [ d ] ) {
2014-08-27 21:09:39 +02:00
region * r2 = rconnect ( r , d ) ;
if ( ! r2 )
continue ;
nrd - - ;
if ( dh ) {
char regname [ 4096 ] ;
if ( nrd = = 0 ) {
bytes = ( int ) strlcpy ( bufp , " " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , " nr_nb_final " ) , size ) ;
}
else {
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , " nr_nb_next " ) , size ) ;
}
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , directions [ d ] ) , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2014-08-17 00:14:50 +02:00
bytes = ( int ) strlcpy ( bufp , " " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2014-08-27 21:09:39 +02:00
f_regionid ( r2 , f , regname , sizeof ( regname ) ) ;
bytes = _snprintf ( bufp , size , trailinto ( r2 , f - > locale ) , regname ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2014-08-17 00:14:50 +02:00
}
else {
2014-08-27 21:09:39 +02:00
bytes = ( int ) strlcpy ( bufp , " " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
MSG ( ( " nr_vicinitystart " , " dir region " , d , r2 ) , bufp , size , f - > locale ,
f ) ;
bufp + = strlen ( bufp ) ;
dh = true ;
2014-08-17 00:14:50 +02:00
}
}
2014-08-27 21:09:39 +02:00
}
2014-08-17 00:14:50 +02:00
/* Spezielle Richtungen */
for ( a = a_find ( r - > attribs , & at_direction ) ; a & & a - > type = = & at_direction ;
a = a - > next ) {
spec_direction * d = ( spec_direction * ) ( a - > data . v ) ;
bytes = ( int ) strlcpy ( bufp , " " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , d - > desc ) , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) strlcpy ( bufp , " ( \" " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , d - > keyword ) , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) strlcpy ( bufp , " \" ) " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) strlcpy ( bufp , " . " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
dh = 1 ;
}
2010-08-08 10:06:34 +02:00
}
2015-05-13 04:57:08 +02:00
newline ( out ) ;
2010-08-08 10:06:34 +02:00
* bufp = 0 ;
2015-05-13 04:57:08 +02:00
paragraph ( out , buf , 0 , 0 , 0 ) ;
2014-08-17 00:14:50 +02:00
if ( sr - > mode = = see_unit & & is_astral ( r ) & &
! is_cursed ( r - > attribs , C_ASTRALBLOCK , 0 ) ) {
/* Sonderbehandlung Teleport-Ebene */
region_list * rl = astralregions ( r , inhabitable ) ;
region_list * rl2 ;
if ( rl ) {
bufp = buf ;
size = sizeof ( buf ) - 1 ;
2015-01-14 16:13:08 +01:00
2015-01-30 20:43:40 +01:00
// this localization might not work for every language but is fine for de and en
2015-01-14 16:13:08 +01:00
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , " nr_schemes_prefix " ) , size ) ;
2014-08-17 00:14:50 +02:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
rl2 = rl ;
while ( rl2 ) {
bytes = ( int ) f_regionid ( rl2 - > data , f , bufp , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
rl2 = rl2 - > next ;
if ( rl2 ) {
bytes = ( int ) strlcpy ( bufp , " , " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
}
2015-01-14 16:13:08 +01:00
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , " nr_schemes_postfix " ) , size ) ;
2014-08-17 00:14:50 +02:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
free_regionlist ( rl ) ;
/* Schreibe Paragraphen */
2015-05-13 04:57:08 +02:00
newline ( out ) ;
2014-08-17 00:14:50 +02:00
* bufp = 0 ;
2015-05-13 04:57:08 +02:00
paragraph ( out , buf , 0 , 0 , 0 ) ;
2014-08-17 00:14:50 +02:00
}
}
2015-07-06 21:31:27 +02:00
/* Wirkungen permanenter Sprüche */
2015-05-13 04:25:50 +02:00
nr_curses ( out , 0 , f , TYP_REGION , r ) ;
n = 0 ;
2014-08-17 00:14:50 +02:00
/* Produktionsreduktion */
a = a_find ( r - > attribs , & at_reduceproduction ) ;
if ( a ) {
const char * str = LOC ( f - > locale , " nr_reduced_production " ) ;
2015-05-13 04:57:08 +02:00
paragraph ( out , str , 0 , 0 , 0 ) ;
2014-08-17 00:14:50 +02:00
}
if ( edges )
2015-05-13 04:57:08 +02:00
newline ( out ) ;
2014-08-17 00:14:50 +02:00
for ( e = edges ; e ; e = e - > next ) {
bool first = true ;
2015-01-30 20:43:40 +01:00
message * msg ;
2015-01-14 16:13:08 +01:00
2014-08-17 00:14:50 +02:00
bufp = buf ;
size = sizeof ( buf ) - 1 ;
for ( d = 0 ; d ! = MAXDIRECTIONS ; + + d ) {
if ( ! e - > exist [ d ] )
continue ;
2015-01-30 20:43:40 +01:00
// this localization might not work for every language but is fine for de and en
2014-08-17 00:14:50 +02:00
if ( first )
2015-01-14 16:13:08 +01:00
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , " nr_borderlist_prefix " ) , size ) ;
2014-08-17 00:14:50 +02:00
else if ( e - > lastd = = d )
2015-01-14 16:13:08 +01:00
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , " nr_borderlist_lastfix " ) , size ) ;
2014-08-17 00:14:50 +02:00
else
2015-01-14 16:13:08 +01:00
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , " nr_borderlist_infix " ) , size ) ;
2014-08-17 00:14:50 +02:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , directions [ d ] ) , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
first = false ;
}
2015-01-30 20:43:40 +01:00
// TODO name is localized? Works for roads anyway...
msg = msg_message ( " nr_borderlist_postfix " , " transparent object " ,
e - > transparent , e - > name ) ;
bytes = ( int ) nr_render ( msg , f - > locale , bufp , size , f ) ;
msg_release ( msg ) ;
2014-08-17 00:14:50 +02:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2015-01-14 16:13:08 +01:00
2014-08-17 00:14:50 +02:00
* bufp = 0 ;
2015-05-13 04:57:08 +02:00
paragraph ( out , buf , 0 , 0 , 0 ) ;
2014-08-17 00:14:50 +02:00
}
if ( edges ) {
while ( edges ) {
e = edges - > next ;
free ( edges - > name ) ;
free ( edges ) ;
edges = e ;
}
2010-08-08 10:06:34 +02:00
}
}
2015-05-13 05:36:00 +02:00
static void statistics ( stream * out , const region * r , const faction * f )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
const unit * u ;
int number = 0 , p = rpeasants ( r ) ;
message * m ;
item * itm , * items = NULL ;
char buf [ 4096 ] ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
/* count */
for ( u = r - > units ; u ; u = u - > next ) {
if ( u - > faction = = f & & ! fval ( u_race ( u ) , RCF_INVISIBLE ) ) {
for ( itm = u - > items ; itm ; itm = itm - > next ) {
i_change ( & items , itm - > type , itm - > number ) ;
}
number + = u - > number ;
}
}
/* print */
2015-05-13 05:36:00 +02:00
newline ( out ) ;
2014-08-17 00:14:50 +02:00
m = msg_message ( " nr_stat_header " , " region " , r ) ;
2010-08-08 10:06:34 +02:00
nr_render ( m , f - > locale , buf , sizeof ( buf ) , f ) ;
msg_release ( m ) ;
2015-05-13 05:36:00 +02:00
paragraph ( out , buf , 0 , 0 , 0 ) ;
newline ( out ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
/* Region */
if ( skill_enabled ( SK_ENTERTAINMENT ) & & fval ( r - > terrain , LAND_REGION )
& & rmoney ( r ) ) {
m = msg_message ( " nr_stat_maxentertainment " , " max " , entertainmoney ( r ) ) ;
nr_render ( m , f - > locale , buf , sizeof ( buf ) , f ) ;
2015-05-13 05:36:00 +02:00
paragraph ( out , buf , 2 , 2 , 0 ) ;
2014-08-17 00:14:50 +02:00
msg_release ( m ) ;
2010-08-08 10:06:34 +02:00
}
2014-08-17 00:14:50 +02:00
if ( production ( r ) & & ( ! fval ( r - > terrain , SEA_REGION )
| | f - > race = = get_race ( RC_AQUARIAN ) ) ) {
if ( markets_module ( ) ) { /* hack */
m =
msg_message ( " nr_stat_salary_new " , " max " , wage ( r , NULL , NULL , turn + 1 ) ) ;
}
else {
m = msg_message ( " nr_stat_salary " , " max " , wage ( r , f , f - > race , turn + 1 ) ) ;
}
nr_render ( m , f - > locale , buf , sizeof ( buf ) , f ) ;
2015-05-13 05:36:00 +02:00
paragraph ( out , buf , 2 , 2 , 0 ) ;
2014-08-17 00:14:50 +02:00
msg_release ( m ) ;
2010-08-08 10:06:34 +02:00
}
2014-08-17 00:14:50 +02:00
if ( p ) {
m = msg_message ( " nr_stat_recruits " , " max " , p / RECRUITFRACTION ) ;
nr_render ( m , f - > locale , buf , sizeof ( buf ) , f ) ;
2015-05-13 05:36:00 +02:00
paragraph ( out , buf , 2 , 2 , 0 ) ;
2014-08-17 00:14:50 +02:00
msg_release ( m ) ;
if ( ! markets_module ( ) ) {
if ( buildingtype_exists ( r , bt_find ( " caravan " ) , true ) ) {
m = msg_message ( " nr_stat_luxuries " , " max " , ( p * 2 ) / TRADE_FRACTION ) ;
}
else {
m = msg_message ( " nr_stat_luxuries " , " max " , p / TRADE_FRACTION ) ;
}
nr_render ( m , f - > locale , buf , sizeof ( buf ) , f ) ;
2015-05-13 05:36:00 +02:00
paragraph ( out , buf , 2 , 2 , 0 ) ;
2014-08-17 00:14:50 +02:00
msg_release ( m ) ;
}
if ( r - > land - > ownership ) {
m = msg_message ( " nr_stat_morale " , " morale " , r - > land - > morale ) ;
nr_render ( m , f - > locale , buf , sizeof ( buf ) , f ) ;
2015-05-13 05:36:00 +02:00
paragraph ( out , buf , 2 , 2 , 0 ) ;
2014-08-17 00:14:50 +02:00
msg_release ( m ) ;
}
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
}
/* info about units */
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
m = msg_message ( " nr_stat_people " , " max " , number ) ;
nr_render ( m , f - > locale , buf , sizeof ( buf ) , f ) ;
2015-05-13 05:36:00 +02:00
paragraph ( out , buf , 2 , 2 , 0 ) ;
2014-08-17 00:14:50 +02:00
msg_release ( m ) ;
for ( itm = items ; itm ; itm = itm - > next ) {
sprintf ( buf , " %s: %d " ,
LOC ( f - > locale , resourcename ( itm - > type - > rtype , GR_PLURAL ) ) , itm - > number ) ;
2015-05-13 05:36:00 +02:00
paragraph ( out , buf , 2 , 2 , 0 ) ;
2014-08-17 00:14:50 +02:00
}
while ( items )
i_free ( i_remove ( & items , items ) ) ;
2010-08-08 10:06:34 +02:00
}
2015-05-13 05:36:00 +02:00
static void durchreisende ( stream * out , const region * r , const faction * f )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
if ( fval ( r , RF_TRAVELUNIT ) ) {
attrib * abegin = a_find ( r - > attribs , & at_travelunit ) , * a ;
int counter = 0 , maxtravel = 0 ;
char buf [ 8192 ] ;
char * bufp = buf ;
int bytes ;
size_t size = sizeof ( buf ) - 1 ;
/* How many are we listing? For grammar. */
for ( a = abegin ; a & & a - > type = = & at_travelunit ; a = a - > next ) {
unit * u = ( unit * ) a - > data . v ;
if ( r ! = u - > region & & ( ! u - > ship | | ship_owner ( u - > ship ) = = u ) ) {
if ( cansee_durchgezogen ( f , r , u , 0 ) ) {
+ + maxtravel ;
}
}
2010-08-08 10:06:34 +02:00
}
2014-08-17 00:14:50 +02:00
if ( maxtravel = = 0 ) {
return ;
}
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
/* Auflisten. */
2015-05-13 05:36:00 +02:00
newline ( out ) ;
2011-03-07 08:02:35 +01:00
2014-08-17 00:14:50 +02:00
for ( a = abegin ; a & & a - > type = = & at_travelunit ; a = a - > next ) {
unit * u = ( unit * ) a - > data . v ;
if ( r ! = u - > region & & ( ! u - > ship | | ship_owner ( u - > ship ) = = u ) ) {
if ( cansee_durchgezogen ( f , r , u , 0 ) ) {
+ + counter ;
if ( u - > ship ! = NULL ) {
2014-11-09 14:39:48 +01:00
# ifdef GERMAN_FLUFF_ENABLED
2015-01-30 20:43:40 +01:00
if ( strcmp ( " de " , f - > locale - > name ) = = 0 ) {
if ( counter = = 1 ) {
bytes = ( int ) strlcpy ( bufp , " Die " , size ) ;
}
else {
bytes = ( int ) strlcpy ( bufp , " die " , size ) ;
}
if ( wrptr ( & bufp , & size , bytes ) ! = 0 ) {
WARN_STATIC_BUFFER ( ) ;
break ;
}
2014-08-17 00:14:50 +02:00
}
2014-08-25 00:35:49 +02:00
# endif
2014-08-17 00:14:50 +02:00
bytes = ( int ) strlcpy ( bufp , shipname ( u - > ship ) , size ) ;
}
else {
bytes = ( int ) strlcpy ( bufp , unitname ( u ) , size ) ;
}
if ( wrptr ( & bufp , & size , bytes ) ! = 0 ) {
WARN_STATIC_BUFFER ( ) ;
break ;
}
if ( counter + 1 < maxtravel ) {
bytes = ( int ) strlcpy ( bufp , " , " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 ) {
WARN_STATIC_BUFFER ( ) ;
break ;
}
}
else if ( counter + 1 = = maxtravel ) {
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , " list_and " ) , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 ) {
WARN_STATIC_BUFFER ( ) ;
break ;
}
}
}
2010-08-08 10:06:34 +02:00
}
2014-08-16 03:07:37 +02:00
}
2014-08-17 00:14:50 +02:00
/* TODO: finish localization */
if ( size > 0 ) {
if ( maxtravel = = 1 ) {
bytes = _snprintf ( bufp , size , " %s " , LOC ( f - > locale , " has_moved_one " ) ) ;
}
else {
bytes = _snprintf ( bufp , size , " %s " , LOC ( f - > locale , " has_moved_many " ) ) ;
}
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2014-08-16 03:07:37 +02:00
}
2014-08-17 00:14:50 +02:00
* bufp = 0 ;
2015-05-13 05:36:00 +02:00
paragraph ( out , buf , 0 , 0 , 0 ) ;
2010-08-08 10:06:34 +02:00
}
}
2011-03-07 08:02:35 +01:00
static int buildingmaintenance ( const building * b , const resource_type * rtype )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
const building_type * bt = b - > type ;
int c , cost = 0 ;
static bool init = false ;
static const curse_type * nocost_ct ;
if ( ! init ) {
init = true ;
nocost_ct = ct_find ( " nocostbuilding " ) ;
}
if ( curse_active ( get_curse ( b - > attribs , nocost_ct ) ) ) {
return 0 ;
}
for ( c = 0 ; bt - > maintenance & & bt - > maintenance [ c ] . number ; + + c ) {
const maintenance * m = bt - > maintenance + c ;
if ( m - > rtype = = rtype ) {
if ( fval ( m , MTF_VARIABLE ) )
cost + = ( b - > size * m - > number ) ;
else
cost + = m - > number ;
}
2010-08-08 10:06:34 +02:00
}
2014-08-17 00:14:50 +02:00
return cost ;
2010-08-08 10:06:34 +02:00
}
static int
2011-03-07 08:02:35 +01:00
report_template ( const char * filename , report_context * ctx , const char * charset )
2010-08-08 10:06:34 +02:00
{
2014-06-24 16:42:45 +02:00
const resource_type * rsilver = get_resourcetype ( R_SILVER ) ;
2014-08-17 00:14:50 +02:00
faction * f = ctx - > f ;
region * r ;
FILE * F = fopen ( filename , " wt " ) ;
2015-05-13 05:36:00 +02:00
stream strm = { 0 } , * out = & strm ;
2014-08-17 00:14:50 +02:00
seen_region * sr = NULL ;
char buf [ 8192 ] , * bufp ;
size_t size ;
int bytes ;
bool utf8 = _strcmpl ( charset , " utf8 " ) = = 0 | | _strcmpl ( charset , " utf-8 " ) = = 0 ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
if ( F = = NULL ) {
perror ( filename ) ;
return - 1 ;
}
2015-05-13 05:36:00 +02:00
fstream_init ( & strm , F ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
if ( utf8 ) {
const unsigned char utf8_bom [ 4 ] = { 0xef , 0xbb , 0xbf , 0 } ;
2015-05-13 05:36:00 +02:00
swrite ( utf8_bom , 1 , 3 , out ) ;
2014-08-17 00:14:50 +02:00
}
2010-08-08 10:06:34 +02:00
2015-05-13 05:36:00 +02:00
newline ( out ) ;
rps_nowrap ( out , LOC ( f - > locale , " nr_template " ) ) ;
newline ( out ) ;
newline ( out ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
sprintf ( buf , " %s %s \" %s \" " , LOC ( f - > locale , " ERESSEA " ) , factionid ( f ) ,
LOC ( f - > locale , " enterpasswd " ) ) ;
2015-05-13 05:36:00 +02:00
rps_nowrap ( out , buf ) ;
newline ( out ) ;
newline ( out ) ;
2014-08-17 00:14:50 +02:00
sprintf ( buf , " ; ECHECK -l -w4 -r%d -v%s " , f - > race - > recruitcost ,
ECHECK_VERSION ) ;
/* -v3.4: ECheck Version 3.4.x */
2015-05-13 05:36:00 +02:00
rps_nowrap ( out , buf ) ;
newline ( out ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
for ( r = ctx - > first ; sr = = NULL & & r ! = ctx - > last ; r = r - > next ) {
sr = find_seen ( ctx - > seen , r ) ;
}
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
for ( ; sr ! = NULL ; sr = sr - > next ) {
region * r = sr - > r ;
unit * u ;
int dh = 0 ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
if ( sr - > mode < see_unit )
continue ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
for ( u = r - > units ; u ; u = u - > next ) {
if ( u - > faction = = f & & ! fval ( u_race ( u ) , RCF_INVISIBLE ) ) {
order * ord ;
if ( ! dh ) {
plane * pl = getplane ( r ) ;
int nx = r - > x , ny = r - > y ;
pnormalize ( & nx , & ny , pl ) ;
2015-05-19 08:02:32 +02:00
adjust_coordinates ( f , & nx , & ny , pl ) ;
2015-05-13 05:36:00 +02:00
newline ( out ) ;
2014-08-17 00:14:50 +02:00
if ( pl & & pl - > id ! = 0 ) {
sprintf ( buf , " %s %d,%d,%d ; %s " , LOC ( f - > locale ,
parameters [ P_REGION ] ) , nx , ny , pl - > id , rname ( r , f - > locale ) ) ;
}
else {
sprintf ( buf , " %s %d,%d ; %s " , LOC ( f - > locale , parameters [ P_REGION ] ) ,
nx , ny , rname ( r , f - > locale ) ) ;
}
2015-05-13 05:36:00 +02:00
rps_nowrap ( out , buf ) ;
newline ( out ) ;
2014-08-17 00:14:50 +02:00
sprintf ( buf , " ; ECheck Lohn %d " , wage ( r , f , f - > race , turn + 1 ) ) ;
2015-05-13 05:36:00 +02:00
rps_nowrap ( out , buf ) ;
newline ( out ) ;
newline ( out ) ;
2014-08-17 00:14:50 +02:00
}
dh = 1 ;
bufp = buf ;
size = sizeof ( buf ) - 1 ;
bytes = _snprintf ( bufp , size , " %s %s; %s [%d,%d$ " ,
LOC ( u - > faction - > locale , parameters [ P_UNIT ] ) ,
2015-02-11 07:55:35 +01:00
unitid ( u ) , unit_getname ( u ) , u - > number , get_money ( u ) ) ;
2014-08-17 00:14:50 +02:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
if ( u - > building & & building_owner ( u - > building ) = = u ) {
building * b = u - > building ;
int cost = buildingmaintenance ( b , rsilver ) ;
if ( cost > 0 ) {
bytes = ( int ) strlcpy ( bufp , " ,U " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) strlcpy ( bufp , itoa10 ( cost ) , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
}
else if ( u - > ship ) {
if ( ship_owner ( u - > ship ) = = u ) {
bytes = ( int ) strlcpy ( bufp , " ,S " , size ) ;
}
else {
bytes = ( int ) strlcpy ( bufp , " ,s " , size ) ;
}
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) strlcpy ( bufp , shipid ( u - > ship ) , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
if ( lifestyle ( u ) = = 0 ) {
bytes = ( int ) strlcpy ( bufp , " ,I " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
bytes = ( int ) strlcpy ( bufp , " ] " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
* bufp = 0 ;
2015-05-13 05:36:00 +02:00
rps_nowrap ( out , buf ) ;
newline ( out ) ;
2014-08-17 00:14:50 +02:00
for ( ord = u - > old_orders ; ord ; ord = ord - > next ) {
/* this new order will replace the old defaults */
strcpy ( buf , " " ) ;
write_order ( ord , buf + 2 , sizeof ( buf ) - 2 ) ;
2015-05-13 05:36:00 +02:00
rps_nowrap ( out , buf ) ;
newline ( out ) ;
2014-08-17 00:14:50 +02:00
}
for ( ord = u - > orders ; ord ; ord = ord - > next ) {
if ( u - > old_orders & & is_repeated ( ord ) )
continue ; /* unit has defaults */
if ( is_persistent ( ord ) ) {
strcpy ( buf , " " ) ;
write_order ( ord , buf + 2 , sizeof ( buf ) - 2 ) ;
2015-05-13 05:36:00 +02:00
rps_nowrap ( out , buf ) ;
newline ( out ) ;
2014-08-17 00:14:50 +02:00
}
}
/* If the lastorder begins with an @ it should have
* been printed in the loop before . */
}
2010-08-08 10:06:34 +02:00
}
}
2015-05-13 05:36:00 +02:00
newline ( out ) ;
2014-08-17 00:14:50 +02:00
strcpy ( buf , LOC ( f - > locale , parameters [ P_NEXT ] ) ) ;
2015-05-13 05:36:00 +02:00
rps_nowrap ( out , buf ) ;
newline ( out ) ;
fstream_done ( & strm ) ;
2014-08-17 00:14:50 +02:00
return 0 ;
2010-08-08 10:06:34 +02:00
}
static void
2011-03-07 08:02:35 +01:00
show_allies ( const faction * f , const ally * allies , char * buf , size_t size )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
int allierte = 0 ;
int i = 0 , h , hh = 0 ;
int bytes , dh = 0 ;
const ally * sf ;
char * bufp = buf ; /* buf already contains data */
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
- - size ; /* leave room for a null-terminator */
for ( sf = allies ; sf ; sf = sf - > next ) {
int mode = alliedgroup ( NULL , f , sf - > faction , sf , HELP_ALL ) ;
if ( mode > 0 )
+ + allierte ;
2010-08-08 10:06:34 +02:00
}
2014-08-17 00:14:50 +02:00
for ( sf = allies ; sf ; sf = sf - > next ) {
int mode = alliedgroup ( NULL , f , sf - > faction , sf , HELP_ALL ) ;
if ( mode < = 0 )
continue ;
i + + ;
if ( dh ) {
if ( i = = allierte ) {
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , " list_and " ) , size ) ;
}
else {
bytes = ( int ) strlcpy ( bufp , " , " , size ) ;
}
2011-03-07 08:02:35 +01:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2014-08-17 00:14:50 +02:00
WARN_STATIC_BUFFER ( ) ;
}
dh = 1 ;
hh = 0 ;
bytes = ( int ) strlcpy ( bufp , factionname ( sf - > faction ) , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) strlcpy ( bufp , " ( " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2011-03-07 08:02:35 +01:00
WARN_STATIC_BUFFER ( ) ;
2014-08-17 00:14:50 +02:00
if ( ( mode & HELP_ALL ) = = HELP_ALL ) {
2015-01-08 20:55:29 +01:00
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , parameters [ P_ANY ] ) , size ) ;
2014-08-17 00:14:50 +02:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2010-08-08 10:06:34 +02:00
}
2014-08-17 00:14:50 +02:00
else {
for ( h = 1 ; h < HELP_ALL ; h * = 2 ) {
int p = MAXPARAMS ;
if ( ( mode & h ) = = h ) {
switch ( h ) {
case HELP_TRAVEL :
p = P_TRAVEL ;
break ;
case HELP_MONEY :
p = P_MONEY ;
break ;
case HELP_FIGHT :
p = P_FIGHT ;
break ;
case HELP_GIVE :
p = P_GIVE ;
break ;
case HELP_GUARD :
p = P_GUARD ;
break ;
case HELP_FSTEALTH :
p = P_FACTIONSTEALTH ;
break ;
}
}
if ( p ! = MAXPARAMS ) {
if ( hh ) {
bytes = ( int ) strlcpy ( bufp , " , " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
2015-01-08 20:55:29 +01:00
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , parameters [ p ] ) , size ) ;
2014-08-17 00:14:50 +02:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
hh = 1 ;
}
}
}
bytes = ( int ) strlcpy ( bufp , " ) " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2010-08-08 10:06:34 +02:00
}
2014-08-17 00:14:50 +02:00
bytes = ( int ) strlcpy ( bufp , " . " , size ) ;
2011-03-07 08:02:35 +01:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2014-08-17 00:14:50 +02:00
WARN_STATIC_BUFFER ( ) ;
* bufp = 0 ;
2010-08-08 10:06:34 +02:00
}
2015-05-13 05:36:00 +02:00
static void allies ( stream * out , const faction * f )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
const group * g = f - > groups ;
char buf [ 16384 ] ;
if ( f - > allies ) {
int bytes ;
size_t size = sizeof ( buf ) ;
bytes = _snprintf ( buf , size , " %s " , LOC ( f - > locale , " faction_help " ) ) ;
size - = bytes ;
show_allies ( f , f - > allies , buf + bytes , size ) ;
2015-05-13 05:36:00 +02:00
paragraph ( out , buf , 0 , 0 , 0 ) ;
newline ( out ) ;
2010-08-08 10:06:34 +02:00
}
2014-08-17 00:14:50 +02:00
while ( g ) {
if ( g - > allies ) {
int bytes ;
size_t size = sizeof ( buf ) ;
bytes = _snprintf ( buf , size , " %s %s " , g - > name , LOC ( f - > locale , " group_help " ) ) ;
size - = bytes ;
show_allies ( f , g - > allies , buf + bytes , size ) ;
2015-05-13 05:36:00 +02:00
paragraph ( out , buf , 0 , 0 , 0 ) ;
newline ( out ) ;
2014-08-17 00:14:50 +02:00
}
g = g - > next ;
2010-08-08 10:06:34 +02:00
}
}
2015-05-13 05:36:00 +02:00
static void guards ( stream * out , const region * r , const faction * see )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
/* die Partei see sieht dies; wegen
* " unbekannte Partei " , wenn man es selbst ist . . . */
faction * guardians [ 512 ] ;
int nextguard = 0 ;
unit * u ;
int i ;
bool tarned = false ;
/* Bewachung */
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
for ( u = r - > units ; u ; u = u - > next ) {
if ( is_guard ( u , GUARD_ALL ) ! = 0 ) {
faction * f = u - > faction ;
faction * fv = visible_faction ( see , u ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
if ( fv ! = f & & see ! = fv ) {
f = fv ;
}
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
if ( f ! = see & & fval ( u , UFL_ANON_FACTION ) ) {
tarned = true ;
}
else {
for ( i = 0 ; i ! = nextguard ; + + i )
if ( guardians [ i ] = = f )
break ;
if ( i = = nextguard ) {
guardians [ nextguard + + ] = f ;
}
}
2010-08-08 10:06:34 +02:00
}
}
2014-08-17 00:14:50 +02:00
if ( nextguard | | tarned ) {
char buf [ 8192 ] ;
char * bufp = buf ;
size_t size = sizeof ( buf ) - 1 ;
int bytes ;
2011-03-07 08:02:35 +01:00
2015-01-14 16:13:08 +01:00
bytes = ( int ) strlcpy ( bufp , LOC ( see - > locale , " nr_guarding_prefix " ) , size ) ;
2014-08-17 00:14:50 +02:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
for ( i = 0 ; i ! = nextguard + ( tarned ? 1 : 0 ) ; + + i ) {
if ( i ! = 0 ) {
if ( i = = nextguard - ( tarned ? 0 : 1 ) ) {
bytes = ( int ) strlcpy ( bufp , LOC ( see - > locale , " list_and " ) , size ) ;
}
else {
bytes = ( int ) strlcpy ( bufp , " , " , size ) ;
}
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
if ( i < nextguard ) {
bytes = ( int ) strlcpy ( bufp , factionname ( guardians [ i ] ) , size ) ;
}
else {
2015-01-14 16:13:08 +01:00
bytes = ( int ) strlcpy ( bufp , LOC ( see - > locale , " nr_guarding_unknown " ) , size ) ;
2014-08-17 00:14:50 +02:00
}
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2010-08-08 10:06:34 +02:00
}
2015-01-14 16:13:08 +01:00
bytes = ( int ) strlcpy ( bufp , LOC ( see - > locale , " nr_guarding_postfix " ) , size ) ;
2011-03-07 08:02:35 +01:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2014-08-17 00:14:50 +02:00
WARN_STATIC_BUFFER ( ) ;
2015-05-13 05:36:00 +02:00
newline ( out ) ;
2014-08-17 00:14:50 +02:00
* bufp = 0 ;
2015-05-13 05:36:00 +02:00
paragraph ( out , buf , 0 , 0 , 0 ) ;
2010-08-08 10:06:34 +02:00
}
}
2015-05-13 05:36:00 +02:00
static void rpline ( stream * out )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
static char line [ REPORTWIDTH + 1 ] ;
if ( line [ 0 ] ! = ' - ' ) {
memset ( line , ' - ' , sizeof ( line ) ) ;
line [ REPORTWIDTH ] = ' \n ' ;
}
2015-05-13 05:36:00 +02:00
swrite ( line , sizeof ( char ) , sizeof ( line ) , out ) ;
2014-08-17 00:14:50 +02:00
}
2015-05-13 05:36:00 +02:00
static void list_address ( stream * out , const faction * uf , quicklist * seenfactions )
2014-08-17 00:14:50 +02:00
{
int qi = 0 ;
quicklist * flist = seenfactions ;
2015-05-13 05:36:00 +02:00
centre ( out , LOC ( uf - > locale , " nr_addresses " ) , false ) ;
newline ( out ) ;
2014-08-17 00:14:50 +02:00
while ( flist ! = NULL ) {
const faction * f = ( const faction * ) ql_get ( flist , qi ) ;
if ( ! is_monsters ( f ) ) {
char buf [ 8192 ] ;
char label = ' - ' ;
sprintf ( buf , " %s: %s; %s " , factionname ( f ) , f - > email ,
f - > banner ? f - > banner : " " ) ;
if ( uf = = f )
label = ' * ' ;
2014-12-09 14:14:35 +01:00
else if ( is_allied ( uf , f ) )
2014-08-17 00:14:50 +02:00
label = ' o ' ;
else if ( alliedfaction ( NULL , uf , f , HELP_ALL ) )
label = ' + ' ;
2015-05-13 05:36:00 +02:00
paragraph ( out , buf , 4 , 0 , label ) ;
2014-08-17 00:14:50 +02:00
}
ql_advance ( & flist , & qi , 1 ) ;
}
2015-05-13 05:36:00 +02:00
newline ( out ) ;
rpline ( out ) ;
2014-08-17 00:14:50 +02:00
}
static void
2015-05-13 04:25:50 +02:00
nr_ship ( stream * out , const seen_region * sr , const ship * sh , const faction * f ,
2014-08-17 00:14:50 +02:00
const unit * captain )
{
const region * r = sr - > r ;
char buffer [ 8192 ] , * bufp = buffer ;
size_t size = sizeof ( buffer ) - 1 ;
int bytes ;
char ch ;
2015-05-13 04:57:08 +02:00
newline ( out ) ;
2014-08-17 00:14:50 +02:00
if ( captain & & captain - > faction = = f ) {
int n = 0 , p = 0 ;
getshipweight ( sh , & n , & p ) ;
n = ( n + 99 ) / 100 ; /* 1 Silber = 1 GE */
bytes = _snprintf ( bufp , size , " %s, %s, (%d/%d) " , shipname ( sh ) ,
LOC ( f - > locale , sh - > type - > _name ) , n , shipcapacity ( sh ) / 100 ) ;
}
else {
bytes =
_snprintf ( bufp , size , " %s, %s " , shipname ( sh ) , LOC ( f - > locale ,
sh - > type - > _name ) ) ;
}
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
assert ( sh - > type - > construction - > improvement = = NULL ) ; /* sonst ist construction::size nicht ship_type::maxsize */
if ( sh - > size ! = sh - > type - > construction - > maxsize ) {
bytes = _snprintf ( bufp , size , " , %s (%d/%d) " ,
LOC ( f - > locale , " nr_undercons " ) , sh - > size ,
sh - > type - > construction - > maxsize ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
if ( sh - > damage ) {
int percent =
( sh - > damage * 100 + DAMAGE_SCALE - 1 ) / ( sh - > size * DAMAGE_SCALE ) ;
bytes =
_snprintf ( bufp , size , " , %d%% %s " , percent , LOC ( f - > locale , " nr_damaged " ) ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
if ( ! fval ( r - > terrain , SEA_REGION ) ) {
if ( sh - > coast ! = NODIRECTION ) {
bytes = ( int ) strlcpy ( bufp , " , " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , coasts [ sh - > coast ] ) , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
}
ch = 0 ;
if ( sh - > display & & sh - > display [ 0 ] ) {
bytes = ( int ) strlcpy ( bufp , " ; " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) strlcpy ( bufp , sh - > display , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
ch = sh - > display [ strlen ( sh - > display ) - 1 ] ;
}
if ( ch ! = ' ! ' & & ch ! = ' ? ' & & ch ! = ' . ' ) {
bytes = ( int ) strlcpy ( bufp , " . " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
* bufp = 0 ;
2015-05-13 04:57:08 +02:00
paragraph ( out , buffer , 2 , 0 , 0 ) ;
2014-08-17 00:14:50 +02:00
2015-05-13 04:25:50 +02:00
nr_curses ( out , 4 , f , TYP_SHIP , sh ) ;
2010-08-08 10:06:34 +02:00
}
2014-08-17 00:14:50 +02:00
static void
2015-05-13 04:25:50 +02:00
nr_building ( stream * out , const seen_region * sr , const building * b ,
2014-08-17 00:14:50 +02:00
const faction * f )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
int i , bytes ;
const char * name , * bname , * billusion = NULL ;
const struct locale * lang = NULL ;
char buffer [ 8192 ] , * bufp = buffer ;
2015-01-14 16:13:08 +01:00
message * msg ;
2014-08-17 00:14:50 +02:00
size_t size = sizeof ( buffer ) - 1 ;
2010-08-08 10:06:34 +02:00
2015-05-13 04:57:08 +02:00
newline ( out ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
if ( f )
lang = f - > locale ;
2010-08-08 10:06:34 +02:00
2011-03-07 08:02:35 +01:00
bytes =
2014-08-17 00:14:50 +02:00
_snprintf ( bufp , size , " %s, %s %d, " , buildingname ( b ) , LOC ( f - > locale ,
" nr_size " ) , b - > size ) ;
2011-03-07 08:02:35 +01:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
report_building ( b , & bname , & billusion ) ;
name = LOC ( lang , billusion ? billusion : bname ) ;
bytes = ( int ) strlcpy ( bufp , name , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
2011-03-07 08:02:35 +01:00
WARN_STATIC_BUFFER ( ) ;
2014-08-17 00:14:50 +02:00
if ( billusion ) {
unit * owner = building_owner ( b ) ;
if ( owner & & owner - > faction = = f ) {
/* illusion. report real type */
name = LOC ( lang , bname ) ;
bytes = _snprintf ( bufp , size , " (%s) " , name ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
2010-08-08 10:06:34 +02:00
}
2014-08-17 00:14:50 +02:00
if ( b - > size < b - > type - > maxsize ) {
2015-01-14 16:13:08 +01:00
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , " nr_building_inprogress " ) , size ) ;
2014-08-17 00:14:50 +02:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
if ( b - > besieged > 0 & & sr - > mode > = see_lighthouse ) {
2015-01-30 20:43:40 +01:00
msg = msg_message ( " nr_building_besieged " , " soldiers diff " , b - > besieged ,
b - > besieged - b - > size * SIEGEFACTOR ) ;
bytes = ( int ) nr_render ( msg , f - > locale , bufp , size , f ) ;
2014-08-17 00:14:50 +02:00
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
2015-01-30 20:43:40 +01:00
msg_release ( msg ) ;
2014-08-17 00:14:50 +02:00
}
i = 0 ;
if ( b - > display & & b - > display [ 0 ] ) {
bytes = ( int ) strlcpy ( bufp , " ; " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) strlcpy ( bufp , b - > display , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
i = b - > display [ strlen ( b - > display ) - 1 ] ;
2010-08-08 10:06:34 +02:00
}
2014-08-17 00:14:50 +02:00
if ( i ! = ' ! ' & & i ! = ' ? ' & & i ! = ' . ' ) {
bytes = ( int ) strlcpy ( bufp , " . " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
* bufp = 0 ;
2015-05-13 04:57:08 +02:00
paragraph ( out , buffer , 2 , 0 , 0 ) ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
if ( sr - > mode < see_lighthouse )
return ;
2010-08-08 10:06:34 +02:00
2015-05-13 04:25:50 +02:00
i = 0 ;
nr_curses ( out , 4 , f , TYP_BUILDING , b ) ;
2010-08-08 10:06:34 +02:00
}
2015-05-13 04:57:08 +02:00
static void nr_paragraph ( stream * out , message * m , faction * f )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
int bytes ;
char buf [ 4096 ] , * bufp = buf ;
size_t size = sizeof ( buf ) - 1 ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
bytes = ( int ) nr_render ( m , f - > locale , bufp , size , f ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
msg_release ( m ) ;
2010-08-08 10:06:34 +02:00
2015-05-13 05:36:00 +02:00
paragraph ( out , buf , 0 , 0 , 0 ) ;
2010-08-08 10:06:34 +02:00
}
int
2011-03-07 08:02:35 +01:00
report_plaintext ( const char * filename , report_context * ctx ,
2014-08-17 00:14:50 +02:00
const char * charset )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
int flag = 0 ;
char ch ;
int anyunits , no_units , no_people ;
const struct region * r ;
faction * f = ctx - > f ;
unit * u ;
char pzTime [ 64 ] ;
attrib * a ;
message * m ;
unsigned char op ;
2015-05-13 04:25:50 +02:00
int maxh , bytes , ix = want ( O_STATISTICS ) ;
2014-08-17 00:14:50 +02:00
int wants_stats = ( f - > options & ix ) ;
FILE * F = fopen ( filename , " wt " ) ;
2015-05-13 05:36:00 +02:00
stream strm = { 0 } , * out = & strm ;
2014-08-17 00:14:50 +02:00
seen_region * sr = NULL ;
char buf [ 8192 ] ;
char * bufp ;
bool utf8 = _strcmpl ( charset , " utf8 " ) = = 0 | | _strcmpl ( charset , " utf-8 " ) = = 0 ;
size_t size ;
/* static variables can cope with writing for different turns */
static int thisseason = - 1 ;
static int nextseason = - 1 ;
static int gamecookie = - 1 ;
if ( gamecookie ! = global . cookie ) {
gamedate date ;
get_gamedate ( turn + 1 , & date ) ;
thisseason = date . season ;
get_gamedate ( turn + 2 , & date ) ;
nextseason = date . season ;
gamecookie = global . cookie ;
}
if ( F = = NULL ) {
perror ( filename ) ;
return - 1 ;
}
2015-05-13 05:36:00 +02:00
fstream_init ( & strm , F ) ;
2015-05-13 04:25:50 +02:00
2014-08-17 00:14:50 +02:00
if ( utf8 ) {
const unsigned char utf8_bom [ 4 ] = { 0xef , 0xbb , 0xbf , 0 } ;
fwrite ( utf8_bom , 1 , 3 , F ) ;
}
strftime ( pzTime , 64 , " %A, %d. %B %Y, %H:%M " , localtime ( & ctx - > report_time ) ) ;
m = msg_message ( " nr_header_date " , " game date " , game_name ( ) , pzTime ) ;
nr_render ( m , f - > locale , buf , sizeof ( buf ) , f ) ;
msg_release ( m ) ;
2015-05-13 05:36:00 +02:00
centre ( out , buf , true ) ;
2010-08-08 10:06:34 +02:00
2015-05-13 05:36:00 +02:00
centre ( out , gamedate_season ( f - > locale ) , true ) ;
newline ( out ) ;
2014-08-17 00:14:50 +02:00
sprintf ( buf , " %s, %s/%s (%s) " , factionname ( f ) ,
2014-12-09 07:20:36 +01:00
LOC ( f - > locale , rc_name_s ( f - > race , NAME_PLURAL ) ) ,
2014-08-17 00:14:50 +02:00
LOC ( f - > locale , mkname ( " school " , magic_school [ f - > magiegebiet ] ) ) , f - > email ) ;
2015-05-13 05:36:00 +02:00
centre ( out , buf , true ) ;
2014-08-17 00:14:50 +02:00
if ( f_get_alliance ( f ) ) {
2015-05-13 05:36:00 +02:00
centre ( out , alliancename ( f - > alliance ) , true ) ;
2014-08-17 00:14:50 +02:00
}
if ( f - > age < = 2 ) {
const char * s ;
if ( f - > age < = 1 ) {
ADDMSG ( & f - > msgs , msg_message ( " changepasswd " , " value " , f - > passw ) ) ;
}
RENDER ( f , buf , sizeof ( buf ) , ( " newbie_password " , " password " , f - > passw ) ) ;
2015-05-13 05:36:00 +02:00
newline ( out ) ;
centre ( out , buf , true ) ;
2014-08-17 00:14:50 +02:00
s = locale_getstring ( f - > locale , " newbie_info_1 " ) ;
if ( s ) {
2015-05-13 05:36:00 +02:00
newline ( out ) ;
centre ( out , s , true ) ;
2014-08-17 00:14:50 +02:00
}
s = locale_getstring ( f - > locale , " newbie_info_2 " ) ;
if ( s ) {
2015-05-13 05:36:00 +02:00
newline ( out ) ;
centre ( out , s , true ) ;
2014-08-17 00:14:50 +02:00
}
if ( ( f - > options & want ( O_COMPUTER ) ) = = 0 ) {
f - > options | = want ( O_COMPUTER ) ;
s = locale_getstring ( f - > locale , " newbie_info_3 " ) ;
if ( s ) {
2015-05-13 05:36:00 +02:00
newline ( out ) ;
centre ( out , s , true ) ;
2014-08-17 00:14:50 +02:00
}
}
2010-08-08 10:06:34 +02:00
}
2015-05-13 05:36:00 +02:00
newline ( out ) ;
2010-08-08 10:06:34 +02:00
# if SCORE_MODULE
2014-08-17 00:14:50 +02:00
if ( f - > options & want ( O_SCORE ) & & f - > age > DISPLAYSCORE ) {
RENDER ( f , buf , sizeof ( buf ) , ( " nr_score " , " score average " , f - > score ,
average_score_of_age ( f - > age , f - > age / 24 + 1 ) ) ) ;
2015-05-13 05:36:00 +02:00
centre ( out , buf , true ) ;
2014-08-17 00:14:50 +02:00
}
2010-08-08 10:06:34 +02:00
# endif
# ifdef COUNT_AGAIN
2014-08-17 00:14:50 +02:00
no_units = 0 ;
no_people = 0 ;
for ( u = f - > units ; u ; u = u - > nextF ) {
if ( playerrace ( u_race ( u ) ) ) {
+ + no_people ;
no_units + = u - > number ;
assert ( f = = u - > faction ) ;
}
}
if ( no_units ! = f - > no_units ) {
f - > no_units = no_units ;
}
if ( no_people ! = f - > num_people ) {
f - > num_people = no_people ;
2010-08-08 10:06:34 +02:00
}
# else
2014-08-17 00:14:50 +02:00
no_units = count_units ( f ) ;
no_people = count_all ( f ) ;
if ( f - > flags & FFL_NPC ) {
no_people = f - > num_total ;
2010-08-08 10:06:34 +02:00
}
2014-08-17 00:14:50 +02:00
else {
no_people = f - > num_people ;
}
# endif
2014-12-19 19:57:24 +01:00
m = msg_message ( " nr_population " , " population units limit " , no_people , no_units , rule_faction_limit ( ) ) ;
2010-08-08 10:06:34 +02:00
nr_render ( m , f - > locale , buf , sizeof ( buf ) , f ) ;
msg_release ( m ) ;
2015-05-13 05:36:00 +02:00
centre ( out , buf , true ) ;
2014-08-17 00:14:50 +02:00
if ( f - > race = = get_race ( RC_HUMAN ) ) {
int maxmig = count_maxmigrants ( f ) ;
if ( maxmig > 0 ) {
m =
msg_message ( " nr_migrants " , " units maxunits " , count_migrants ( f ) , maxmig ) ;
nr_render ( m , f - > locale , buf , sizeof ( buf ) , f ) ;
msg_release ( m ) ;
2015-05-13 05:36:00 +02:00
centre ( out , buf , true ) ;
2014-08-17 00:14:50 +02:00
}
2010-08-08 10:06:34 +02:00
}
2014-08-17 00:14:50 +02:00
if ( f_get_alliance ( f ) ) {
m =
msg_message ( " nr_alliance " , " leader name id age " ,
alliance_get_leader ( f - > alliance ) , f - > alliance - > name , f - > alliance - > id ,
turn - f - > alliance_joindate ) ;
nr_render ( m , f - > locale , buf , sizeof ( buf ) , f ) ;
msg_release ( m ) ;
2015-05-13 05:36:00 +02:00
centre ( out , buf , true ) ;
2014-08-17 00:14:50 +02:00
}
2015-05-13 04:25:50 +02:00
maxh = maxheroes ( f ) ;
if ( maxh ) {
message * msg =
msg_message ( " nr_heroes " , " units maxunits " , countheroes ( f ) , maxh ) ;
nr_render ( msg , f - > locale , buf , sizeof ( buf ) , f ) ;
msg_release ( msg ) ;
2015-05-13 05:36:00 +02:00
centre ( out , buf , true ) ;
2015-05-13 04:25:50 +02:00
}
if ( f - > items ! = NULL ) {
message * msg = msg_message ( " nr_claims " , " items " , f - > items ) ;
nr_render ( msg , f - > locale , buf , sizeof ( buf ) , f ) ;
msg_release ( msg ) ;
2015-05-13 05:36:00 +02:00
newline ( out ) ;
centre ( out , buf , true ) ;
2015-05-13 04:25:50 +02:00
}
/* Insekten-Winter-Warnung */
if ( f - > race = = get_race ( RC_INSECT ) ) {
if ( thisseason = = 0 ) {
2015-05-13 05:36:00 +02:00
centre ( out , LOC ( f - > locale , " nr_insectwinter " ) , true ) ;
newline ( out ) ;
2015-05-13 04:25:50 +02:00
}
else {
if ( nextseason = = 0 ) {
2015-05-13 05:36:00 +02:00
centre ( out , LOC ( f - > locale , " nr_insectfall " ) , true ) ;
newline ( out ) ;
2015-05-13 04:25:50 +02:00
}
}
}
bufp = buf ;
size = sizeof ( buf ) - 1 ;
bytes = _snprintf ( buf , size , " %s: " , LOC ( f - > locale , " nr_options " ) ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
for ( op = 0 ; op ! = MAXOPTIONS ; op + + ) {
if ( f - > options & want ( op ) & & options [ op ] ) {
bytes = ( int ) strlcpy ( bufp , " " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
bytes = ( int ) strlcpy ( bufp , LOC ( f - > locale , options [ op ] ) , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
flag + + ;
}
}
if ( flag > 0 ) {
2015-05-13 05:36:00 +02:00
newline ( out ) ;
2015-05-13 04:25:50 +02:00
* bufp = 0 ;
2015-05-13 05:36:00 +02:00
centre ( out , buf , true ) ;
2015-05-13 04:25:50 +02:00
}
2015-05-13 05:36:00 +02:00
rp_messages ( out , f - > msgs , f , 0 , true ) ;
rp_battles ( out , f ) ;
2015-05-13 04:25:50 +02:00
a = a_find ( f - > attribs , & at_reportspell ) ;
if ( a ) {
2015-05-13 05:36:00 +02:00
newline ( out ) ;
centre ( out , LOC ( f - > locale , " section_newspells " ) , true ) ;
2015-05-13 04:25:50 +02:00
while ( a & & a - > type = = & at_reportspell ) {
spellbook_entry * sbe = ( spellbook_entry * ) a - > data . v ;
2015-05-13 05:36:00 +02:00
nr_spell ( out , sbe , f - > locale ) ;
2015-05-13 04:25:50 +02:00
a = a - > next ;
}
}
ch = 0 ;
for ( a = a_find ( f - > attribs , & at_showitem ) ; a & & a - > type = = & at_showitem ;
a = a - > next ) {
const potion_type * ptype =
resource2potion ( ( ( const item_type * ) a - > data . v ) - > rtype ) ;
const char * description = NULL ;
if ( ptype ! = NULL ) {
const char * pname = resourcename ( ptype - > itype - > rtype , 0 ) ;
if ( ch = = 0 ) {
2015-05-13 05:36:00 +02:00
newline ( out ) ;
centre ( out , LOC ( f - > locale , " section_newpotions " ) , true ) ;
2015-05-13 04:25:50 +02:00
ch = 1 ;
}
2015-05-13 05:36:00 +02:00
newline ( out ) ;
centre ( out , LOC ( f - > locale , pname ) , true ) ;
2015-05-13 04:25:50 +02:00
_snprintf ( buf , sizeof ( buf ) , " %s %d " , LOC ( f - > locale , " nr_level " ) ,
ptype - > level ) ;
2015-05-13 05:36:00 +02:00
centre ( out , buf , true ) ;
newline ( out ) ;
2015-05-13 04:25:50 +02:00
bufp = buf ;
size = sizeof ( buf ) - 1 ;
bytes = _snprintf ( bufp , size , " %s: " , LOC ( f - > locale , " nr_herbsrequired " ) ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
if ( ptype - > itype - > construction ) {
requirement * m = ptype - > itype - > construction - > materials ;
while ( m - > number ) {
bytes =
( int ) strlcpy ( bufp , LOC ( f - > locale , resourcename ( m - > rtype , 0 ) ) , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
+ + m ;
if ( m - > number )
bytes = ( int ) strlcpy ( bufp , " , " , size ) ;
if ( wrptr ( & bufp , & size , bytes ) ! = 0 )
WARN_STATIC_BUFFER ( ) ;
}
}
* bufp = 0 ;
2015-05-13 05:36:00 +02:00
centre ( out , buf , true ) ;
newline ( out ) ;
2015-05-13 04:25:50 +02:00
if ( description = = NULL ) {
const char * potiontext = mkname ( " potion " , pname ) ;
description = LOC ( f - > locale , potiontext ) ;
}
2015-05-13 05:36:00 +02:00
centre ( out , description , true ) ;
2015-05-13 04:25:50 +02:00
}
}
2015-05-13 05:36:00 +02:00
newline ( out ) ;
centre ( out , LOC ( f - > locale , " nr_alliances " ) , false ) ;
newline ( out ) ;
2015-05-13 04:25:50 +02:00
2015-05-13 05:36:00 +02:00
allies ( out , f ) ;
2015-05-13 04:25:50 +02:00
2015-05-13 05:36:00 +02:00
rpline ( out ) ;
2015-05-13 04:25:50 +02:00
anyunits = 0 ;
for ( r = ctx - > first ; sr = = NULL & & r ! = ctx - > last ; r = r - > next ) {
sr = find_seen ( ctx - > seen , r ) ;
}
for ( ; sr ! = NULL ; sr = sr - > next ) {
region * r = sr - > r ;
int stealthmod = stealth_modifier ( sr - > mode ) ;
building * b = r - > buildings ;
ship * sh = r - > ships ;
if ( sr - > mode < see_lighthouse )
continue ;
/* Beschreibung */
if ( sr - > mode = = see_unit ) {
anyunits = 1 ;
2015-05-13 05:36:00 +02:00
describe ( out , sr , f ) ;
2015-05-13 04:25:50 +02:00
if ( markets_module ( ) & & r - > land ) {
const item_type * lux = r_luxury ( r ) ;
const item_type * herb = r - > land - > herbtype ;
message * m = 0 ;
if ( herb & & lux ) {
m = msg_message ( " nr_market_info_p " , " p1 p2 " ,
lux ? lux - > rtype : 0 , herb ? herb - > rtype : 0 ) ;
}
else if ( lux | | herb ) {
m = msg_message ( " nr_market_info_s " , " p1 " ,
lux ? lux - > rtype : herb - > rtype ) ;
}
if ( m ) {
2015-05-13 05:36:00 +02:00
newline ( out ) ;
nr_paragraph ( out , m , f ) ;
2015-05-13 04:25:50 +02:00
}
/* */
}
else {
if ( ! fval ( r - > terrain , SEA_REGION ) & & rpeasants ( r ) / TRADE_FRACTION > 0 ) {
2015-05-13 05:36:00 +02:00
newline ( out ) ;
prices ( out , r , f ) ;
2015-05-13 04:25:50 +02:00
}
}
2015-05-13 05:36:00 +02:00
guards ( out , r , f ) ;
durchreisende ( out , r , f ) ;
2015-05-13 04:25:50 +02:00
}
else {
if ( sr - > mode = = see_far ) {
2015-05-13 05:36:00 +02:00
describe ( out , sr , f ) ;
guards ( out , r , f ) ;
durchreisende ( out , r , f ) ;
2015-05-13 04:25:50 +02:00
}
else if ( sr - > mode = = see_lighthouse ) {
2015-05-13 05:36:00 +02:00
describe ( out , sr , f ) ;
durchreisende ( out , r , f ) ;
2015-05-13 04:25:50 +02:00
}
else {
2015-05-13 05:36:00 +02:00
describe ( out , sr , f ) ;
durchreisende ( out , r , f ) ;
2015-05-13 04:25:50 +02:00
}
}
/* Statistik */
if ( wants_stats & & sr - > mode = = see_unit )
2015-05-13 05:36:00 +02:00
statistics ( out , r , f ) ;
2015-05-13 04:25:50 +02:00
/* Nachrichten an REGION in der Region */
if ( sr - > mode = = see_unit | | sr - > mode = = see_travel ) {
// TODO: Bug 2073
message_list * mlist = r_getmessages ( r , f ) ;
2015-05-13 05:36:00 +02:00
rp_messages ( out , r - > msgs , f , 0 , true ) ;
2015-05-13 04:25:50 +02:00
if ( mlist )
2015-05-13 05:36:00 +02:00
rp_messages ( out , mlist , f , 0 , true ) ;
2015-05-13 04:25:50 +02:00
}
/* report all units. they are pre-sorted in an efficient manner */
u = r - > units ;
while ( b ) {
while ( b & & ( ! u | | u - > building ! = b ) ) {
2015-05-13 05:36:00 +02:00
nr_building ( out , sr , b , f ) ;
2015-05-13 04:25:50 +02:00
b = b - > next ;
}
if ( b ) {
2015-05-13 05:36:00 +02:00
nr_building ( out , sr , b , f ) ;
2015-05-13 04:25:50 +02:00
while ( u & & u - > building = = b ) {
2015-05-13 05:36:00 +02:00
nr_unit ( out , f , u , 6 , sr - > mode ) ;
2015-05-13 04:25:50 +02:00
u = u - > next ;
}
b = b - > next ;
}
}
while ( u & & ! u - > ship ) {
if ( stealthmod > INT_MIN ) {
if ( u - > faction = = f | | cansee ( f , r , u , stealthmod ) ) {
2015-05-13 05:36:00 +02:00
nr_unit ( out , f , u , 4 , sr - > mode ) ;
2015-05-13 04:25:50 +02:00
}
}
assert ( ! u - > building ) ;
u = u - > next ;
}
while ( sh ) {
while ( sh & & ( ! u | | u - > ship ! = sh ) ) {
2015-05-13 05:36:00 +02:00
nr_ship ( out , sr , sh , f , NULL ) ;
2015-05-13 04:25:50 +02:00
sh = sh - > next ;
}
if ( sh ) {
2015-05-13 05:36:00 +02:00
nr_ship ( out , sr , sh , f , u ) ;
2015-05-13 04:25:50 +02:00
while ( u & & u - > ship = = sh ) {
2015-05-13 05:36:00 +02:00
nr_unit ( out , f , u , 6 , sr - > mode ) ;
2015-05-13 04:25:50 +02:00
u = u - > next ;
}
sh = sh - > next ;
}
}
assert ( ! u ) ;
2015-05-13 05:36:00 +02:00
newline ( out ) ;
rpline ( out ) ;
2015-05-13 04:25:50 +02:00
}
if ( ! is_monsters ( f ) ) {
if ( ! anyunits ) {
2015-05-13 05:36:00 +02:00
newline ( out ) ;
paragraph ( out , LOC ( f - > locale , " nr_youaredead " ) , 0 , 2 , 0 ) ;
2015-05-13 04:25:50 +02:00
}
else {
2015-05-13 05:36:00 +02:00
list_address ( out , f , ctx - > addresses ) ;
2015-05-13 04:25:50 +02:00
}
}
2015-05-13 05:36:00 +02:00
fstream_done ( & strm ) ;
2015-05-13 04:25:50 +02:00
return 0 ;
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
void base36conversion ( void )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
region * r ;
for ( r = regions ; r ; r = r - > next ) {
unit * u ;
for ( u = r - > units ; u ; u = u - > next ) {
if ( forbiddenid ( u - > no ) ) {
uunhash ( u ) ;
u - > no = newunitid ( ) ;
uhash ( u ) ;
}
}
2010-08-08 10:06:34 +02:00
}
}
# define FMAXHASH 1021
struct fsee {
2014-08-17 00:14:50 +02:00
struct fsee * nexthash ;
faction * f ;
struct see {
struct see * next ;
faction * seen ;
unit * proof ;
} * see ;
2011-03-07 08:02:35 +01:00
} * fsee [ FMAXHASH ] ;
2010-08-08 10:06:34 +02:00
# define REPORT_NR (1 << O_REPORT)
# define REPORT_CR (1 << O_COMPUTER)
# define REPORT_ZV (1 << O_ZUGVORLAGE)
# define REPORT_ZIP (1 << O_COMPRESS)
# define REPORT_BZIP2 (1 << O_BZIP2)
2011-03-07 08:02:35 +01:00
unit * can_find ( faction * f , faction * f2 )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
int key = f - > no % FMAXHASH ;
struct fsee * fs = fsee [ key ] ;
struct see * ss ;
if ( f = = f2 )
return f - > units ;
while ( fs & & fs - > f ! = f )
fs = fs - > nexthash ;
if ( ! fs )
return NULL ;
ss = fs - > see ;
while ( ss & & ss - > seen ! = f2 )
ss = ss - > next ;
if ( ss ) {
/* bei TARNE PARTEI yxz muss die Partei von unit proof nicht
* wirklich Partei f2 sein ! */
/* assert(ss->proof->faction==f2); */
return ss - > proof ;
}
2011-03-07 08:02:35 +01:00
return NULL ;
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
static void add_find ( faction * f , unit * u , faction * f2 )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
/* faction f sees f2 through u */
int key = f - > no % FMAXHASH ;
struct fsee * * fp = & fsee [ key ] ;
struct fsee * fs ;
struct see * * sp ;
struct see * ss ;
while ( * fp & & ( * fp ) - > f ! = f )
fp = & ( * fp ) - > nexthash ;
if ( ! * fp ) {
fs = * fp = calloc ( sizeof ( struct fsee ) , 1 ) ;
fs - > f = f ;
}
else
fs = * fp ;
sp = & fs - > see ;
while ( * sp & & ( * sp ) - > seen ! = f2 )
sp = & ( * sp ) - > next ;
if ( ! * sp ) {
ss = * sp = calloc ( sizeof ( struct see ) , 1 ) ;
ss - > proof = u ;
ss - > seen = f2 ;
}
else
ss = * sp ;
2010-08-08 10:06:34 +02:00
ss - > proof = u ;
}
2011-03-07 08:02:35 +01:00
static void update_find ( void )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
region * r ;
static bool initial = true ;
2010-08-08 10:06:34 +02:00
2014-08-17 00:14:50 +02:00
if ( initial )
for ( r = regions ; r ; r = r - > next ) {
2015-01-30 20:37:14 +01:00
unit * u ;
for ( u = r - > units ; u ; u = u - > next ) {
faction * lastf = u - > faction ;
unit * u2 ;
for ( u2 = r - > units ; u2 ; u2 = u2 - > next ) {
if ( u2 - > faction = = lastf | | u2 - > faction = = u - > faction )
continue ;
if ( seefaction ( u - > faction , r , u2 , 0 ) ) {
faction * fv = visible_faction ( u - > faction , u2 ) ;
lastf = fv ;
add_find ( u - > faction , u2 , fv ) ;
}
2014-08-17 00:14:50 +02:00
}
}
2010-08-08 10:06:34 +02:00
}
2014-08-17 00:14:50 +02:00
initial = false ;
2010-08-08 10:06:34 +02:00
}
2012-06-24 07:41:07 +02:00
bool kann_finden ( faction * f1 , faction * f2 )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
update_find ( ) ;
return ( bool ) ( can_find ( f1 , f2 ) ! = NULL ) ;
2010-08-08 10:06:34 +02:00
}
/******* end summary ******/
2011-03-07 08:02:35 +01:00
void register_nr ( void )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
if ( ! nocr )
register_reporttype ( " nr " , & report_plaintext , 1 < < O_REPORT ) ;
if ( ! nonr )
register_reporttype ( " txt " , & report_template , 1 < < O_ZUGVORLAGE ) ;
2010-08-08 10:06:34 +02:00
}
2011-03-07 08:02:35 +01:00
void report_cleanup ( void )
2010-08-08 10:06:34 +02:00
{
2014-08-17 00:14:50 +02:00
int i ;
for ( i = 0 ; i ! = FMAXHASH ; + + i ) {
while ( fsee [ i ] ) {
struct fsee * fs = fsee [ i ] - > nexthash ;
free ( fsee [ i ] ) ;
fsee [ i ] = fs ;
}
2010-08-08 10:06:34 +02:00
}
}