Merge pull request #755 from ennorehling/develop

ongoing work
This commit is contained in:
Enno Rehling 2018-01-05 17:52:26 +01:00 committed by GitHub
commit 1bd28f8ce5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 188 additions and 79 deletions

View File

@ -7,6 +7,7 @@ script: s/travis-build
addons: addons:
apt: apt:
packages: packages:
- libbsd-dev
- liblua5.1-dev - liblua5.1-dev
- libtolua-dev - libtolua-dev
- libncurses5-dev - libncurses5-dev

View File

@ -1,24 +1,46 @@
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
project (eressea-server C)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/" ${CMAKE_MODULE_PATH})
if (WIN32) if (WIN32)
FILE(TO_CMAKE_PATH "${CMAKE_MODULE_PATH}" CMAKE_MODULE_PATH ) FILE(TO_CMAKE_PATH "${CMAKE_MODULE_PATH}" CMAKE_MODULE_PATH )
FILE(TO_CMAKE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH ) FILE(TO_CMAKE_PATH "${CMAKE_PREFIX_PATH}" CMAKE_PREFIX_PATH )
endif(WIN32) endif(WIN32)
project (eressea-server C)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/" ${CMAKE_MODULE_PATH})
if (MSVC) if (MSVC)
include(MSVC) include(MSVC)
set (HAVE_STRDUP 0)
set (HAVE_STRLCAT 0)
set (HAVE_LIBBSD 0)
else (MSVC)
INCLUDE (CheckIncludeFile)
CHECK_INCLUDE_FILE(bsd/string.h HAVE_LIBBSD)
INCLUDE (CheckFunctionExists)
CHECK_FUNCTION_EXISTS(strdup HAVE_STRDUP)
IF (HAVE_LIBBSD)
INCLUDE (CheckLibraryExists)
CHECK_LIBRARY_EXISTS(bsd strlcat "bsd/string.h" HAVE_STRLCAT)
ELSE (HAVE_LIBBSD)
CHECK_FUNCTION_EXISTS(strlcat HAVE_STRLCAT)
ENDIF(HAVE_LIBBSD)
endif (MSVC) endif (MSVC)
INCLUDE (CheckSymbolExists) if (MSVC)
CHECK_SYMBOL_EXISTS(strlcat string.h HAVE_STRLCAT) find_package (PDCurses)
CHECK_SYMBOL_EXISTS(strdup string.h HAVE_STRDUP) SET(CURSES_FOUND ${PDCURSES_FOUND})
SET(CURSES_LIBRARIES ${PDCURSES_LIBRARY})
SET(CURSES_INCLUDE_DIR ${PDCURSES_INCLUDE_DIR})
else (MSVC)
find_package (Curses)
endif (MSVC)
find_package (SQLite3) find_package (SQLite3)
find_package (BerkeleyDB) find_package (BerkeleyDB)
find_package (Curses) find_package (LibXml2 REQUIRED)
find_package (LibXml2)
find_package (ToLua REQUIRED) find_package (ToLua REQUIRED)
if (TOLUA_FOUND) if (TOLUA_FOUND)
if (${TOLUA_VERSION_STRING} VERSION_GREATER "5.2") if (${TOLUA_VERSION_STRING} VERSION_GREATER "5.2")

View File

@ -0,0 +1,38 @@
# Locate PDCurses library
# This module defines
# PDCURSES_LIBRARIES, the name of the library to link against
# PDCURSES_FOUND, if false, do not try to link to PDCurses
# PDCURSES_INCLUDE_DIR, where to find curses.h
FIND_PATH(PDCURSES_INCLUDE_DIR curses.h
HINTS
$ENV{PDCURSESDIR}
PATH_SUFFIXES include/pdcurses include)
FIND_LIBRARY(PDCURSES_LIBRARY
NAMES pdcurses
HINTS
$ENV{PDCURSESDIR}
PATH_SUFFIXES lib64 lib)
FIND_LIBRARY(PDCURSES_PANEL_LIBRARY
NAMES panel
HINTS
$ENV{PDCURSESDIR}
PATH_SUFFIXES lib64 lib)
IF(PDCURSES_LIBRARY)
SET(PDCURSES_LIBRARIES ${PDCURSES_LIBRARY})
IF(PDCURSES_PANEL_LIBRARY)
SET(PDCURSES_LIBRARIES ${PDCURSES_LIBRARIES} ${PDCURSES_PANEL_LIBRARY})
ENDIF(PDCURSES_PANEL_LIBRARY)
ENDIF(PDCURSES_LIBRARY)
SET(PDCURSES_FOUND "NO")
IF(PDCURSES_INCLUDE_DIR AND PDCURSES_LIBRARY)
# message(STATUS "Found PDCurses library: ${PDCURSES_LIBRARIES}")
# Set the final string here so the GUI reflects the final state.
SET(PDCURSES_LIBRARIES PDCURSES_LIBRARY} CACHE STRING "Where the PDCurses Library can be found")
SET(PDCURSES_FOUND "YES")
ENDIF(PDCURSES_INCLUDE_DIR AND PDCURSES_LIBRARY)

View File

@ -8,6 +8,7 @@ function setup()
eressea.settings.set("rules.ship.damage.nocrewocean", "0") eressea.settings.set("rules.ship.damage.nocrewocean", "0")
eressea.settings.set("rules.ship.damage.nocrew", "0") eressea.settings.set("rules.ship.damage.nocrew", "0")
eressea.settings.set("rules.ship.drifting", "0") eressea.settings.set("rules.ship.drifting", "0")
eressea.settings.set("rules.ship.storms", "0")
end end
function test_ship_requires_skill() function test_ship_requires_skill()

View File

@ -267,14 +267,24 @@ add_test(server test_eressea)
install(TARGETS eressea DESTINATION "bin") install(TARGETS eressea DESTINATION "bin")
if (HAVE_LIBBSD)
add_definitions(-DHAVE_LIBBSD)
endif (HAVE_LIBBSD)
if (HAVE_STRLCAT) if (HAVE_STRLCAT)
add_definitions(-DHAVE_BSDSTRING) add_definitions(-DHAVE_BSDSTRING)
endif(HAVE_STRLCAT) endif (HAVE_STRLCAT)
if (HAVE_STRDUP) if (HAVE_STRDUP)
add_definitions(-DHAVE_STRDUP) add_definitions(-DHAVE_STRDUP)
endif(HAVE_STRDUP) endif(HAVE_STRDUP)
if (HAVE_LIBBSD)
target_link_libraries(test_eressea bsd)
target_link_libraries(eressea bsd)
target_link_libraries(convert bsd)
endif (HAVE_LIBBSD)
if (DB_FOUND) if (DB_FOUND)
include_directories (${DB_INCLUDE_DIR}) include_directories (${DB_INCLUDE_DIR})
target_link_libraries(convert ${DB_LIBRARIES}) target_link_libraries(convert ${DB_LIBRARIES})

View File

@ -64,7 +64,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/assert.h> #include <util/assert.h>
#include <util/attrib.h> #include <util/attrib.h>
#include <util/base36.h> #include <util/base36.h>
#include <util/bsdstring.h>
#include <util/language.h> #include <util/language.h>
#include <util/lists.h> #include <util/lists.h>
#include <util/log.h> #include <util/log.h>
@ -3517,10 +3516,10 @@ static int battle_report(battle * b)
for (bf = b->factions; bf; bf = bf->next) { for (bf = b->factions; bf; bf = bf->next) {
faction *fac = bf->faction; faction *fac = bf->faction;
char buf[32 * MAXSIDES]; char buf[32 * MAXSIDES];
char *bufp = buf;
size_t size = sizeof(buf) - 1;
message *m; message *m;
sbstring sbs;
sbs_init(&sbs, buf, sizeof(buf));
battle_message_faction(b, fac, msg_separator); battle_message_faction(b, fac, msg_separator);
if (cont) if (cont)
@ -3540,24 +3539,22 @@ static int battle_report(battle * b)
char buffer[32]; char buffer[32];
if (komma) { if (komma) {
bufp = STRLCPY(bufp, ", ", size); sbs_strcat(&sbs, ", ");
} }
snprintf(buffer, sizeof(buffer), "%s %2d(%s): ", snprintf(buffer, sizeof(buffer), "%s %2d(%s): ",
loc_army, army_index(s), abbrev); loc_army, army_index(s), abbrev);
sbs_strcat(&sbs, buffer);
bufp = STRLCPY(bufp, buffer, size);
for (r = FIGHT_ROW; r != NUMROWS; ++r) { for (r = FIGHT_ROW; r != NUMROWS; ++r) {
if (alive[r]) { if (alive[r]) {
if (l != FIGHT_ROW) { if (l != FIGHT_ROW) {
bufp = STRLCPY(bufp, "+", size); sbs_strcat(&sbs, "+");
} }
while (k--) { while (k--) {
bufp = STRLCPY(bufp, "0+", size); sbs_strcat(&sbs, "0+");
} }
sprintf(buffer, "%d", alive[r]); sprintf(buffer, "%d", alive[r]);
sbs_strcat(&sbs, buffer);
bufp = STRLCPY(bufp, buffer, size);
k = 0; k = 0;
l = r + 1; l = r + 1;
@ -3569,7 +3566,6 @@ static int battle_report(battle * b)
komma = true; komma = true;
} }
} }
*bufp = 0;
fbattlerecord(b, fac, buf); fbattlerecord(b, fac, buf);
} }
return cont; return cont;

View File

@ -1,4 +1,6 @@
#ifdef _MSC_VER
#include <platform.h> #include <platform.h>
#endif
#include "items.h" #include "items.h"
#include "alchemy.h" #include "alchemy.h"
@ -313,7 +315,7 @@ static int heal(unit * user, int effect)
{ {
int req = unit_max_hp(user) * user->number - user->hp; int req = unit_max_hp(user) * user->number - user->hp;
if (req > 0) { if (req > 0) {
req = MIN(req, effect); if (req > effect) req = effect;
effect -= req; effect -= req;
user->hp += req; user->hp += req;
} }

View File

@ -16,7 +16,9 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/ **/
#ifdef _MSC_VER
#include <platform.h> #include <platform.h>
#endif
#include <kernel/config.h> #include <kernel/config.h>
#include "connection.h" #include "connection.h"
@ -134,7 +136,8 @@ static connection **get_borders_i(const region * r1, const region * r2)
int key = reg_hashkey(r1); int key = reg_hashkey(r1);
int k2 = reg_hashkey(r2); int k2 = reg_hashkey(r2);
key = MIN(k2, key) % BORDER_MAXHASH; if (key > k2) key = k2;
key = key % BORDER_MAXHASH;
bp = &borders[key]; bp = &borders[key];
while (*bp) { while (*bp) {
connection *b = *bp; connection *b = *bp;
@ -515,9 +518,10 @@ static const char *b_nameroad(const connection * b, const region * r,
} }
} }
else { else {
int percent = MAX(1, 100 * local / r->terrain->max_road);
if (local) { if (local) {
const char *temp = LOC(f->locale, mkname("border", "a_road_percent")); const char *temp = LOC(f->locale, mkname("border", "a_road_percent"));
int percent = 100 * local / r->terrain->max_road;
if (percent < 1) percent = 1;
str_replace(buffer, sizeof(buffer), temp, "$percent", itoa10(percent)); str_replace(buffer, sizeof(buffer), temp, "$percent", itoa10(percent));
} }
else { else {

View File

@ -16,7 +16,9 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/ **/
#ifdef _MSC_VER
#include <platform.h> #include <platform.h>
#endif
#include <kernel/config.h> #include <kernel/config.h>
#include "curse.h" #include "curse.h"
@ -324,7 +326,8 @@ const curse_type *ct_find(const char *c)
return type; return type;
} }
else { else {
size_t k = MIN(c_len, strlen(type->cname)); size_t k = strlen(type->cname);
if (k > c_len) k = c_len;
if (!memcmp(c, type->cname, k)) { if (!memcmp(c, type->cname, k)) {
return type; return type;
} }
@ -483,7 +486,7 @@ int get_cursedmen(const unit * u, const curse * c)
cursedmen = c->data.i; cursedmen = c->data.i;
} }
return MIN(u->number, cursedmen); return (u->number < cursedmen) ? u->number : cursedmen;
} }
/* setzt die Anzahl der betroffenen Personen auf cursedmen */ /* setzt die Anzahl der betroffenen Personen auf cursedmen */
@ -572,19 +575,19 @@ curse *create_curse(unit * magician, attrib ** ap, const curse_type * ct,
/* es gibt schon eins diese Typs */ /* es gibt schon eins diese Typs */
if (c && ct->mergeflags != NO_MERGE) { if (c && ct->mergeflags != NO_MERGE) {
if (ct->mergeflags & M_DURATION) { if (ct->mergeflags & M_DURATION) {
c->duration = MAX(c->duration, duration); if (c->duration < duration) c->duration = duration;
} }
else if (ct->mergeflags & M_SUMDURATION) { else if (ct->mergeflags & M_SUMDURATION) {
c->duration += duration; c->duration += duration;
} }
if (ct->mergeflags & M_MAXEFFECT) { if (ct->mergeflags & M_MAXEFFECT) {
c->effect = MAX(c->effect, effect); if (c->effect < effect) c->effect = effect;
} }
else if (ct->mergeflags & M_SUMEFFECT) { else if (ct->mergeflags & M_SUMEFFECT) {
c->effect += effect; c->effect += effect;
} }
if (ct->mergeflags & M_VIGOUR) { if (ct->mergeflags & M_VIGOUR) {
c->vigour = MAX(vigour, c->vigour); if (c->vigour < vigour) c->vigour = vigour;
} }
else if (ct->mergeflags & M_VIGOUR_ADD) { else if (ct->mergeflags & M_VIGOUR_ADD) {
c->vigour = vigour + c->vigour; c->vigour = vigour + c->vigour;

View File

@ -17,7 +17,9 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/ **/
#ifdef _MSC_VER
#include <platform.h> #include <platform.h>
#endif
#include <kernel/config.h> #include <kernel/config.h>
#include "laws.h" #include "laws.h"
@ -208,7 +210,8 @@ static void live(region * r)
} }
/* bestes Talent raussuchen */ /* bestes Talent raussuchen */
if (sb != NULL) { if (sb != NULL) {
int weeks = MIN(effect, u->number); int weeks = u->number;
if (weeks > effect) weeks = effect;
reduce_skill(u, sb, weeks); reduce_skill(u, sb, weeks);
ADDMSG(&u->faction->msgs, msg_message("dumbeffect", ADDMSG(&u->faction->msgs, msg_message("dumbeffect",
"unit weeks skill", u, weeks, (skill_t)sb->id)); "unit weeks skill", u, weeks, (skill_t)sb->id));
@ -276,7 +279,7 @@ static void calculate_emigration(region * r)
int max_emigration = MAX_EMIGRATION(rp2 - maxp2); int max_emigration = MAX_EMIGRATION(rp2 - maxp2);
if (max_emigration > 0) { if (max_emigration > 0) {
max_emigration = MIN(max_emigration, max_immigrants); if (max_emigration > max_immigrants) max_emigration = max_immigrants;
r->land->newpeasants += max_emigration; r->land->newpeasants += max_emigration;
rc->land->newpeasants -= max_emigration; rc->land->newpeasants -= max_emigration;
max_immigrants -= max_emigration; max_immigrants -= max_emigration;
@ -301,8 +304,8 @@ int peasant_luck_effect(int peasants, int luck, int maxp, double variance)
int births = 0; int births = 0;
double mean; double mean;
if (luck == 0) return 0; if (luck == 0) return 0;
mean = fmin(luck, peasants);
mean = peasant_luck_factor() * peasant_growth_factor() * MIN(luck, peasants); mean *= peasant_luck_factor() * peasant_growth_factor();
mean *= ((peasants / (double)maxp < .9) ? 1 : PEASANTFORCE); mean *= ((peasants / (double)maxp < .9) ? 1 : PEASANTFORCE);
births = RAND_ROUND(normalvariate(mean, variance * mean)); births = RAND_ROUND(normalvariate(mean, variance * mean));
@ -315,11 +318,11 @@ int peasant_luck_effect(int peasants, int luck, int maxp, double variance)
static void peasants(region * r, int rule) static void peasants(region * r, int rule)
{ {
int peasants = rpeasants(r); int rp = rpeasants(r);
int money = rmoney(r); int money = rmoney(r);
int maxp = max_production(r); int maxp = max_production(r);
int n, satiated; int n, satiated;
int dead = 0; int dead = 0, peasants = rp;
if (peasants > 0 && rule > 0) { if (peasants > 0 && rule > 0) {
int luck = 0; int luck = 0;
@ -339,7 +342,8 @@ static void peasants(region * r, int rule)
/* Alle werden satt, oder halt soviele für die es auch Geld gibt */ /* Alle werden satt, oder halt soviele für die es auch Geld gibt */
satiated = MIN(peasants, money / maintenance_cost(NULL)); satiated = money / maintenance_cost(NULL);
if (satiated > peasants) satiated = peasants;
rsetmoney(r, money - satiated * maintenance_cost(NULL)); rsetmoney(r, money - satiated * maintenance_cost(NULL));
/* Von denjenigen, die nicht satt geworden sind, verhungert der /* Von denjenigen, die nicht satt geworden sind, verhungert der
@ -348,7 +352,8 @@ static void peasants(region * r, int rule)
/* Es verhungert maximal die unterernährten Bevölkerung. */ /* Es verhungert maximal die unterernährten Bevölkerung. */
n = MIN(peasants - satiated, rpeasants(r)); n = peasants - satiated;
if (n > rp) n = rp;
dead += (int)(0.5 + n * PEASANT_STARVATION_CHANCE); dead += (int)(0.5 + n * PEASANT_STARVATION_CHANCE);
if (dead > 0) { if (dead > 0) {
@ -429,13 +434,12 @@ static void horses(region * r)
/* Logistisches Wachstum, Optimum bei halbem Maximalbesatz. */ /* Logistisches Wachstum, Optimum bei halbem Maximalbesatz. */
maxhorses = region_maxworkers(r) / 10; maxhorses = region_maxworkers(r) / 10;
maxhorses = MAX(0, maxhorses);
horses = rhorses(r); horses = rhorses(r);
if (horses > 0) { if (horses > 0) {
if (is_cursed(r->attribs, &ct_godcursezone)) { if (is_cursed(r->attribs, &ct_godcursezone)) {
rsethorses(r, (int)(horses * 0.9)); rsethorses(r, (int)(horses * 0.9));
} }
else if (maxhorses) { else if (maxhorses > 0) {
double growth = double growth =
(RESOURCE_QUANTITY * HORSEGROWTH * 200 * (maxhorses - (RESOURCE_QUANTITY * HORSEGROWTH * 200 * (maxhorses -
horses)) / maxhorses; horses)) / maxhorses;
@ -464,7 +468,7 @@ static void horses(region * r)
if (r2 && fval(r2->terrain, WALK_INTO)) { if (r2 && fval(r2->terrain, WALK_INTO)) {
int pt = (rhorses(r) * HORSEMOVE) / 100; int pt = (rhorses(r) * HORSEMOVE) / 100;
pt = (int)normalvariate(pt, pt / 4.0); pt = (int)normalvariate(pt, pt / 4.0);
pt = MAX(0, pt); if (pt < 0) pt = 0;
if (fval(r2, RF_MIGRATION)) if (fval(r2, RF_MIGRATION))
rsethorses(r2, rhorses(r2) + pt); rsethorses(r2, rhorses(r2) + pt);
else { else {
@ -571,13 +575,14 @@ growing_trees(region * r, const int current_season, const int last_weeks_season)
if (current_season == SEASON_SUMMER || current_season == SEASON_AUTUMN) { if (current_season == SEASON_SUMMER || current_season == SEASON_AUTUMN) {
double seedchance = 0.01F * RESOURCE_QUANTITY; double seedchance = 0.01F * RESOURCE_QUANTITY;
int elves = count_race(r, get_race(RC_ELF)); int mp, elves = count_race(r, get_race(RC_ELF));
direction_t d; direction_t d;
a = a_find(r->attribs, &at_germs); a = a_find(r->attribs, &at_germs);
if (a && last_weeks_season == SEASON_SPRING) { if (a && last_weeks_season == SEASON_SPRING) {
/* ungekeimte Samen bleiben erhalten, Sprößlinge wachsen */ /* ungekeimte Samen bleiben erhalten, Sprößlinge wachsen */
sprout = MIN(a->data.sa[1], rtrees(r, 1)); sprout = rtrees(r, 1);
if (sprout > a->data.sa[1]) sprout = a->data.sa[1];
/* aus dem gesamt Sprößlingepool abziehen */ /* aus dem gesamt Sprößlingepool abziehen */
rsettrees(r, 1, rtrees(r, 1) - sprout); rsettrees(r, 1, rtrees(r, 1) - sprout);
/* zu den Bäumen hinzufügen */ /* zu den Bäumen hinzufügen */
@ -592,12 +597,14 @@ growing_trees(region * r, const int current_season, const int last_weeks_season)
return; return;
} }
if (max_production(r) <= 0) mp = max_production(r);
if (mp <= 0)
return; return;
/* Grundchance 1.0% */ /* Grundchance 1.0% */
/* Jeder Elf in der Region erhöht die Chance marginal */ /* Jeder Elf in der Region erhöht die Chance marginal */
elves = MIN(elves, max_production(r) / 8); mp = mp / 8;
if (elves > mp) elves = mp;
if (elves) { if (elves) {
seedchance += 1.0 - pow(0.99999, elves * RESOURCE_QUANTITY); seedchance += 1.0 - pow(0.99999, elves * RESOURCE_QUANTITY);
} }
@ -664,7 +671,8 @@ growing_trees(region * r, const int current_season, const int last_weeks_season)
/* Raubbau abfangen, es dürfen nie mehr Samen wachsen, als aktuell /* Raubbau abfangen, es dürfen nie mehr Samen wachsen, als aktuell
* in der Region sind */ * in der Region sind */
seeds = MIN(a->data.sa[0], rtrees(r, 0)); seeds = rtrees(r, 0);
if (seeds > a->data.sa[0]) seeds = a->data.sa[0];
sprout = 0; sprout = 0;
for (i = 0; i < seeds; i++) { for (i = 0; i < seeds; i++) {
@ -684,7 +692,8 @@ growing_trees(region * r, const int current_season, const int last_weeks_season)
* der Region entfernt werden können, da Jungbäume in der gleichen * der Region entfernt werden können, da Jungbäume in der gleichen
* Runde nachwachsen, wir also nicht mehr zwischen diesjährigen und * Runde nachwachsen, wir also nicht mehr zwischen diesjährigen und
* 'alten' Jungbäumen unterscheiden könnten */ * 'alten' Jungbäumen unterscheiden könnten */
sprout = MIN(a->data.sa[1], rtrees(r, 1)); sprout = rtrees(r, 1);
if (sprout > a->data.sa[1]) sprout = a->data.sa[1];
grownup_trees = 0; grownup_trees = 0;
for (i = 0; i < sprout; i++) { for (i = 0; i < sprout; i++) {
@ -707,6 +716,7 @@ growing_herbs(region * r, const int current_season, const int last_weeks_season)
* *
* Jedes Kraut hat eine Wahrscheinlichkeit von (100-(vorhandene * Jedes Kraut hat eine Wahrscheinlichkeit von (100-(vorhandene
* Kräuter))% sich zu vermehren. */ * Kräuter))% sich zu vermehren. */
UNUSED_ARG(last_weeks_season);
if (current_season != SEASON_WINTER) { if (current_season != SEASON_WINTER) {
int i; int i;
for (i = rherbs(r); i > 0; i--) { for (i = rherbs(r); i > 0; i--) {
@ -724,7 +734,9 @@ void immigration(void)
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
if (r->land && r->land->newpeasants) { if (r->land && r->land->newpeasants) {
int rp = rpeasants(r) + r->land->newpeasants; int rp = rpeasants(r) + r->land->newpeasants;
rsetpeasants(r, MAX(0, rp)); /* FIXME: kann ernsthaft abs(newpeasants) > rpeasants(r) sein? */
if (rp < 0) rp = 0;
rsetpeasants(r, rp);
} }
/* Genereate some (0-6 depending on the income) peasants out of nothing */ /* Genereate some (0-6 depending on the income) peasants out of nothing */
/* if less than 50 are in the region and there is space and no monster or demon units in the region */ /* if less than 50 are in the region and there is space and no monster or demon units in the region */
@ -830,7 +842,7 @@ void demographics(void)
peasants(r, peasant_rules); peasants(r, peasant_rules);
if (r->age > 20) { if (r->age > 20) {
double mwp = MAX(region_maxworkers(r), 1); double mwp = fmax(region_maxworkers(r), 1);
double prob = double prob =
pow(rpeasants(r) / (mwp * wage(r, NULL, NULL, turn) * 0.13), 4.0) pow(rpeasants(r) / (mwp * wage(r, NULL, NULL, turn) * 0.13), 4.0)
* PLAGUE_CHANCE; * PLAGUE_CHANCE;
@ -905,7 +917,7 @@ static int slipthru(const region * r, const unit * u, const building * b)
int can_contact(const region * r, const unit * u, const unit * u2) { int can_contact(const region * r, const unit * u, const unit * u2) {
/* hier geht es nur um die belagerung von burgen */ /* hier geht es nur um die belagerung von burgen */
UNUSED_ARG(r);
if (u->building == u2->building) { if (u->building == u2->building) {
return 1; return 1;
} }
@ -994,6 +1006,7 @@ int quit_cmd(unit * u, struct order *ord)
static bool mayenter(region * r, unit * u, building * b) static bool mayenter(region * r, unit * u, building * b)
{ {
unit *u2; unit *u2;
UNUSED_ARG(r);
if (fval(b, BLD_UNGUARDED)) if (fval(b, BLD_UNGUARDED))
return true; return true;
u2 = building_owner(b); u2 = building_owner(b);
@ -1245,7 +1258,7 @@ static void nmr_death(faction * f)
static void remove_idle_players(void) static void remove_idle_players(void)
{ {
faction **fp; faction **fp;
int timeout = NMRTimeout(); int i, timeout = NMRTimeout();
log_info(" - beseitige Spieler, die sich zu lange nicht mehr gemeldet haben..."); log_info(" - beseitige Spieler, die sich zu lange nicht mehr gemeldet haben...");
@ -1269,7 +1282,9 @@ static void remove_idle_players(void)
} }
log_info(" - beseitige Spieler, die sich nach der Anmeldung nicht gemeldet haben..."); log_info(" - beseitige Spieler, die sich nach der Anmeldung nicht gemeldet haben...");
age = calloc(MAX(4, turn + 1), sizeof(int)); i = turn + 1;
if (i < 4) i = 4;
age = calloc(i, sizeof(int));
for (fp = &factions; *fp;) { for (fp = &factions; *fp;) {
faction *f = *fp; faction *f = *fp;
if (!is_monsters(f)) { if (!is_monsters(f)) {
@ -2639,8 +2654,7 @@ int combatspell_cmd(unit * u, struct order *ord)
/* Optional: STUFE n */ /* Optional: STUFE n */
if (findparam(s, u->faction->locale) == P_LEVEL) { if (findparam(s, u->faction->locale) == P_LEVEL) {
/* Merken, setzen kommt erst später */ /* Merken, setzen kommt erst später */
level = getint(); level = getuint();
level = MAX(0, level);
s = gettoken(token, sizeof(token)); s = gettoken(token, sizeof(token));
} }
@ -2867,16 +2881,20 @@ static void age_stonecircle(building *b) {
if (!c) { if (!c) {
int sk = effskill(mage, SK_MAGIC, 0); int sk = effskill(mage, SK_MAGIC, 0);
float effect = 100; float effect = 100;
if (sk > 0) {
int vig = sk;
int dur = (sk + 1) / 2;
/* the mage reactivates the circle */ /* the mage reactivates the circle */
c = create_curse(mage, &rt->attribs, &ct_astralblock, c = create_curse(mage, &rt->attribs, &ct_astralblock,
(float)MAX(1, sk), MAX(1, sk / 2), effect, 0); vig, dur, effect, 0);
ADDMSG(&r->msgs, ADDMSG(&r->msgs,
msg_message("astralshield_activate", "region unit", r, mage)); msg_message("astralshield_activate", "region unit", r, mage));
} }
}
else { else {
int sk = effskill(mage, SK_MAGIC, 0); int sk = effskill(mage, SK_MAGIC, 0);
c->duration = MAX(c->duration, sk / 2); if (c->duration < sk / 2) c->duration = sk / 2;
c->vigour = MAX(c->vigour, (float)sk); if (c->vigour < sk) c->vigour = sk;
} }
} }
} }
@ -2917,12 +2935,14 @@ static void ageing(void)
/* Goliathwasser */ /* Goliathwasser */
int i = get_effect(u, oldpotiontype[P_STRONG]); int i = get_effect(u, oldpotiontype[P_STRONG]);
if (i > 0) { if (i > 0) {
change_effect(u, oldpotiontype[P_STRONG], -1 * MIN(u->number, i)); if (i > u->number) i = u->number;
change_effect(u, oldpotiontype[P_STRONG], - i);
} }
/* Berserkerblut */ /* Berserkerblut */
i = get_effect(u, oldpotiontype[P_BERSERK]); i = get_effect(u, oldpotiontype[P_BERSERK]);
if (i > 0) { if (i > 0) {
change_effect(u, oldpotiontype[P_BERSERK], -1 * MIN(u->number, i)); if (i > u->number) i = u->number;
change_effect(u, oldpotiontype[P_BERSERK], - i);
} }
if (u->attribs) { if (u->attribs) {
@ -2992,13 +3012,14 @@ static int maxunits(const faction * f)
{ {
int flimit = rule_faction_limit(); int flimit = rule_faction_limit();
int alimit = rule_alliance_limit(); int alimit = rule_alliance_limit();
UNUSED_ARG(f);
if (alimit == 0) { if (alimit == 0) {
return flimit; return flimit;
} }
if (flimit == 0) { if (flimit == 0) {
return alimit; return alimit;
} }
return MIN(alimit, flimit); return (alimit > flimit) ? flimit : alimit;
} }
int checkunitnumber(const faction * f, int add) int checkunitnumber(const faction * f, int add)
@ -3306,7 +3327,7 @@ void monthly_healing(void)
p *= u_heal_factor(u); p *= u_heal_factor(u);
if (u->hp < umhp) { if (u->hp < umhp) {
double maxheal = MAX(u->number, umhp / 20.0); double maxheal = fmax(u->number, umhp / 20.0);
int addhp; int addhp;
if (active_building(u, bt_find("inn"))) { if (active_building(u, bt_find("inn"))) {
p *= 1.5; p *= 1.5;
@ -3321,7 +3342,8 @@ void monthly_healing(void)
++addhp; ++addhp;
/* Aufaddieren der geheilten HP. */ /* Aufaddieren der geheilten HP. */
u->hp = MIN(u->hp + addhp, umhp); if (umhp > u->hp + addhp) umhp = u->hp + addhp;
u->hp = umhp;
/* soll man an negativer regeneration sterben können? */ /* soll man an negativer regeneration sterben können? */
assert(u->hp > 0); assert(u->hp > 0);
@ -3647,7 +3669,7 @@ int claim_cmd(unit * u, struct order *ord)
if (itype) { if (itype) {
item **iclaim = i_find(&u->faction->items, itype); item **iclaim = i_find(&u->faction->items, itype);
if (iclaim && *iclaim) { if (iclaim && *iclaim) {
n = MIN(n, (*iclaim)->number); if (n > (*iclaim)->number) n = (*iclaim)->number;
i_change(iclaim, itype, -n); i_change(iclaim, itype, -n);
i_change(&u->items, itype, n); i_change(&u->items, itype, n);
} }
@ -3907,7 +3929,7 @@ int armedmen(const unit * u, bool siege_weapons)
if (n >= u->number) if (n >= u->number)
break; break;
} }
n = MIN(n, u->number); if (n > u->number) n = u->number;
} }
} }
return n; return n;
@ -3941,9 +3963,9 @@ int siege_cmd(unit * u, order * ord)
rt_catapult = rt_find("catapult"); rt_catapult = rt_find("catapult");
d = i_get(u->items, rt_catapult->itype); d = i_get(u->items, rt_catapult->itype);
d = MIN(u->number, d); if (d > u->number) d = u->number;
pooled = get_pooled(u, rt_catapultammo, GET_DEFAULT, d); pooled = get_pooled(u, rt_catapultammo, GET_DEFAULT, d);
d = MIN(pooled, d); if (d > pooled) d = pooled;
if (effskill(u, SK_CATAPULT, 0) >= 1) { if (effskill(u, SK_CATAPULT, 0) >= 1) {
katapultiere = d; katapultiere = d;
d *= effskill(u, SK_CATAPULT, 0); d *= effskill(u, SK_CATAPULT, 0);
@ -3970,11 +3992,11 @@ int siege_cmd(unit * u, order * ord)
* einheiten wieder abgesucht werden muessen! */ * einheiten wieder abgesucht werden muessen! */
usetsiege(u, b); usetsiege(u, b);
b->besieged += MAX(bewaffnete, katapultiere); if (katapultiere < bewaffnete) katapultiere = bewaffnete;
b->besieged += katapultiere;
/* definitiver schaden eingeschraenkt */ /* definitiver schaden eingeschraenkt */
if (d > b->size - 1) d = b->size - 1;
d = MIN(d, b->size - 1);
/* meldung, schaden anrichten */ /* meldung, schaden anrichten */
if (d && !curse_active(get_curse(b->attribs, &ct_magicwalls))) { if (d && !curse_active(get_curse(b->attribs, &ct_magicwalls))) {

View File

@ -72,7 +72,7 @@ int lighthouse_range(const building * b, const faction * f, const unit *u)
int sk = effskill(u, SK_PERCEPTION, 0) / 3; int sk = effskill(u, SK_PERCEPTION, 0) / 3;
assert(u->building == b); assert(u->building == b);
assert(u->faction == f); assert(u->faction == f);
maxd = MIN(maxd, sk); if (maxd > sk) maxd = sk;
} }
/* E3A rule: no perception req'd */ /* E3A rule: no perception req'd */
return maxd; return maxd;

View File

@ -103,7 +103,7 @@ static void reduce_weight(unit * u)
int horses = get_resource(u, get_resourcetype(R_HORSE)); int horses = get_resource(u, get_resourcetype(R_HORSE));
if (horses > 0) { if (horses > 0) {
horses = MIN(horses, (u->number * 2)); if (horses > u->number * 2) horses = u->number * 2;
change_resource(u, get_resourcetype(R_HORSE), -horses); change_resource(u, get_resourcetype(R_HORSE), -horses);
} }

View File

@ -2301,7 +2301,7 @@ int follow_ship(unit * u, order * ord)
moves = 1; moves = 1;
speed = (int)getuint(); speed = getuint();
if (speed == 0) { if (speed == 0) {
speed = shipspeed(u->ship, u); speed = shipspeed(u->ship, u);
} }

View File

@ -246,7 +246,7 @@ int getint(void)
return s ? atoi(s) : 0; return s ? atoi(s) : 0;
} }
unsigned int getuint(void) int getuint(void)
{ {
int n = getint(); int n = getint();
return (n < 0) ? 0 : n; return (n < 0) ? 0 : n;

View File

@ -28,7 +28,7 @@ extern "C" {
bool parser_end(void); bool parser_end(void);
const char *getstrtoken(void); const char *getstrtoken(void);
const char *gettoken(char *lbuf, size_t bufsize); const char *gettoken(char *lbuf, size_t bufsize);
unsigned int getuint(void); int getuint(void);
int getint(void); int getint(void);
int getid(void); int getid(void);
unsigned int atoip(const char *s); unsigned int atoip(const char *s);

View File

@ -25,10 +25,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* libc includes */ /* libc includes */
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_LIBBSD
#include <bsd/string.h>
#else
#include <string.h>
#endif
size_t str_strlcpy(char *dst, const char *src, size_t len) size_t str_strlcpy(char *dst, const char *src, size_t len)
{ {
#ifdef HAVE_BSDSTRING #ifdef HAVE_BSDSTRING
@ -232,10 +237,15 @@ unsigned int wang_hash(unsigned int a)
} }
char *str_strdup(const char *s) { char *str_strdup(const char *s) {
#ifdef _MSC_VER #ifdef HAVE_STRDUP
return strdup(s);
#elif defined(_MSC_VER)
return _strdup(s); return _strdup(s);
#else #else
return strdup(s); size_t len = strlen(s);
char *dup = malloc(len+1);
memcpy(dup, s, len+1);
return dup;
#endif #endif
} }

View File

@ -9,5 +9,5 @@ IF exist build-vs%VSVERSION% goto HAVEDIR
mkdir build-vs%VSVERSION% mkdir build-vs%VSVERSION%
:HAVEDIR :HAVEDIR
cd build-vs%VSVERSION% cd build-vs%VSVERSION%
"%ProgramFiles%\CMake\bin\cmake.exe" -G "Visual Studio %VSVERSION%" -DCMAKE_PREFIX_PATH="%ProgramFiles(x86)%/Lua/5.1;%ERESSEA%/dependencies-win32" -DCMAKE_MODULE_PATH="%SRCDIR%/cmake/Modules" -DCMAKE_SUPPRESS_REGENERATION=TRUE .. "%ProgramFiles%\CMake\bin\cmake.exe" -G "Visual Studio %VSVERSION%" -DCMAKE_PREFIX_PATH="%ProgramFiles(x86)%\Lua\5.1;%ERESSEA%\dependencies-win32" -DCMAKE_SUPPRESS_REGENERATION=TRUE ..
PAUSE PAUSE