forked from github/server
compiling with -pedantic on linux
This commit is contained in:
parent
04b3d7ff45
commit
b4c5607747
16 changed files with 1850 additions and 1837 deletions
|
@ -20,6 +20,7 @@ without prior permission by the authors of Eressea.
|
|||
#include <kernel/binarystore.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <lua.h>
|
||||
#include <tolua.h>
|
||||
|
|
|
@ -8,17 +8,17 @@
|
|||
|
||||
This program may not be used, modified or distributed
|
||||
without prior permission by the authors of Eressea.
|
||||
*/
|
||||
|
||||
*/
|
||||
|
||||
#include <platform.h>
|
||||
#include "bindings.h"
|
||||
#include "bind_unit.h"
|
||||
#include "bind_faction.h"
|
||||
#include "bind_region.h"
|
||||
#include "helpers.h"
|
||||
|
||||
|
||||
#include <kernel/config.h>
|
||||
|
||||
|
||||
#include <kernel/alliance.h>
|
||||
#include <kernel/skill.h>
|
||||
#include <kernel/equipment.h>
|
||||
|
@ -37,18 +37,18 @@ without prior permission by the authors of Eressea.
|
|||
#include <kernel/teleport.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/save.h>
|
||||
|
||||
|
||||
#include <gamecode/creport.h>
|
||||
#include <gamecode/economy.h>
|
||||
#include <gamecode/summary.h>
|
||||
#include <gamecode/laws.h>
|
||||
#include <gamecode/monster.h>
|
||||
#include <gamecode/market.h>
|
||||
|
||||
|
||||
#include <modules/autoseed.h>
|
||||
#include <modules/score.h>
|
||||
#include <attributes/key.h>
|
||||
|
||||
|
||||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/eventbus.h>
|
||||
|
@ -59,15 +59,15 @@ without prior permission by the authors of Eressea.
|
|||
#include <util/rand.h>
|
||||
#include <util/rng.h>
|
||||
#include <util/storage.h>
|
||||
|
||||
|
||||
#include <iniparser/iniparser.h>
|
||||
#include <tolua.h>
|
||||
#include <lua.h>
|
||||
|
||||
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
|
||||
int log_lua_error(lua_State * L)
|
||||
int log_lua_error(lua_State * L)
|
||||
{
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error(("LUA call failed.\n%s\n", error));
|
||||
|
@ -75,10 +75,10 @@ int log_lua_error(lua_State * L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int tolua_orderlist_next(lua_State * L)
|
||||
int tolua_orderlist_next(lua_State * L)
|
||||
{
|
||||
order ** order_ptr = (order **) lua_touserdata(L, lua_upvalueindex(1));
|
||||
order * ord = *order_ptr;
|
||||
order **order_ptr = (order **) lua_touserdata(L, lua_upvalueindex(1));
|
||||
order *ord = *order_ptr;
|
||||
if (ord != NULL) {
|
||||
char cmd[8192];
|
||||
write_order(ord, cmd, sizeof(cmd));
|
||||
|
@ -89,10 +89,10 @@ int tolua_orderlist_next(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_quicklist_iter(lua_State * L)
|
||||
static int tolua_quicklist_iter(lua_State * L)
|
||||
{
|
||||
quicklist ** qlp = (quicklist **) lua_touserdata(L, lua_upvalueindex(1));
|
||||
quicklist * ql = *qlp;
|
||||
quicklist **qlp = (quicklist **) lua_touserdata(L, lua_upvalueindex(1));
|
||||
quicklist *ql = *qlp;
|
||||
if (ql != NULL) {
|
||||
int index = lua_tointeger(L, lua_upvalueindex(2));
|
||||
const char *type = lua_tostring(L, lua_upvalueindex(3));
|
||||
|
@ -107,27 +107,27 @@ static int tolua_quicklist_iter(lua_State * L)
|
|||
}
|
||||
|
||||
int tolua_quicklist_push(struct lua_State *L, const char *list_type,
|
||||
const char *elem_type, struct quicklist *list)
|
||||
const char *elem_type, struct quicklist *list)
|
||||
{
|
||||
if (list) {
|
||||
quicklist ** qlist_ptr =
|
||||
quicklist **qlist_ptr =
|
||||
(quicklist **) lua_newuserdata(L, sizeof(quicklist *));
|
||||
*qlist_ptr = list;
|
||||
luaL_getmetatable(L, list_type);
|
||||
lua_setmetatable(L, -2);
|
||||
lua_pushnumber(L, 0);
|
||||
lua_pushstring(L, elem_type);
|
||||
lua_pushcclosure(L, tolua_quicklist_iter, 3); /* OBS: this closure has multiple upvalues (list, index, type_name) */
|
||||
lua_pushcclosure(L, tolua_quicklist_iter, 3); /* OBS: this closure has multiple upvalues (list, index, type_name) */
|
||||
} else {
|
||||
lua_pushnil(L);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int tolua_itemlist_next(lua_State * L)
|
||||
int tolua_itemlist_next(lua_State * L)
|
||||
{
|
||||
item ** item_ptr = (item **) lua_touserdata(L, lua_upvalueindex(1));
|
||||
item * itm = *item_ptr;
|
||||
item **item_ptr = (item **) lua_touserdata(L, lua_upvalueindex(1));
|
||||
item *itm = *item_ptr;
|
||||
if (itm != NULL) {
|
||||
tolua_pushstring(L, itm->type->rtype->_name[0]);
|
||||
*item_ptr = itm->next;
|
||||
|
@ -136,11 +136,11 @@ int tolua_itemlist_next(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_autoseed(lua_State * L)
|
||||
static int tolua_autoseed(lua_State * L)
|
||||
{
|
||||
const char *filename = tolua_tostring(L, 1, 0);
|
||||
int new_island = tolua_toboolean(L, 2, 0);
|
||||
newfaction * players = read_newfactions(filename);
|
||||
newfaction *players = read_newfactions(filename);
|
||||
if (players != NULL) {
|
||||
while (players) {
|
||||
int n = listlen(players);
|
||||
|
@ -155,16 +155,16 @@ static int tolua_autoseed(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_getkey(lua_State * L)
|
||||
static int tolua_getkey(lua_State * L)
|
||||
{
|
||||
const char *name = tolua_tostring(L, 1, 0);
|
||||
int flag = atoi36(name);
|
||||
attrib * a = find_key(global.attribs, flag);
|
||||
attrib *a = find_key(global.attribs, flag);
|
||||
lua_pushboolean(L, a != NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_translate(lua_State * L)
|
||||
static int tolua_translate(lua_State * L)
|
||||
{
|
||||
const char *str = tolua_tostring(L, 1, 0);
|
||||
const char *lang = tolua_tostring(L, 2, 0);
|
||||
|
@ -177,12 +177,12 @@ static int tolua_translate(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_setkey(lua_State * L)
|
||||
static int tolua_setkey(lua_State * L)
|
||||
{
|
||||
const char *name = tolua_tostring(L, 1, 0);
|
||||
int value = tolua_toboolean(L, 2, 0);
|
||||
int flag = atoi36(name);
|
||||
attrib * a = find_key(global.attribs, flag);
|
||||
attrib *a = find_key(global.attribs, flag);
|
||||
if (a == NULL && value) {
|
||||
add_key(&global.attribs, flag);
|
||||
} else if (a != NULL && !value) {
|
||||
|
@ -191,13 +191,13 @@ static int tolua_setkey(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_rng_int(lua_State * L)
|
||||
static int tolua_rng_int(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, (lua_Number) rng_int());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_read_orders(lua_State * L)
|
||||
static int tolua_read_orders(lua_State * L)
|
||||
{
|
||||
const char *filename = tolua_tostring(L, 1, 0);
|
||||
int result = readorders(filename);
|
||||
|
@ -205,10 +205,10 @@ static int tolua_read_orders(lua_State * L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_message_unit(lua_State * L)
|
||||
static int tolua_message_unit(lua_State * L)
|
||||
{
|
||||
unit * sender = (unit *) tolua_tousertype(L, 1, 0);
|
||||
unit * target = (unit *) tolua_tousertype(L, 2, 0);
|
||||
unit *sender = (unit *) tolua_tousertype(L, 1, 0);
|
||||
unit *target = (unit *) tolua_tousertype(L, 2, 0);
|
||||
const char *str = tolua_tostring(L, 3, 0);
|
||||
if (!target)
|
||||
tolua_error(L, TOLUA_CAST "target is nil", NULL);
|
||||
|
@ -218,10 +218,10 @@ static int tolua_message_unit(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_message_faction(lua_State * L)
|
||||
static int tolua_message_faction(lua_State * L)
|
||||
{
|
||||
unit * sender = (unit *) tolua_tousertype(L, 1, 0);
|
||||
faction * target = (faction *) tolua_tousertype(L, 2, 0);
|
||||
unit *sender = (unit *) tolua_tousertype(L, 1, 0);
|
||||
faction *target = (faction *) tolua_tousertype(L, 2, 0);
|
||||
const char *str = tolua_tostring(L, 3, 0);
|
||||
if (!target)
|
||||
tolua_error(L, TOLUA_CAST "target is nil", NULL);
|
||||
|
@ -231,9 +231,9 @@ static int tolua_message_faction(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_message_region(lua_State * L)
|
||||
static int tolua_message_region(lua_State * L)
|
||||
{
|
||||
unit * sender = (unit *) tolua_tousertype(L, 1, 0);
|
||||
unit *sender = (unit *) tolua_tousertype(L, 1, 0);
|
||||
const char *str = tolua_tostring(L, 2, 0);
|
||||
if (!sender)
|
||||
tolua_error(L, TOLUA_CAST "sender is nil", NULL);
|
||||
|
@ -242,46 +242,46 @@ static int tolua_message_region(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_update_guards(lua_State * L)
|
||||
static int tolua_update_guards(lua_State * L)
|
||||
{
|
||||
update_guards();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_set_turn(lua_State * L)
|
||||
static int tolua_set_turn(lua_State * L)
|
||||
{
|
||||
turn = (int)tolua_tonumber(L, 1, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_get_turn(lua_State * L)
|
||||
static int tolua_get_turn(lua_State * L)
|
||||
{
|
||||
tolua_pushnumber(L, (lua_Number) turn);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_atoi36(lua_State * L)
|
||||
static int tolua_atoi36(lua_State * L)
|
||||
{
|
||||
const char *s = tolua_tostring(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number) atoi36(s));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_itoa36(lua_State * L)
|
||||
static int tolua_itoa36(lua_State * L)
|
||||
{
|
||||
int i = (int)tolua_tonumber(L, 1, 0);
|
||||
tolua_pushstring(L, itoa36(i));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_dice_rand(lua_State * L)
|
||||
static int tolua_dice_rand(lua_State * L)
|
||||
{
|
||||
const char *s = tolua_tostring(L, 1, 0);
|
||||
tolua_pushnumber(L, dice_rand(s));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_addequipment(lua_State * L)
|
||||
static int tolua_addequipment(lua_State * L)
|
||||
{
|
||||
const char *eqname = tolua_tostring(L, 1, 0);
|
||||
const char *iname = tolua_tostring(L, 2, 0);
|
||||
|
@ -298,7 +298,7 @@ static int tolua_addequipment(lua_State * L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_get_season(lua_State * L)
|
||||
static int tolua_get_season(lua_State * L)
|
||||
{
|
||||
int turnno = (int)tolua_tonumber(L, 1, 0);
|
||||
gamedate gd;
|
||||
|
@ -307,25 +307,25 @@ static int tolua_get_season(lua_State * L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_create_curse(lua_State * L)
|
||||
static int tolua_create_curse(lua_State * L)
|
||||
{
|
||||
unit * u = (unit *) tolua_tousertype(L, 1, 0);
|
||||
unit *u = (unit *) tolua_tousertype(L, 1, 0);
|
||||
tolua_Error tolua_err;
|
||||
attrib ** ap = NULL;
|
||||
attrib **ap = NULL;
|
||||
if (tolua_isusertype(L, 2, TOLUA_CAST "unit", 0, &tolua_err)) {
|
||||
unit * target = (unit *) tolua_tousertype(L, 2, 0);
|
||||
unit *target = (unit *) tolua_tousertype(L, 2, 0);
|
||||
if (target)
|
||||
ap = &target->attribs;
|
||||
} else if (tolua_isusertype(L, 2, TOLUA_CAST "region", 0, &tolua_err)) {
|
||||
region * target = (region *) tolua_tousertype(L, 2, 0);
|
||||
region *target = (region *) tolua_tousertype(L, 2, 0);
|
||||
if (target)
|
||||
ap = &target->attribs;
|
||||
} else if (tolua_isusertype(L, 2, TOLUA_CAST "ship", 0, &tolua_err)) {
|
||||
ship * target = (ship *) tolua_tousertype(L, 2, 0);
|
||||
ship *target = (ship *) tolua_tousertype(L, 2, 0);
|
||||
if (target)
|
||||
ap = &target->attribs;
|
||||
} else if (tolua_isusertype(L, 2, TOLUA_CAST "building", 0, &tolua_err)) {
|
||||
building * target = (building *) tolua_tousertype(L, 2, 0);
|
||||
building *target = (building *) tolua_tousertype(L, 2, 0);
|
||||
if (target)
|
||||
ap = &target->attribs;
|
||||
}
|
||||
|
@ -336,8 +336,8 @@ static int tolua_create_curse(lua_State * L)
|
|||
double vigour = tolua_tonumber(L, 4, 0);
|
||||
int duration = (int)tolua_tonumber(L, 5, 0);
|
||||
double effect = tolua_tonumber(L, 6, 0);
|
||||
int men = (int)tolua_tonumber(L, 7, 0); /* optional */
|
||||
curse * c = create_curse(u, ap, ctype, vigour, duration, effect, men);
|
||||
int men = (int)tolua_tonumber(L, 7, 0); /* optional */
|
||||
curse *c = create_curse(u, ap, ctype, vigour, duration, effect, men);
|
||||
if (c) {
|
||||
tolua_pushboolean(L, true);
|
||||
return 1;
|
||||
|
@ -348,9 +348,9 @@ static int tolua_create_curse(lua_State * L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_learn_skill(lua_State * L)
|
||||
static int tolua_learn_skill(lua_State * L)
|
||||
{
|
||||
unit * u = (unit *) tolua_tousertype(L, 1, 0);
|
||||
unit *u = (unit *) tolua_tousertype(L, 1, 0);
|
||||
const char *skname = tolua_tostring(L, 2, 0);
|
||||
float chances = (float)tolua_tonumber(L, 3, 0);
|
||||
skill_t sk = sk_find(skname);
|
||||
|
@ -360,34 +360,34 @@ static int tolua_learn_skill(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_update_scores(lua_State * L)
|
||||
static int tolua_update_scores(lua_State * L)
|
||||
{
|
||||
score();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_update_owners(lua_State * L)
|
||||
static int tolua_update_owners(lua_State * L)
|
||||
{
|
||||
region * r;
|
||||
region *r;
|
||||
for (r = regions; r; r = r->next) {
|
||||
update_owners(r);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_update_subscriptions(lua_State * L)
|
||||
static int tolua_update_subscriptions(lua_State * L)
|
||||
{
|
||||
update_subscriptions();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_remove_empty_units(lua_State * L)
|
||||
static int tolua_remove_empty_units(lua_State * L)
|
||||
{
|
||||
remove_empty_units();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_get_nmrs(lua_State * L)
|
||||
static int tolua_get_nmrs(lua_State * L)
|
||||
{
|
||||
int result = -1;
|
||||
int n = (int)tolua_tonumber(L, 1, 0);
|
||||
|
@ -401,15 +401,15 @@ static int tolua_get_nmrs(lua_State * L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_equipunit(lua_State * L)
|
||||
static int tolua_equipunit(lua_State * L)
|
||||
{
|
||||
unit * u = (unit *) tolua_tousertype(L, 1, 0);
|
||||
unit *u = (unit *) tolua_tousertype(L, 1, 0);
|
||||
const char *eqname = tolua_tostring(L, 2, 0);
|
||||
equip_unit(u, get_equipment(eqname));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_equipment_setitem(lua_State * L)
|
||||
static int tolua_equipment_setitem(lua_State * L)
|
||||
{
|
||||
int result = -1;
|
||||
const char *eqname = tolua_tostring(L, 1, 0);
|
||||
|
@ -426,30 +426,30 @@ static int tolua_equipment_setitem(lua_State * L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_spawn_braineaters(lua_State * L)
|
||||
static int tolua_spawn_braineaters(lua_State * L)
|
||||
{
|
||||
float chance = (float)tolua_tonumber(L, 1, 0);
|
||||
spawn_braineaters(chance);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_init_reports(lua_State * L)
|
||||
static int tolua_init_reports(lua_State * L)
|
||||
{
|
||||
int result = init_reports();
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_write_report(lua_State * L)
|
||||
static int tolua_write_report(lua_State * L)
|
||||
{
|
||||
faction * f = (faction *) tolua_tousertype(L, 1, 0);
|
||||
faction *f = (faction *) tolua_tousertype(L, 1, 0);
|
||||
time_t ltime = time(0);
|
||||
int result = write_reports(f, ltime);
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_write_reports(lua_State * L)
|
||||
static int tolua_write_reports(lua_State * L)
|
||||
{
|
||||
int result;
|
||||
init_reports();
|
||||
|
@ -458,13 +458,13 @@ static int tolua_write_reports(lua_State * L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static void reset_game(void)
|
||||
static void reset_game(void)
|
||||
{
|
||||
region * r;
|
||||
faction * f;
|
||||
region *r;
|
||||
faction *f;
|
||||
for (r = regions; r; r = r->next) {
|
||||
unit * u;
|
||||
building * b;
|
||||
unit *u;
|
||||
building *b;
|
||||
r->flags &= RF_SAVEMASK;
|
||||
for (u = r->units; u; u = u->next) {
|
||||
u->flags &= UFL_SAVEMASK;
|
||||
|
@ -473,10 +473,10 @@ static void reset_game(void)
|
|||
b->flags &= BLD_SAVEMASK;
|
||||
}
|
||||
if (r->land && r->land->ownership && r->land->ownership->owner) {
|
||||
faction * owner = r->land->ownership->owner;
|
||||
faction *owner = r->land->ownership->owner;
|
||||
if (owner == get_monsters()) {
|
||||
/* some compat-fix, i believe. */
|
||||
owner = update_owners(r);
|
||||
/* some compat-fix, i believe. */
|
||||
owner = update_owners(r);
|
||||
}
|
||||
if (owner) {
|
||||
fset(r, RF_GUARDED);
|
||||
|
@ -488,7 +488,7 @@ static void reset_game(void)
|
|||
}
|
||||
}
|
||||
|
||||
static int tolua_process_orders(lua_State * L)
|
||||
static int tolua_process_orders(lua_State * L)
|
||||
{
|
||||
++turn;
|
||||
reset_game();
|
||||
|
@ -496,7 +496,7 @@ static int tolua_process_orders(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_write_passwords(lua_State * L)
|
||||
static int tolua_write_passwords(lua_State * L)
|
||||
{
|
||||
int result = writepasswd();
|
||||
lua_pushnumber(L, (lua_Number) result);
|
||||
|
@ -504,13 +504,13 @@ static int tolua_write_passwords(lua_State * L)
|
|||
}
|
||||
|
||||
static struct summary *sum_begin = 0;
|
||||
static int tolua_init_summary(lua_State * L)
|
||||
static int tolua_init_summary(lua_State * L)
|
||||
{
|
||||
sum_begin = make_summary();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_write_summary(lua_State * L)
|
||||
static int tolua_write_summary(lua_State * L)
|
||||
{
|
||||
if (sum_begin) {
|
||||
struct summary *sum_end = make_summary();
|
||||
|
@ -521,13 +521,13 @@ static int tolua_write_summary(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_free_game(lua_State * L)
|
||||
static int tolua_free_game(lua_State * L)
|
||||
{
|
||||
free_gamedata();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_write_map(lua_State * L)
|
||||
static int tolua_write_map(lua_State * L)
|
||||
{
|
||||
const char *filename = tolua_tostring(L, 1, 0);
|
||||
if (filename) {
|
||||
|
@ -536,7 +536,7 @@ static int tolua_write_map(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_write_game(lua_State * L)
|
||||
static int tolua_write_game(lua_State * L)
|
||||
{
|
||||
const char *filename = tolua_tostring(L, 1, 0);
|
||||
const char *mode = tolua_tostring(L, 2, 0);
|
||||
|
@ -549,7 +549,7 @@ static int tolua_write_game(lua_State * L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_read_game(lua_State * L)
|
||||
static int tolua_read_game(lua_State * L)
|
||||
{
|
||||
const char *filename = tolua_tostring(L, 1, 0);
|
||||
const char *mode = tolua_tostring(L, 2, 0);
|
||||
|
@ -561,84 +561,84 @@ static int tolua_read_game(lua_State * L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_read_turn(lua_State * L)
|
||||
static int tolua_read_turn(lua_State * L)
|
||||
{
|
||||
int cturn = current_turn();
|
||||
tolua_pushnumber(L, (lua_Number) cturn);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_get_faction(lua_State * L)
|
||||
static int tolua_get_faction(lua_State * L)
|
||||
{
|
||||
int no = tolua_toid(L, 1, 0);
|
||||
faction * f = findfaction(no);
|
||||
faction *f = findfaction(no);
|
||||
tolua_pushusertype(L, f, TOLUA_CAST "faction");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_get_region(lua_State * L)
|
||||
static int tolua_get_region(lua_State * L)
|
||||
{
|
||||
int x = (int)tolua_tonumber(L, 1, 0);
|
||||
int y = (int)tolua_tonumber(L, 2, 0);
|
||||
region * r;
|
||||
region *r;
|
||||
assert(!pnormalize(&x, &y, findplane(x, y)));
|
||||
r = findregion(x, y);
|
||||
tolua_pushusertype(L, r, TOLUA_CAST "region");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_get_region_byid(lua_State * L)
|
||||
static int tolua_get_region_byid(lua_State * L)
|
||||
{
|
||||
int uid = (int)tolua_tonumber(L, 1, 0);
|
||||
region * r = findregionbyid(uid);
|
||||
region *r = findregionbyid(uid);
|
||||
tolua_pushusertype(L, r, TOLUA_CAST "region");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_get_building(lua_State * L)
|
||||
static int tolua_get_building(lua_State * L)
|
||||
{
|
||||
int no = tolua_toid(L, 1, 0);
|
||||
building * b = findbuilding(no);
|
||||
building *b = findbuilding(no);
|
||||
tolua_pushusertype(L, b, TOLUA_CAST "building");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_get_ship(lua_State * L)
|
||||
static int tolua_get_ship(lua_State * L)
|
||||
{
|
||||
int no = tolua_toid(L, 1, 0);
|
||||
ship * sh = findship(no);
|
||||
ship *sh = findship(no);
|
||||
tolua_pushusertype(L, sh, TOLUA_CAST "ship");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_get_alliance(lua_State * L)
|
||||
static int tolua_get_alliance(lua_State * L)
|
||||
{
|
||||
int no = tolua_toid(L, 1, 0);
|
||||
alliance * f = findalliance(no);
|
||||
alliance *f = findalliance(no);
|
||||
tolua_pushusertype(L, f, TOLUA_CAST "alliance");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_get_unit(lua_State * L)
|
||||
static int tolua_get_unit(lua_State * L)
|
||||
{
|
||||
int no = tolua_toid(L, 1, 0);
|
||||
unit * u = findunit(no);
|
||||
unit *u = findunit(no);
|
||||
tolua_pushusertype(L, u, TOLUA_CAST "unit");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_alliance_create(lua_State * L)
|
||||
static int tolua_alliance_create(lua_State * L)
|
||||
{
|
||||
int id = (int)tolua_tonumber(L, 1, 0);
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
alliance * alli = makealliance(id, name);
|
||||
alliance *alli = makealliance(id, name);
|
||||
tolua_pushusertype(L, alli, TOLUA_CAST "alliance");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_get_regions(lua_State * L)
|
||||
static int tolua_get_regions(lua_State * L)
|
||||
{
|
||||
region ** region_ptr = (region **) lua_newuserdata(L, sizeof(region *));
|
||||
region **region_ptr = (region **) lua_newuserdata(L, sizeof(region *));
|
||||
luaL_getmetatable(L, "region");
|
||||
lua_setmetatable(L, -2);
|
||||
*region_ptr = regions;
|
||||
|
@ -646,9 +646,9 @@ static int tolua_get_regions(lua_State * L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_get_factions(lua_State * L)
|
||||
static int tolua_get_factions(lua_State * L)
|
||||
{
|
||||
faction ** faction_ptr = (faction **) lua_newuserdata(L, sizeof(faction *));
|
||||
faction **faction_ptr = (faction **) lua_newuserdata(L, sizeof(faction *));
|
||||
luaL_getmetatable(L, "faction");
|
||||
lua_setmetatable(L, -2);
|
||||
*faction_ptr = factions;
|
||||
|
@ -656,48 +656,47 @@ static int tolua_get_factions(lua_State * L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_get_alliance_factions(lua_State * L)
|
||||
static int tolua_get_alliance_factions(lua_State * L)
|
||||
{
|
||||
alliance * self = (alliance *) tolua_tousertype(L, 1, 0);
|
||||
alliance *self = (alliance *) tolua_tousertype(L, 1, 0);
|
||||
return tolua_quicklist_push(L, "faction_list", "faction", self->members);
|
||||
}
|
||||
|
||||
static int tolua_get_alliance_id(lua_State * L)
|
||||
static int tolua_get_alliance_id(lua_State * L)
|
||||
{
|
||||
alliance * self = (alliance *) tolua_tousertype(L, 1, 0);
|
||||
alliance *self = (alliance *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number) self->id);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_get_alliance_name(lua_State * L)
|
||||
static int tolua_get_alliance_name(lua_State * L)
|
||||
{
|
||||
alliance * self = (alliance *) tolua_tousertype(L, 1, 0);
|
||||
alliance *self = (alliance *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, self->name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_set_alliance_name(lua_State * L)
|
||||
static int tolua_set_alliance_name(lua_State * L)
|
||||
{
|
||||
alliance * self = (alliance *) tolua_tousertype(L, 1, 0);
|
||||
alliance *self = (alliance *) tolua_tousertype(L, 1, 0);
|
||||
alliance_setname(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#include <libxml/tree.h>
|
||||
#include <util/functions.h>
|
||||
#include <util/xml.h>
|
||||
#include <kernel/spell.h>
|
||||
static int tolua_write_spells(lua_State * L)
|
||||
static int tolua_write_spells(lua_State * L)
|
||||
{
|
||||
spell_f fun = (spell_f) get_function("lua_castspell");
|
||||
const char *filename = "magic.xml";
|
||||
xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
|
||||
xmlNodePtr root = xmlNewNode(NULL, BAD_CAST "spells");
|
||||
quicklist * ql;
|
||||
quicklist *ql;
|
||||
int qi;
|
||||
for (ql = spells, qi = 0; ql; ql_advance(&ql, &qi, 1)) {
|
||||
spell * sp = (spell *) ql_get(ql, qi);
|
||||
spell *sp = (spell *) ql_get(ql, qi);
|
||||
if (sp->sp_function != fun) {
|
||||
int combat = 0;
|
||||
xmlNodePtr node = xmlNewNode(NULL, BAD_CAST "spell");
|
||||
|
@ -711,7 +710,7 @@ static int tolua_write_spells(lua_State * L)
|
|||
if (sp->parameter)
|
||||
xmlNewProp(node, BAD_CAST "parameters", BAD_CAST sp->parameter);
|
||||
if (sp->components) {
|
||||
spell_component * comp = sp->components;
|
||||
spell_component *comp = sp->components;
|
||||
for (; comp->type != 0; ++comp) {
|
||||
static const char *costs[] = { "fixed", "level", "linear" };
|
||||
xmlNodePtr cnode = xmlNewNode(NULL, BAD_CAST "resource");
|
||||
|
@ -737,10 +736,10 @@ static int tolua_write_spells(lua_State * L)
|
|||
}
|
||||
if (sp->sptyp & POSTCOMBATSPELL)
|
||||
combat = 3;
|
||||
|
||||
|
||||
else if (sp->sptyp & COMBATSPELL)
|
||||
combat = 2;
|
||||
|
||||
|
||||
else if (sp->sptyp & PRECOMBATSPELL)
|
||||
combat = 1;
|
||||
if (combat) {
|
||||
|
@ -756,20 +755,20 @@ static int tolua_write_spells(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int config_get_ships(lua_State * L)
|
||||
static int config_get_ships(lua_State * L)
|
||||
{
|
||||
quicklist * ql;
|
||||
quicklist *ql;
|
||||
int qi, i = 0;
|
||||
lua_createtable(L, ql_length(shiptypes), 0);
|
||||
for (qi = 0, ql = shiptypes; ql; ql_advance(&ql, &qi, 1)) {
|
||||
ship_type * stype = (ship_type *) ql_get(ql, qi);
|
||||
ship_type *stype = (ship_type *) ql_get(ql, qi);
|
||||
tolua_pushstring(L, TOLUA_CAST stype->name[0]);
|
||||
lua_rawseti(L, -2, ++i);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int config_get_locales(lua_State * L)
|
||||
static int config_get_locales(lua_State * L)
|
||||
{
|
||||
const struct locale *lang;
|
||||
int i = 0, n = 0;
|
||||
|
@ -783,7 +782,7 @@ static int config_get_locales(lua_State * L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int config_get_resource(lua_State * L)
|
||||
static int config_get_resource(lua_State * L)
|
||||
{
|
||||
const char *name = tolua_tostring(L, 1, 0);
|
||||
if (name) {
|
||||
|
@ -824,42 +823,42 @@ static int config_get_resource(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_get_spell_text(lua_State * L)
|
||||
static int tolua_get_spell_text(lua_State * L)
|
||||
{
|
||||
const struct locale *loc = default_locale;
|
||||
spell * self = (spell *) tolua_tousertype(L, 1, 0);
|
||||
spell *self = (spell *) tolua_tousertype(L, 1, 0);
|
||||
lua_pushstring(L, spell_info(self, loc));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_get_spell_school(lua_State * L)
|
||||
static int tolua_get_spell_school(lua_State * L)
|
||||
{
|
||||
spell * self = (spell *) tolua_tousertype(L, 1, 0);
|
||||
spell *self = (spell *) tolua_tousertype(L, 1, 0);
|
||||
lua_pushstring(L, magic_school[self->magietyp]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_get_spell_level(lua_State * L)
|
||||
static int tolua_get_spell_level(lua_State * L)
|
||||
{
|
||||
spell * self = (spell *) tolua_tousertype(L, 1, 0);
|
||||
spell *self = (spell *) tolua_tousertype(L, 1, 0);
|
||||
lua_pushnumber(L, self->level);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_get_spell_name(lua_State * L)
|
||||
static int tolua_get_spell_name(lua_State * L)
|
||||
{
|
||||
const struct locale *lang = default_locale;
|
||||
spell * self = (spell *) tolua_tousertype(L, 1, 0);
|
||||
spell *self = (spell *) tolua_tousertype(L, 1, 0);
|
||||
lua_pushstring(L, spell_name(self, lang));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_get_spells(lua_State * L)
|
||||
static int tolua_get_spells(lua_State * L)
|
||||
{
|
||||
return tolua_quicklist_push(L, "spell_list", "spell", spells);
|
||||
}
|
||||
|
||||
int tolua_read_xml(lua_State * L)
|
||||
int tolua_read_xml(lua_State * L)
|
||||
{
|
||||
const char *filename = tolua_tostring(L, 1, 0);
|
||||
const char *catalog = tolua_tostring(L, 2, 0);
|
||||
|
@ -867,15 +866,15 @@ int tolua_read_xml(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int tolua_process_markets(lua_State * L)
|
||||
int tolua_process_markets(lua_State * L)
|
||||
{
|
||||
do_markets();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tolua_process_produce(lua_State * L)
|
||||
int tolua_process_produce(lua_State * L)
|
||||
{
|
||||
region * r;
|
||||
region *r;
|
||||
for (r = regions; r; r = r->next) {
|
||||
produce(r);
|
||||
}
|
||||
|
@ -884,19 +883,19 @@ int tolua_process_produce(lua_State * L)
|
|||
|
||||
typedef struct event_args {
|
||||
int hfunction;
|
||||
int hargs;
|
||||
const char *sendertype;
|
||||
int hargs;
|
||||
const char *sendertype;
|
||||
} event_args;
|
||||
|
||||
static void args_free(void *udata)
|
||||
static void args_free(void *udata)
|
||||
{
|
||||
free(udata);
|
||||
}
|
||||
|
||||
static void event_cb(void *sender, const char *event, void *udata)
|
||||
static void event_cb(void *sender, const char *event, void *udata)
|
||||
{
|
||||
lua_State * L = (lua_State *) global.vm_state;
|
||||
event_args * args = (event_args *) udata;
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
event_args *args = (event_args *) udata;
|
||||
int nargs = 2;
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, args->hfunction);
|
||||
if (sender && args->sendertype) {
|
||||
|
@ -917,12 +916,12 @@ static void event_cb(void *sender, const char *event, void *udata)
|
|||
* 2: event (string)
|
||||
* 3: handler (function)
|
||||
* 4: arguments (any, *optional*)
|
||||
**/
|
||||
static int tolua_eventbus_register(lua_State * L)
|
||||
**/
|
||||
static int tolua_eventbus_register(lua_State * L)
|
||||
{
|
||||
void *sender = tolua_tousertype(L, 1, 0);
|
||||
const char *event = tolua_tostring(L, 2, 0);
|
||||
event_args * args = malloc(sizeof(event_args));
|
||||
event_args *args = malloc(sizeof(event_args));
|
||||
args->sendertype = sender ? tolua_typename(L, 1) : NULL;
|
||||
lua_pushvalue(L, 3);
|
||||
args->hfunction = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
|
@ -936,7 +935,7 @@ static int tolua_eventbus_register(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_eventbus_fire(lua_State * L)
|
||||
static int tolua_eventbus_fire(lua_State * L)
|
||||
{
|
||||
void *sender = tolua_tousertype(L, 1, 0);
|
||||
const char *event = tolua_tostring(L, 2, 0);
|
||||
|
@ -945,24 +944,24 @@ static int tolua_eventbus_fire(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_report_unit(lua_State * L)
|
||||
static int tolua_report_unit(lua_State * L)
|
||||
{
|
||||
char buffer[512];
|
||||
unit * u = (unit *) tolua_tousertype(L, 1, 0);
|
||||
faction * f = (faction *) tolua_tousertype(L, 2, 0);
|
||||
unit *u = (unit *) tolua_tousertype(L, 1, 0);
|
||||
faction *f = (faction *) tolua_tousertype(L, 2, 0);
|
||||
bufunit(f, u, 0, see_unit, buffer, sizeof(buffer));
|
||||
tolua_pushstring(L, buffer);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_settings_get(lua_State * L)
|
||||
static int tolua_settings_get(lua_State * L)
|
||||
{
|
||||
const char *name = tolua_tostring(L, 1, 0);
|
||||
tolua_pushstring(L, get_param(global.parameters, name));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_settings_set(lua_State * L)
|
||||
static int tolua_settings_set(lua_State * L)
|
||||
{
|
||||
const char *name = tolua_tostring(L, 1, 0);
|
||||
const char *value = tolua_tostring(L, 2, 0);
|
||||
|
@ -970,8 +969,7 @@ static int tolua_settings_set(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
parse_inifile(lua_State * L, dictionary * d, const char *section)
|
||||
static void parse_inifile(lua_State * L, dictionary * d, const char *section)
|
||||
{
|
||||
int i;
|
||||
size_t len = strlen(section);
|
||||
|
@ -990,18 +988,18 @@ parse_inifile(lua_State * L, dictionary * d, const char *section)
|
|||
lua_rawset(L, -3);
|
||||
}
|
||||
}
|
||||
|
||||
/* special case */
|
||||
lua_pushstring(L, "basepath");
|
||||
|
||||
/* special case */
|
||||
lua_pushstring(L, "basepath");
|
||||
lua_pushstring(L, basepath());
|
||||
lua_rawset(L, -3);
|
||||
}
|
||||
|
||||
int tolua_eressea_open(lua_State * L)
|
||||
int tolua_eressea_open(lua_State * L)
|
||||
{
|
||||
tolua_open(L);
|
||||
|
||||
/* register user types */
|
||||
|
||||
/* register user types */
|
||||
tolua_usertype(L, TOLUA_CAST "spell");
|
||||
tolua_usertype(L, TOLUA_CAST "spell_list");
|
||||
tolua_usertype(L, TOLUA_CAST "order");
|
||||
|
@ -1029,7 +1027,8 @@ int tolua_eressea_open(lua_State * L)
|
|||
NULL);
|
||||
tolua_function(L, TOLUA_CAST "create", tolua_alliance_create);
|
||||
} tolua_endmodule(L);
|
||||
tolua_cclass(L, TOLUA_CAST "spell", TOLUA_CAST "spell", TOLUA_CAST "", NULL);
|
||||
tolua_cclass(L, TOLUA_CAST "spell", TOLUA_CAST "spell", TOLUA_CAST "",
|
||||
NULL);
|
||||
tolua_beginmodule(L, TOLUA_CAST "spell");
|
||||
{
|
||||
tolua_function(L, TOLUA_CAST "__tostring", tolua_get_spell_name);
|
||||
|
@ -1088,11 +1087,10 @@ int tolua_eressea_open(lua_State * L)
|
|||
tolua_function(L, TOLUA_CAST "message_unit", tolua_message_unit);
|
||||
tolua_function(L, TOLUA_CAST "message_faction", tolua_message_faction);
|
||||
tolua_function(L, TOLUA_CAST "message_region", tolua_message_region);
|
||||
|
||||
/* scripted monsters */
|
||||
tolua_function(L, TOLUA_CAST "spawn_braineaters",
|
||||
tolua_spawn_braineaters);
|
||||
|
||||
|
||||
/* scripted monsters */
|
||||
tolua_function(L, TOLUA_CAST "spawn_braineaters", tolua_spawn_braineaters);
|
||||
|
||||
tolua_function(L, TOLUA_CAST "update_guards", tolua_update_guards);
|
||||
tolua_function(L, TOLUA_CAST "set_turn", &tolua_set_turn);
|
||||
tolua_function(L, TOLUA_CAST "get_turn", &tolua_get_turn);
|
||||
|
@ -1104,8 +1102,10 @@ int tolua_eressea_open(lua_State * L)
|
|||
tolua_function(L, TOLUA_CAST "itoa36", tolua_itoa36);
|
||||
tolua_function(L, TOLUA_CAST "dice_roll", tolua_dice_rand);
|
||||
tolua_function(L, TOLUA_CAST "get_nmrs", tolua_get_nmrs);
|
||||
tolua_function(L, TOLUA_CAST "remove_empty_units", tolua_remove_empty_units);
|
||||
tolua_function(L, TOLUA_CAST "update_subscriptions", tolua_update_subscriptions);
|
||||
tolua_function(L, TOLUA_CAST "remove_empty_units",
|
||||
tolua_remove_empty_units);
|
||||
tolua_function(L, TOLUA_CAST "update_subscriptions",
|
||||
tolua_update_subscriptions);
|
||||
tolua_function(L, TOLUA_CAST "update_scores", tolua_update_scores);
|
||||
tolua_function(L, TOLUA_CAST "update_owners", tolua_update_owners);
|
||||
tolua_function(L, TOLUA_CAST "learn_skill", tolua_learn_skill);
|
||||
|
|
|
@ -124,14 +124,15 @@ static void recruit_init(void)
|
|||
int income(const unit * u)
|
||||
{
|
||||
switch (old_race(u->race)) {
|
||||
case RC_FIREDRAGON:
|
||||
return 150 * u->number;
|
||||
case RC_DRAGON:
|
||||
return 1000 * u->number;
|
||||
case RC_WYRM:
|
||||
return 5000 * u->number;
|
||||
case RC_FIREDRAGON:
|
||||
return 150 * u->number;
|
||||
case RC_DRAGON:
|
||||
return 1000 * u->number;
|
||||
case RC_WYRM:
|
||||
return 5000 * u->number;
|
||||
default:
|
||||
return 20 * u->number;
|
||||
}
|
||||
return 20 * u->number;
|
||||
}
|
||||
|
||||
static void scramble(void *data, int n, size_t width)
|
||||
|
@ -356,8 +357,7 @@ static int do_recruiting(recruitment * recruits, int available)
|
|||
|
||||
number = MIN(req->qty, (int)(get / multi));
|
||||
if (rc->recruitcost) {
|
||||
int afford =
|
||||
get_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT,
|
||||
int afford = get_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT,
|
||||
number * rc->recruitcost) / rc->recruitcost;
|
||||
number = MIN(number, afford);
|
||||
use_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT,
|
||||
|
@ -1297,22 +1297,22 @@ static int recruit_archetype(unit * u, order * ord)
|
|||
return n;
|
||||
} else
|
||||
switch (n) {
|
||||
case ENOMATERIALS:
|
||||
ADDMSG(&u->faction->msgs, msg_materials_required(u, ord, arch->ctype,
|
||||
want));
|
||||
break;
|
||||
case ELOWSKILL:
|
||||
case ENEEDSKILL:
|
||||
/* no skill, or not enough skill points to build */
|
||||
cmistake(u, ord, 50, MSG_PRODUCE);
|
||||
break;
|
||||
case EBUILDINGREQ:
|
||||
ADDMSG(&u->faction->msgs,
|
||||
msg_feedback(u, u->thisorder, "building_needed", "building",
|
||||
arch->ctype->btype->_name));
|
||||
break;
|
||||
default:
|
||||
assert(!"unhandled return value from build() in recruit_archetype");
|
||||
case ENOMATERIALS:
|
||||
ADDMSG(&u->faction->msgs, msg_materials_required(u, ord, arch->ctype,
|
||||
want));
|
||||
break;
|
||||
case ELOWSKILL:
|
||||
case ENEEDSKILL:
|
||||
/* no skill, or not enough skill points to build */
|
||||
cmistake(u, ord, 50, MSG_PRODUCE);
|
||||
break;
|
||||
case EBUILDINGREQ:
|
||||
ADDMSG(&u->faction->msgs,
|
||||
msg_feedback(u, u->thisorder, "building_needed", "building",
|
||||
arch->ctype->btype->_name));
|
||||
break;
|
||||
default:
|
||||
assert(!"unhandled return value from build() in recruit_archetype");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1340,27 +1340,21 @@ void economics(region * r)
|
|||
boolean destroyed = false;
|
||||
if (u->number > 0) {
|
||||
for (ord = u->orders; ord; ord = ord->next) {
|
||||
switch (get_keyword(ord)) {
|
||||
case K_DESTROY:
|
||||
if (!destroyed) {
|
||||
if (destroy_cmd(u, ord) != 0)
|
||||
ord = NULL;
|
||||
destroyed = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case K_GIVE:
|
||||
case K_LIEFERE:
|
||||
give_cmd(u, ord);
|
||||
break;
|
||||
|
||||
case K_FORGET:
|
||||
forget_cmd(u, ord);
|
||||
break;
|
||||
|
||||
keyword_t kwd = get_keyword(ord);
|
||||
if (kwd == K_DESTROY) {
|
||||
if (!destroyed) {
|
||||
if (destroy_cmd(u, ord) != 0)
|
||||
ord = NULL;
|
||||
destroyed = true;
|
||||
}
|
||||
} else if (kwd == K_GIVE || kwd == K_LIEFERE) {
|
||||
give_cmd(u, ord);
|
||||
} else if (kwd == K_FORGET) {
|
||||
forget_cmd(u, ord);
|
||||
}
|
||||
if (u->orders == NULL)
|
||||
if (u->orders == NULL) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1418,24 +1412,24 @@ static void manufacture(unit * u, const item_type * itype, int want)
|
|||
}
|
||||
n = build(u, itype->construction, 0, want);
|
||||
switch (n) {
|
||||
case ENEEDSKILL:
|
||||
ADDMSG(&u->faction->msgs,
|
||||
msg_feedback(u, u->thisorder, "skill_needed", "skill", sk));
|
||||
return;
|
||||
case EBUILDINGREQ:
|
||||
ADDMSG(&u->faction->msgs,
|
||||
msg_feedback(u, u->thisorder, "building_needed", "building",
|
||||
itype->construction->btype->_name));
|
||||
return;
|
||||
case ELOWSKILL:
|
||||
ADDMSG(&u->faction->msgs,
|
||||
msg_feedback(u, u->thisorder, "manufacture_skills",
|
||||
"skill minskill product", sk, minskill, itype->rtype, 1));
|
||||
return;
|
||||
case ENOMATERIALS:
|
||||
ADDMSG(&u->faction->msgs, msg_materials_required(u, u->thisorder,
|
||||
itype->construction, want));
|
||||
return;
|
||||
case ENEEDSKILL:
|
||||
ADDMSG(&u->faction->msgs,
|
||||
msg_feedback(u, u->thisorder, "skill_needed", "skill", sk));
|
||||
return;
|
||||
case EBUILDINGREQ:
|
||||
ADDMSG(&u->faction->msgs,
|
||||
msg_feedback(u, u->thisorder, "building_needed", "building",
|
||||
itype->construction->btype->_name));
|
||||
return;
|
||||
case ELOWSKILL:
|
||||
ADDMSG(&u->faction->msgs,
|
||||
msg_feedback(u, u->thisorder, "manufacture_skills",
|
||||
"skill minskill product", sk, minskill, itype->rtype, 1));
|
||||
return;
|
||||
case ENOMATERIALS:
|
||||
ADDMSG(&u->faction->msgs, msg_materials_required(u, u->thisorder,
|
||||
itype->construction, want));
|
||||
return;
|
||||
}
|
||||
if (n > 0) {
|
||||
i_change(&u->items, itype, n);
|
||||
|
@ -1829,33 +1823,33 @@ static void create_potion(unit * u, const potion_type * ptype, int want)
|
|||
}
|
||||
built = build(u, ptype->itype->construction, 0, want);
|
||||
switch (built) {
|
||||
case ELOWSKILL:
|
||||
case ENEEDSKILL:
|
||||
/* no skill, or not enough skill points to build */
|
||||
cmistake(u, u->thisorder, 50, MSG_PRODUCE);
|
||||
break;
|
||||
case EBUILDINGREQ:
|
||||
ADDMSG(&u->faction->msgs,
|
||||
msg_feedback(u, u->thisorder, "building_needed", "building",
|
||||
ptype->itype->construction->btype->_name));
|
||||
break;
|
||||
case ECOMPLETE:
|
||||
assert(0);
|
||||
break;
|
||||
case ENOMATERIALS:
|
||||
/* something missing from the list of materials */
|
||||
ADDMSG(&u->faction->msgs, msg_materials_required(u, u->thisorder,
|
||||
ptype->itype->construction, want));
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
i_change(&u->items, ptype->itype, built);
|
||||
if (want == INT_MAX)
|
||||
want = built;
|
||||
ADDMSG(&u->faction->msgs, msg_message("manufacture",
|
||||
"unit region amount wanted resource", u, u->region, built, want,
|
||||
ptype->itype->rtype));
|
||||
break;
|
||||
case ELOWSKILL:
|
||||
case ENEEDSKILL:
|
||||
/* no skill, or not enough skill points to build */
|
||||
cmistake(u, u->thisorder, 50, MSG_PRODUCE);
|
||||
break;
|
||||
case EBUILDINGREQ:
|
||||
ADDMSG(&u->faction->msgs,
|
||||
msg_feedback(u, u->thisorder, "building_needed", "building",
|
||||
ptype->itype->construction->btype->_name));
|
||||
break;
|
||||
case ECOMPLETE:
|
||||
assert(0);
|
||||
break;
|
||||
case ENOMATERIALS:
|
||||
/* something missing from the list of materials */
|
||||
ADDMSG(&u->faction->msgs, msg_materials_required(u, u->thisorder,
|
||||
ptype->itype->construction, want));
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
i_change(&u->items, ptype->itype, built);
|
||||
if (want == INT_MAX)
|
||||
want = built;
|
||||
ADDMSG(&u->faction->msgs, msg_message("manufacture",
|
||||
"unit region amount wanted resource", u, u->region, built, want,
|
||||
ptype->itype->rtype));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2862,26 +2856,25 @@ static void breed_cmd(unit * u, struct order *ord)
|
|||
}
|
||||
|
||||
switch (p) {
|
||||
case P_HERBS:
|
||||
plant(r, u, m);
|
||||
break;
|
||||
case P_TREES:
|
||||
breedtrees(r, u, m);
|
||||
break;
|
||||
default:
|
||||
if (p != P_ANY) {
|
||||
rtype = findresourcetype(s, u->faction->locale);
|
||||
if (rtype == rt_mallornseed || rtype == rt_seed) {
|
||||
breedtrees(r, u, m);
|
||||
break;
|
||||
} else if (rtype != oldresourcetype[R_HORSE]) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_cannotmake",
|
||||
""));
|
||||
break;
|
||||
}
|
||||
case P_HERBS:
|
||||
plant(r, u, m);
|
||||
break;
|
||||
case P_TREES:
|
||||
breedtrees(r, u, m);
|
||||
break;
|
||||
default:
|
||||
if (p != P_ANY) {
|
||||
rtype = findresourcetype(s, u->faction->locale);
|
||||
if (rtype == rt_mallornseed || rtype == rt_seed) {
|
||||
breedtrees(r, u, m);
|
||||
break;
|
||||
} else if (rtype != oldresourcetype[R_HORSE]) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_cannotmake", ""));
|
||||
break;
|
||||
}
|
||||
breedhorses(r, u);
|
||||
break;
|
||||
}
|
||||
breedhorses(r, u);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3446,17 +3439,15 @@ void produce(struct region *r)
|
|||
}
|
||||
|
||||
for (ord = u->orders; ord; ord = ord->next) {
|
||||
switch (get_keyword(ord)) {
|
||||
case K_BUY:
|
||||
buy(u, &buyorders, ord);
|
||||
trader = true;
|
||||
break;
|
||||
case K_SELL:
|
||||
/* sell returns true if the sale is not limited
|
||||
* by the region limit */
|
||||
limited &= !sell(u, &sellorders, ord);
|
||||
trader = true;
|
||||
break;
|
||||
keyword_t kwd = get_keyword(ord);
|
||||
if (kwd == K_BUY) {
|
||||
buy(u, &buyorders, ord);
|
||||
trader = true;
|
||||
} else if (kwd == K_SELL) {
|
||||
/* sell returns true if the sale is not limited
|
||||
* by the region limit */
|
||||
limited &= !sell(u, &sellorders, ord);
|
||||
trader = true;
|
||||
}
|
||||
}
|
||||
if (trader) {
|
||||
|
@ -3479,41 +3470,41 @@ void produce(struct region *r)
|
|||
|
||||
switch (todo) {
|
||||
|
||||
case K_ENTERTAIN:
|
||||
entertain_cmd(u, u->thisorder);
|
||||
break;
|
||||
case K_ENTERTAIN:
|
||||
entertain_cmd(u, u->thisorder);
|
||||
break;
|
||||
|
||||
case K_WORK:
|
||||
if (!rule_autowork && do_work(u, u->thisorder, nextworker) == 0) {
|
||||
assert(nextworker - workers < MAX_WORKERS);
|
||||
++nextworker;
|
||||
}
|
||||
break;
|
||||
case K_WORK:
|
||||
if (!rule_autowork && do_work(u, u->thisorder, nextworker) == 0) {
|
||||
assert(nextworker - workers < MAX_WORKERS);
|
||||
++nextworker;
|
||||
}
|
||||
break;
|
||||
|
||||
case K_TAX:
|
||||
tax_cmd(u, u->thisorder, &taxorders);
|
||||
break;
|
||||
case K_TAX:
|
||||
tax_cmd(u, u->thisorder, &taxorders);
|
||||
break;
|
||||
|
||||
case K_STEAL:
|
||||
steal_cmd(u, u->thisorder, &stealorders);
|
||||
break;
|
||||
case K_STEAL:
|
||||
steal_cmd(u, u->thisorder, &stealorders);
|
||||
break;
|
||||
|
||||
case K_SPY:
|
||||
spy_cmd(u, u->thisorder);
|
||||
break;
|
||||
case K_SPY:
|
||||
spy_cmd(u, u->thisorder);
|
||||
break;
|
||||
|
||||
case K_SABOTAGE:
|
||||
sabotage_cmd(u, u->thisorder);
|
||||
break;
|
||||
case K_SABOTAGE:
|
||||
sabotage_cmd(u, u->thisorder);
|
||||
break;
|
||||
|
||||
case K_PLANT:
|
||||
case K_BREED:
|
||||
breed_cmd(u, u->thisorder);
|
||||
break;
|
||||
case K_PLANT:
|
||||
case K_BREED:
|
||||
breed_cmd(u, u->thisorder);
|
||||
break;
|
||||
|
||||
case K_RESEARCH:
|
||||
research_cmd(u, u->thisorder);
|
||||
break;
|
||||
case K_RESEARCH:
|
||||
research_cmd(u, u->thisorder);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
1415
src/gamecode/laws.c
1415
src/gamecode/laws.c
File diff suppressed because it is too large
Load diff
|
@ -104,9 +104,7 @@ boolean is_migrant(unit * u)
|
|||
/* ------------------------------------------------------------- */
|
||||
boolean magic_lowskill(unit * u)
|
||||
{
|
||||
if (u->race == new_race[RC_TOAD])
|
||||
return true;
|
||||
return false;
|
||||
return (u->race == new_race[RC_TOAD]) ? true : false;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
|
@ -121,23 +119,22 @@ int study_cost(unit * u, skill_t sk)
|
|||
sprintf(buffer, "skills.cost.%s", skillnames[sk]);
|
||||
cost[sk] = get_param_int(global.parameters, buffer, -1);
|
||||
}
|
||||
if (cost[sk] >= 0)
|
||||
if (cost[sk] >= 0) {
|
||||
return cost[sk];
|
||||
|
||||
}
|
||||
switch (sk) {
|
||||
case SK_SPY:
|
||||
return 100;
|
||||
break;
|
||||
case SK_TACTICS:
|
||||
case SK_HERBALISM:
|
||||
case SK_ALCHEMY:
|
||||
return 200;
|
||||
break;
|
||||
case SK_MAGIC: /* Die Magiekosten betragen 50+Summe(50*Stufe) */
|
||||
/* 'Stufe' ist dabei die nächste zu erreichende Stufe */
|
||||
stufe = 1 + get_level(u, SK_MAGIC);
|
||||
return k * (1 + ((stufe + 1) * stufe / 2));
|
||||
break;
|
||||
case SK_SPY:
|
||||
return 100;
|
||||
case SK_TACTICS:
|
||||
case SK_HERBALISM:
|
||||
case SK_ALCHEMY:
|
||||
return 200;
|
||||
case SK_MAGIC: /* Die Magiekosten betragen 50+Summe(50*Stufe) */
|
||||
/* 'Stufe' ist dabei die nächste zu erreichende Stufe */
|
||||
stufe = 1 + get_level(u, SK_MAGIC);
|
||||
return k * (1 + ((stufe + 1) * stufe / 2));
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -951,19 +951,19 @@ build_building(unit * u, const building_type * btype, int want, order * ord)
|
|||
built = build(u, btype->construction, built, n);
|
||||
|
||||
switch (built) {
|
||||
case ECOMPLETE:
|
||||
/* the building is already complete */
|
||||
cmistake(u, ord, 4, MSG_PRODUCE);
|
||||
return;
|
||||
case ENOMATERIALS:
|
||||
ADDMSG(&u->faction->msgs, msg_materials_required(u, ord,
|
||||
btype->construction, want));
|
||||
return;
|
||||
case ELOWSKILL:
|
||||
case ENEEDSKILL:
|
||||
/* no skill, or not enough skill points to build */
|
||||
cmistake(u, ord, 50, MSG_PRODUCE);
|
||||
return;
|
||||
case ECOMPLETE:
|
||||
/* the building is already complete */
|
||||
cmistake(u, ord, 4, MSG_PRODUCE);
|
||||
return;
|
||||
case ENOMATERIALS:
|
||||
ADDMSG(&u->faction->msgs, msg_materials_required(u, ord,
|
||||
btype->construction, want));
|
||||
return;
|
||||
case ELOWSKILL:
|
||||
case ENEEDSKILL:
|
||||
/* no skill, or not enough skill points to build */
|
||||
cmistake(u, ord, 50, MSG_PRODUCE);
|
||||
return;
|
||||
}
|
||||
|
||||
/* at this point, the building size is increased. */
|
||||
|
@ -1324,10 +1324,9 @@ void do_misc(region * r, boolean lasttry)
|
|||
for (uc = r->units; uc; uc = uc->next) {
|
||||
order *ord;
|
||||
for (ord = uc->orders; ord; ord = ord->next) {
|
||||
switch (get_keyword(ord)) {
|
||||
case K_CONTACT:
|
||||
contact_cmd(uc, ord, lasttry);
|
||||
break;
|
||||
keyword_t kwd = get_keyword(ord);
|
||||
if (kwd == K_CONTACT) {
|
||||
contact_cmd(uc, ord, lasttry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1349,37 +1348,37 @@ void do_misc(region * r, boolean lasttry)
|
|||
id = getid();
|
||||
|
||||
switch (p) {
|
||||
case P_BUILDING:
|
||||
case P_GEBAEUDE:
|
||||
if (u->building && u->building->no == id)
|
||||
break;
|
||||
if (enter_building(u, ord, id, lasttry)) {
|
||||
unit *ub;
|
||||
for (ub = u; ub; ub = ub->next) {
|
||||
if (ub->building == u->building) {
|
||||
ulast = ub;
|
||||
}
|
||||
case P_BUILDING:
|
||||
case P_GEBAEUDE:
|
||||
if (u->building && u->building->no == id)
|
||||
break;
|
||||
if (enter_building(u, ord, id, lasttry)) {
|
||||
unit *ub;
|
||||
for (ub = u; ub; ub = ub->next) {
|
||||
if (ub->building == u->building) {
|
||||
ulast = ub;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case P_SHIP:
|
||||
if (u->ship && u->ship->no == id)
|
||||
break;
|
||||
if (enter_ship(u, ord, id, lasttry)) {
|
||||
unit *ub;
|
||||
ulast = u;
|
||||
for (ub = u; ub; ub = ub->next) {
|
||||
if (ub->ship == u->ship) {
|
||||
ulast = ub;
|
||||
}
|
||||
case P_SHIP:
|
||||
if (u->ship && u->ship->no == id)
|
||||
break;
|
||||
if (enter_ship(u, ord, id, lasttry)) {
|
||||
unit *ub;
|
||||
ulast = u;
|
||||
for (ub = u; ub; ub = ub->next) {
|
||||
if (ub->ship == u->ship) {
|
||||
ulast = ub;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (lasttry)
|
||||
cmistake(u, ord, 79, MSG_MOVE);
|
||||
default:
|
||||
if (lasttry)
|
||||
cmistake(u, ord, 79, MSG_MOVE);
|
||||
|
||||
}
|
||||
if (ulast != NULL) {
|
||||
|
|
|
@ -587,15 +587,11 @@ int skill_limit(faction * f, skill_t sk)
|
|||
return fl;
|
||||
}
|
||||
}
|
||||
switch (sk) {
|
||||
case SK_MAGIC:
|
||||
m = max_magicians(f);
|
||||
break;
|
||||
case SK_ALCHEMY:
|
||||
m =
|
||||
get_param_int(global.parameters, "rules.maxskills.alchemy",
|
||||
MAXALCHEMISTS);
|
||||
break;
|
||||
if (sk == SK_MAGIC) {
|
||||
m = max_magicians(f);
|
||||
} else if (sk == SK_ALCHEMY) {
|
||||
m = get_param_int(global.parameters, "rules.maxskills.alchemy",
|
||||
MAXALCHEMISTS);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
@ -607,8 +603,9 @@ int count_skill(faction * f, skill_t sk)
|
|||
|
||||
for (u = f->units; u; u = u->nextF) {
|
||||
if (has_skill(u, sk)) {
|
||||
if (!is_familiar(u))
|
||||
if (!is_familiar(u)) {
|
||||
n += u->number;
|
||||
}
|
||||
}
|
||||
}
|
||||
return n;
|
||||
|
@ -1585,14 +1582,15 @@ static int read_newunitid(const faction * f, const region * r)
|
|||
int read_unitid(const faction * f, const region * r)
|
||||
{
|
||||
const char *s = getstrtoken();
|
||||
param_t param;
|
||||
|
||||
/* Da s nun nur einen string enthaelt, suchen wir ihn direkt in der
|
||||
* paramliste. machen wir das nicht, dann wird getnewunit in s nach der
|
||||
* nummer suchen, doch dort steht bei temp-units nur "temp" drinnen! */
|
||||
|
||||
switch (findparam(s, f->locale)) {
|
||||
case P_TEMP:
|
||||
return read_newunitid(f, r);
|
||||
param = findparam(s, f->locale);
|
||||
if (param == P_TEMP) {
|
||||
return read_newunitid(f, r);
|
||||
}
|
||||
if (!s || *s == 0)
|
||||
return -1;
|
||||
|
@ -2492,16 +2490,19 @@ unsigned int guard_flags(const unit * u)
|
|||
flags |= GUARD_RECRUIT;
|
||||
#endif
|
||||
switch (old_race(u->race)) {
|
||||
case RC_ELF:
|
||||
if (u->faction->race != u->race)
|
||||
break;
|
||||
/* else fallthrough */
|
||||
case RC_TREEMAN:
|
||||
flags |= GUARD_TREES;
|
||||
break;
|
||||
case RC_IRONKEEPER:
|
||||
flags = GUARD_MINING;
|
||||
case RC_ELF:
|
||||
if (u->faction->race != u->race)
|
||||
break;
|
||||
/* else fallthrough */
|
||||
case RC_TREEMAN:
|
||||
flags |= GUARD_TREES;
|
||||
break;
|
||||
case RC_IRONKEEPER:
|
||||
flags = GUARD_MINING;
|
||||
break;
|
||||
default:
|
||||
/* TODO: This should be configuration variables, all of it */
|
||||
break;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
@ -2932,11 +2933,11 @@ message *movement_error(unit * u, const char *token, order * ord,
|
|||
{
|
||||
direction_t d;
|
||||
switch (error_code) {
|
||||
case E_MOVE_BLOCKED:
|
||||
d = finddirection(token, u->faction->locale);
|
||||
return msg_message("moveblocked", "unit direction", u, d);
|
||||
case E_MOVE_NOREGION:
|
||||
return msg_feedback(u, ord, "unknowndirection", "dirname", token);
|
||||
case E_MOVE_BLOCKED:
|
||||
d = finddirection(token, u->faction->locale);
|
||||
return msg_message("moveblocked", "unit direction", u, d);
|
||||
case E_MOVE_NOREGION:
|
||||
return msg_feedback(u, ord, "unknowndirection", "dirname", token);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
@ -2953,24 +2954,24 @@ int movewhere(const unit * u, const char *token, region * r, region ** resultp)
|
|||
|
||||
d = finddirection(token, u->faction->locale);
|
||||
switch (d) {
|
||||
case D_PAUSE:
|
||||
*resultp = r;
|
||||
break;
|
||||
case D_PAUSE:
|
||||
*resultp = r;
|
||||
break;
|
||||
|
||||
case NODIRECTION:
|
||||
r2 = find_special_direction(r, token, u->faction->locale);
|
||||
if (r2 == NULL) {
|
||||
return E_MOVE_NOREGION;
|
||||
}
|
||||
*resultp = r2;
|
||||
break;
|
||||
case NODIRECTION:
|
||||
r2 = find_special_direction(r, token, u->faction->locale);
|
||||
if (r2 == NULL) {
|
||||
return E_MOVE_NOREGION;
|
||||
}
|
||||
*resultp = r2;
|
||||
break;
|
||||
|
||||
default:
|
||||
r2 = rconnect(r, d);
|
||||
if (r2 == NULL || move_blocked(u, r, r2)) {
|
||||
return E_MOVE_BLOCKED;
|
||||
}
|
||||
*resultp = r2;
|
||||
default:
|
||||
r2 = rconnect(r, d);
|
||||
if (r2 == NULL || move_blocked(u, r, r2)) {
|
||||
return E_MOVE_BLOCKED;
|
||||
}
|
||||
*resultp = r2;
|
||||
}
|
||||
return E_MOVE_OK;
|
||||
}
|
||||
|
|
|
@ -985,13 +985,13 @@ cancast(unit * u, const spell * sp, int level, int range, struct order * ord)
|
|||
/* sind die Kosten stufenabhängig, so muss itemanz noch mit dem
|
||||
* level multipliziert werden */
|
||||
switch (sp->components[k].cost) {
|
||||
case SPC_LEVEL:
|
||||
case SPC_LINEAR:
|
||||
itemanz *= level;
|
||||
break;
|
||||
case SPC_FIX:
|
||||
default:
|
||||
break;
|
||||
case SPC_LEVEL:
|
||||
case SPC_LINEAR:
|
||||
itemanz *= level;
|
||||
break;
|
||||
case SPC_FIX:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
itemhave = get_pooled(u, rtype, GET_DEFAULT, itemanz);
|
||||
|
@ -1206,48 +1206,48 @@ target_resists_magic(unit * magician, void *obj, int objtyp, int t_bonus)
|
|||
return true;
|
||||
|
||||
switch (objtyp) {
|
||||
case TYP_UNIT:
|
||||
{
|
||||
int at, pa = 0;
|
||||
skill *sv;
|
||||
unit *u = (unit *) obj;
|
||||
case TYP_UNIT:
|
||||
{
|
||||
int at, pa = 0;
|
||||
skill *sv;
|
||||
unit *u = (unit *) obj;
|
||||
|
||||
at = effskill(magician, SK_MAGIC);
|
||||
at = effskill(magician, SK_MAGIC);
|
||||
|
||||
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
|
||||
int sk = effskill(u, sv->id);
|
||||
if (pa < sk)
|
||||
pa = sk;
|
||||
}
|
||||
|
||||
/* Contest */
|
||||
probability = 0.05 * (10 + pa - at);
|
||||
|
||||
probability += magic_resistance((unit *) obj);
|
||||
break;
|
||||
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
|
||||
int sk = effskill(u, sv->id);
|
||||
if (pa < sk)
|
||||
pa = sk;
|
||||
}
|
||||
|
||||
case TYP_REGION:
|
||||
/* Bonus durch Zauber */
|
||||
probability +=
|
||||
0.01 * get_curseeffect(((region *) obj)->attribs, C_RESIST_MAGIC, 0);
|
||||
break;
|
||||
/* Contest */
|
||||
probability = 0.05 * (10 + pa - at);
|
||||
|
||||
case TYP_BUILDING:
|
||||
/* Bonus durch Zauber */
|
||||
probability +=
|
||||
0.01 * get_curseeffect(((building *) obj)->attribs, C_RESIST_MAGIC, 0);
|
||||
probability += magic_resistance((unit *) obj);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Bonus durch Typ */
|
||||
probability += 0.01 * ((building *) obj)->type->magres;
|
||||
case TYP_REGION:
|
||||
/* Bonus durch Zauber */
|
||||
probability +=
|
||||
0.01 * get_curseeffect(((region *) obj)->attribs, C_RESIST_MAGIC, 0);
|
||||
break;
|
||||
|
||||
break;
|
||||
case TYP_BUILDING:
|
||||
/* Bonus durch Zauber */
|
||||
probability +=
|
||||
0.01 * get_curseeffect(((building *) obj)->attribs, C_RESIST_MAGIC, 0);
|
||||
|
||||
case TYP_SHIP:
|
||||
/* Bonus durch Zauber */
|
||||
probability +=
|
||||
0.01 * get_curseeffect(((ship *) obj)->attribs, C_RESIST_MAGIC, 0);
|
||||
break;
|
||||
/* Bonus durch Typ */
|
||||
probability += 0.01 * ((building *) obj)->type->magres;
|
||||
|
||||
break;
|
||||
|
||||
case TYP_SHIP:
|
||||
/* Bonus durch Zauber */
|
||||
probability +=
|
||||
0.01 * get_curseeffect(((ship *) obj)->attribs, C_RESIST_MAGIC, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
probability = MAX(0.02, probability + t_bonus * 0.01);
|
||||
|
@ -1348,86 +1348,86 @@ static void do_fumble(castorder * co)
|
|||
ADDMSG(&u->faction->msgs, msg_message("patzer", "unit region spell",
|
||||
u, r, sp));
|
||||
switch (rng_int() % 10) {
|
||||
case 0:
|
||||
/* wenn vorhanden spezieller Patzer, ansonsten nix */
|
||||
if (sp->patzer)
|
||||
sp->patzer(co);
|
||||
else
|
||||
patzer(co);
|
||||
break;
|
||||
case 0:
|
||||
/* wenn vorhanden spezieller Patzer, ansonsten nix */
|
||||
if (sp->patzer)
|
||||
sp->patzer(co);
|
||||
else
|
||||
patzer(co);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
/* Kröte */
|
||||
{
|
||||
/* one or two things will happen: the toad changes her race back,
|
||||
* and may or may not get toadslime.
|
||||
* The list of things to happen are attached to a timeout
|
||||
* trigger and that's added to the triggerlit of the mage gone toad.
|
||||
*/
|
||||
trigger *trestore = trigger_changerace(u, u->race, u->irace);
|
||||
case 1:
|
||||
/* Kröte */
|
||||
{
|
||||
/* one or two things will happen: the toad changes her race back,
|
||||
* and may or may not get toadslime.
|
||||
* The list of things to happen are attached to a timeout
|
||||
* trigger and that's added to the triggerlit of the mage gone toad.
|
||||
*/
|
||||
trigger *trestore = trigger_changerace(u, u->race, u->irace);
|
||||
|
||||
if (chance(0.7)) {
|
||||
const item_type *it_toadslime = it_find("toadslime");
|
||||
if (it_toadslime != NULL) {
|
||||
t_add(&trestore, trigger_giveitem(u, it_toadslime, 1));
|
||||
}
|
||||
if (chance(0.7)) {
|
||||
const item_type *it_toadslime = it_find("toadslime");
|
||||
if (it_toadslime != NULL) {
|
||||
t_add(&trestore, trigger_giveitem(u, it_toadslime, 1));
|
||||
}
|
||||
|
||||
duration = rng_int() % level / 2;
|
||||
if (duration < 2)
|
||||
duration = 2;
|
||||
add_trigger(&u->attribs, "timer", trigger_timeout(duration, trestore));
|
||||
u->race = new_race[RC_TOAD];
|
||||
u->irace = NULL;
|
||||
ADDMSG(&r->msgs, msg_message("patzer6", "unit region spell", u, r, sp));
|
||||
break;
|
||||
}
|
||||
/* fall-through is intentional! */
|
||||
|
||||
case 2:
|
||||
/* temporärer Stufenverlust */
|
||||
duration = MAX(rng_int() % level / 2, 2);
|
||||
effect = -0.5 * level;
|
||||
c =
|
||||
create_curse(u, &u->attribs, ct_find("skillmod"), (float)level,
|
||||
duration, effect, 1);
|
||||
c->data.i = SK_MAGIC;
|
||||
ADDMSG(&u->faction->msgs, msg_message("patzer2", "unit region", u, r));
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
/* Spruch schlägt fehl, alle Magiepunkte weg */
|
||||
set_spellpoints(u, 0);
|
||||
ADDMSG(&u->faction->msgs, msg_message("patzer3", "unit region spell",
|
||||
u, r, sp));
|
||||
break;
|
||||
duration = rng_int() % level / 2;
|
||||
if (duration < 2)
|
||||
duration = 2;
|
||||
add_trigger(&u->attribs, "timer", trigger_timeout(duration, trestore));
|
||||
u->race = new_race[RC_TOAD];
|
||||
u->irace = NULL;
|
||||
ADDMSG(&r->msgs, msg_message("patzer6", "unit region spell", u, r, sp));
|
||||
break;
|
||||
}
|
||||
/* fall-through is intentional! */
|
||||
|
||||
case 5:
|
||||
case 6:
|
||||
/* Spruch gelingt, aber alle Magiepunkte weg */
|
||||
if (sp->sp_function == NULL) {
|
||||
log_error(("spell '%s' has no function.\n", sp->sname));
|
||||
} else {
|
||||
((nspell_f) sp->sp_function) (co);
|
||||
}
|
||||
set_spellpoints(u, 0);
|
||||
ADDMSG(&u->faction->msgs, msg_message("patzer4", "unit region spell",
|
||||
u, r, sp));
|
||||
break;
|
||||
case 2:
|
||||
/* temporärer Stufenverlust */
|
||||
duration = MAX(rng_int() % level / 2, 2);
|
||||
effect = -0.5 * level;
|
||||
c =
|
||||
create_curse(u, &u->attribs, ct_find("skillmod"), (float)level,
|
||||
duration, effect, 1);
|
||||
c->data.i = SK_MAGIC;
|
||||
ADDMSG(&u->faction->msgs, msg_message("patzer2", "unit region", u, r));
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
/* Spruch schlägt fehl, alle Magiepunkte weg */
|
||||
set_spellpoints(u, 0);
|
||||
ADDMSG(&u->faction->msgs, msg_message("patzer3", "unit region spell",
|
||||
u, r, sp));
|
||||
break;
|
||||
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
default:
|
||||
/* Spruch gelingt, alle nachfolgenden Sprüche werden 2^4 so teuer */
|
||||
if (sp->sp_function == NULL) {
|
||||
log_error(("spell '%s' has no function.\n", sp->sname));
|
||||
} else {
|
||||
((nspell_f) sp->sp_function) (co);
|
||||
}
|
||||
ADDMSG(&u->faction->msgs, msg_message("patzer5", "unit region spell",
|
||||
u, r, sp));
|
||||
countspells(u, 3);
|
||||
case 5:
|
||||
case 6:
|
||||
/* Spruch gelingt, aber alle Magiepunkte weg */
|
||||
if (sp->sp_function == NULL) {
|
||||
log_error(("spell '%s' has no function.\n", sp->sname));
|
||||
} else {
|
||||
((nspell_f) sp->sp_function) (co);
|
||||
}
|
||||
set_spellpoints(u, 0);
|
||||
ADDMSG(&u->faction->msgs, msg_message("patzer4", "unit region spell",
|
||||
u, r, sp));
|
||||
break;
|
||||
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
default:
|
||||
/* Spruch gelingt, alle nachfolgenden Sprüche werden 2^4 so teuer */
|
||||
if (sp->sp_function == NULL) {
|
||||
log_error(("spell '%s' has no function.\n", sp->sname));
|
||||
} else {
|
||||
((nspell_f) sp->sp_function) (co);
|
||||
}
|
||||
ADDMSG(&u->faction->msgs, msg_message("patzer5", "unit region spell",
|
||||
u, r, sp));
|
||||
countspells(u, 3);
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -1588,16 +1588,16 @@ verify_unit(region * r, unit * mage, const spell * sp, spllprm * spobj,
|
|||
{
|
||||
unit *u = NULL;
|
||||
switch (spobj->typ) {
|
||||
case SPP_UNIT:
|
||||
u = findunit(spobj->data.i);
|
||||
break;
|
||||
case SPP_TEMP:
|
||||
u = findnewunit(r, mage->faction, spobj->data.i);
|
||||
if (u == NULL)
|
||||
u = findnewunit(mage->region, mage->faction, spobj->data.i);
|
||||
break;
|
||||
default:
|
||||
assert(!"shouldn't happen, this");
|
||||
case SPP_UNIT:
|
||||
u = findunit(spobj->data.i);
|
||||
break;
|
||||
case SPP_TEMP:
|
||||
u = findnewunit(r, mage->faction, spobj->data.i);
|
||||
if (u == NULL)
|
||||
u = findnewunit(mage->region, mage->faction, spobj->data.i);
|
||||
break;
|
||||
default:
|
||||
assert(!"shouldn't happen, this");
|
||||
}
|
||||
if (u != NULL && (sp->sptyp & SEARCHLOCAL)) {
|
||||
if (u->region != r)
|
||||
|
@ -1654,21 +1654,21 @@ verify_targets(castorder * co, int *invalid, int *resist, int *success)
|
|||
spllprm *spobj = sa->param[i];
|
||||
|
||||
switch (spobj->typ) {
|
||||
case SPP_TEMP:
|
||||
case SPP_UNIT:
|
||||
if (!verify_unit(target_r, mage, sp, spobj, co->order))
|
||||
++ * invalid;
|
||||
break;
|
||||
case SPP_BUILDING:
|
||||
if (!verify_building(target_r, mage, sp, spobj, co->order))
|
||||
++ * invalid;
|
||||
break;
|
||||
case SPP_SHIP:
|
||||
if (!verify_ship(target_r, mage, sp, spobj, co->order))
|
||||
++ * invalid;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case SPP_TEMP:
|
||||
case SPP_UNIT:
|
||||
if (!verify_unit(target_r, mage, sp, spobj, co->order))
|
||||
++ * invalid;
|
||||
break;
|
||||
case SPP_BUILDING:
|
||||
if (!verify_building(target_r, mage, sp, spobj, co->order))
|
||||
++ * invalid;
|
||||
break;
|
||||
case SPP_SHIP:
|
||||
if (!verify_ship(target_r, mage, sp, spobj, co->order))
|
||||
++ * invalid;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1683,77 +1683,76 @@ verify_targets(castorder * co, int *invalid, int *resist, int *success)
|
|||
if (spobj->flag == TARGET_NOTFOUND)
|
||||
continue;
|
||||
switch (spobj->typ) {
|
||||
case SPP_TEMP:
|
||||
case SPP_UNIT:
|
||||
u = spobj->data.u;
|
||||
case SPP_TEMP:
|
||||
case SPP_UNIT:
|
||||
u = spobj->data.u;
|
||||
|
||||
if ((sp->sptyp & TESTRESISTANCE)
|
||||
&& target_resists_magic(mage, u, TYP_UNIT, 0)) {
|
||||
/* Fehlermeldung */
|
||||
spobj->data.i = u->no;
|
||||
spobj->flag = TARGET_RESISTS;
|
||||
++*resist;
|
||||
ADDMSG(&mage->faction->msgs, msg_message("spellunitresists",
|
||||
"unit region command target",
|
||||
mage, mage->region, co->order, u));
|
||||
break;
|
||||
}
|
||||
|
||||
/* TODO: Test auf Parteieigenschaft Magieresistsenz */
|
||||
++*success;
|
||||
if ((sp->sptyp & TESTRESISTANCE)
|
||||
&& target_resists_magic(mage, u, TYP_UNIT, 0)) {
|
||||
/* Fehlermeldung */
|
||||
spobj->data.i = u->no;
|
||||
spobj->flag = TARGET_RESISTS;
|
||||
++*resist;
|
||||
ADDMSG(&mage->faction->msgs, msg_message("spellunitresists",
|
||||
"unit region command target", mage, mage->region, co->order, u));
|
||||
break;
|
||||
case SPP_BUILDING:
|
||||
b = spobj->data.b;
|
||||
}
|
||||
|
||||
if ((sp->sptyp & TESTRESISTANCE)
|
||||
&& target_resists_magic(mage, b, TYP_BUILDING, 0)) { /* Fehlermeldung */
|
||||
spobj->data.i = b->no;
|
||||
spobj->flag = TARGET_RESISTS;
|
||||
++*resist;
|
||||
ADDMSG(&mage->faction->msgs, msg_message("spellbuildingresists",
|
||||
"unit region command id",
|
||||
mage, mage->region, co->order, spobj->data.i));
|
||||
break;
|
||||
}
|
||||
++*success;
|
||||
break;
|
||||
case SPP_SHIP:
|
||||
sh = spobj->data.sh;
|
||||
/* TODO: Test auf Parteieigenschaft Magieresistsenz */
|
||||
++*success;
|
||||
break;
|
||||
case SPP_BUILDING:
|
||||
b = spobj->data.b;
|
||||
|
||||
if ((sp->sptyp & TESTRESISTANCE)
|
||||
&& target_resists_magic(mage, sh, TYP_SHIP, 0)) { /* Fehlermeldung */
|
||||
spobj->data.i = sh->no;
|
||||
spobj->flag = TARGET_RESISTS;
|
||||
++*resist;
|
||||
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
|
||||
"spellshipresists", "ship", sh));
|
||||
break;
|
||||
}
|
||||
++*success;
|
||||
if ((sp->sptyp & TESTRESISTANCE)
|
||||
&& target_resists_magic(mage, b, TYP_BUILDING, 0)) { /* Fehlermeldung */
|
||||
spobj->data.i = b->no;
|
||||
spobj->flag = TARGET_RESISTS;
|
||||
++*resist;
|
||||
ADDMSG(&mage->faction->msgs, msg_message("spellbuildingresists",
|
||||
"unit region command id",
|
||||
mage, mage->region, co->order, spobj->data.i));
|
||||
break;
|
||||
}
|
||||
++*success;
|
||||
break;
|
||||
case SPP_SHIP:
|
||||
sh = spobj->data.sh;
|
||||
|
||||
case SPP_REGION:
|
||||
/* haben wir ein Regionsobjekt, dann wird auch dieses und
|
||||
nicht target_r überprüft. */
|
||||
tr = spobj->data.r;
|
||||
if ((sp->sptyp & TESTRESISTANCE)
|
||||
&& target_resists_magic(mage, sh, TYP_SHIP, 0)) { /* Fehlermeldung */
|
||||
spobj->data.i = sh->no;
|
||||
spobj->flag = TARGET_RESISTS;
|
||||
++*resist;
|
||||
ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order,
|
||||
"spellshipresists", "ship", sh));
|
||||
break;
|
||||
}
|
||||
++*success;
|
||||
break;
|
||||
|
||||
if ((sp->sptyp & TESTRESISTANCE)
|
||||
&& target_resists_magic(mage, tr, TYP_REGION, 0)) { /* Fehlermeldung */
|
||||
spobj->flag = TARGET_RESISTS;
|
||||
++*resist;
|
||||
ADDMSG(&mage->faction->msgs, msg_message("spellregionresists",
|
||||
"unit region command", mage, mage->region, co->order));
|
||||
break;
|
||||
}
|
||||
++*success;
|
||||
break;
|
||||
case SPP_INT:
|
||||
case SPP_STRING:
|
||||
++*success;
|
||||
break;
|
||||
case SPP_REGION:
|
||||
/* haben wir ein Regionsobjekt, dann wird auch dieses und
|
||||
nicht target_r überprüft. */
|
||||
tr = spobj->data.r;
|
||||
|
||||
default:
|
||||
if ((sp->sptyp & TESTRESISTANCE)
|
||||
&& target_resists_magic(mage, tr, TYP_REGION, 0)) { /* Fehlermeldung */
|
||||
spobj->flag = TARGET_RESISTS;
|
||||
++*resist;
|
||||
ADDMSG(&mage->faction->msgs, msg_message("spellregionresists",
|
||||
"unit region command", mage, mage->region, co->order));
|
||||
break;
|
||||
}
|
||||
++*success;
|
||||
break;
|
||||
case SPP_INT:
|
||||
case SPP_STRING:
|
||||
++*success;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -1804,11 +1803,11 @@ static void free_spellparameter(spellparameter * pa)
|
|||
for (i = 0; i < pa->length; i++) {
|
||||
|
||||
switch (pa->param[i]->typ) {
|
||||
case SPP_STRING:
|
||||
free(pa->param[i]->data.s);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case SPP_STRING:
|
||||
free(pa->param[i]->data.s);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
free(pa->param[i]);
|
||||
}
|
||||
|
@ -1967,87 +1966,87 @@ static spellparameter *add_spellparameter(region * target_r, unit * u,
|
|||
param_t pword;
|
||||
int j = -1;
|
||||
switch (*c) {
|
||||
case '?':
|
||||
/* tja. das sollte moeglichst nur am Ende passieren,
|
||||
* weil sonst die kacke dampft. */
|
||||
case '?':
|
||||
/* tja. das sollte moeglichst nur am Ende passieren,
|
||||
* weil sonst die kacke dampft. */
|
||||
j = 0;
|
||||
++c;
|
||||
assert(*c == 0);
|
||||
break;
|
||||
case '+':
|
||||
/* das vorhergehende Element kommt ein oder mehrmals vor, wir
|
||||
* springen zum key zurück */
|
||||
j = 0;
|
||||
--c;
|
||||
break;
|
||||
case 'u':
|
||||
/* Parameter ist eine Einheit, evtl. TEMP */
|
||||
j = addparam_unit(param + i, &spobj, u, ord);
|
||||
++c;
|
||||
break;
|
||||
case 'r':
|
||||
/* Parameter sind zwei Regionskoordinaten */
|
||||
/* this silly thing only works in the normal plane! */
|
||||
j = addparam_region(param + i, &spobj, u, ord, get_normalplane());
|
||||
++c;
|
||||
break;
|
||||
case 'b':
|
||||
/* Parameter ist eine Burgnummer */
|
||||
j = addparam_building(param + i, &spobj);
|
||||
++c;
|
||||
break;
|
||||
case 's':
|
||||
j = addparam_ship(param + i, &spobj);
|
||||
++c;
|
||||
break;
|
||||
case 'c':
|
||||
/* Text, wird im Spruch ausgewertet */
|
||||
j = addparam_string(param + i, &spobj);
|
||||
++c;
|
||||
break;
|
||||
case 'i': /* Zahl */
|
||||
j = addparam_int(param + i, &spobj);
|
||||
++c;
|
||||
break;
|
||||
case 'k':
|
||||
++c;
|
||||
pword = findparam(param[i++], u->faction->locale);
|
||||
switch (pword) {
|
||||
case P_REGION:
|
||||
spobj = malloc(sizeof(spllprm));
|
||||
spobj->flag = 0;
|
||||
spobj->typ = SPP_REGION;
|
||||
spobj->data.r = u->region;
|
||||
j = 0;
|
||||
++c;
|
||||
assert(*c == 0);
|
||||
break;
|
||||
case '+':
|
||||
/* das vorhergehende Element kommt ein oder mehrmals vor, wir
|
||||
* springen zum key zurück */
|
||||
j = 0;
|
||||
--c;
|
||||
case P_UNIT:
|
||||
if (i < size) {
|
||||
j = addparam_unit(param + i, &spobj, u, ord);
|
||||
++c;
|
||||
}
|
||||
break;
|
||||
case 'u':
|
||||
/* Parameter ist eine Einheit, evtl. TEMP */
|
||||
j = addparam_unit(param + i, &spobj, u, ord);
|
||||
++c;
|
||||
case P_BUILDING:
|
||||
case P_GEBAEUDE:
|
||||
if (i < size) {
|
||||
j = addparam_building(param + i, &spobj);
|
||||
++c;
|
||||
}
|
||||
break;
|
||||
case 'r':
|
||||
/* Parameter sind zwei Regionskoordinaten */
|
||||
/* this silly thing only works in the normal plane! */
|
||||
j = addparam_region(param + i, &spobj, u, ord, get_normalplane());
|
||||
++c;
|
||||
break;
|
||||
case 'b':
|
||||
/* Parameter ist eine Burgnummer */
|
||||
j = addparam_building(param + i, &spobj);
|
||||
++c;
|
||||
break;
|
||||
case 's':
|
||||
j = addparam_ship(param + i, &spobj);
|
||||
++c;
|
||||
break;
|
||||
case 'c':
|
||||
/* Text, wird im Spruch ausgewertet */
|
||||
j = addparam_string(param + i, &spobj);
|
||||
++c;
|
||||
break;
|
||||
case 'i': /* Zahl */
|
||||
j = addparam_int(param + i, &spobj);
|
||||
++c;
|
||||
break;
|
||||
case 'k':
|
||||
++c;
|
||||
pword = findparam(param[i++], u->faction->locale);
|
||||
switch (pword) {
|
||||
case P_REGION:
|
||||
spobj = malloc(sizeof(spllprm));
|
||||
spobj->flag = 0;
|
||||
spobj->typ = SPP_REGION;
|
||||
spobj->data.r = u->region;
|
||||
j = 0;
|
||||
++c;
|
||||
break;
|
||||
case P_UNIT:
|
||||
if (i < size) {
|
||||
j = addparam_unit(param + i, &spobj, u, ord);
|
||||
++c;
|
||||
}
|
||||
break;
|
||||
case P_BUILDING:
|
||||
case P_GEBAEUDE:
|
||||
if (i < size) {
|
||||
j = addparam_building(param + i, &spobj);
|
||||
++c;
|
||||
}
|
||||
break;
|
||||
case P_SHIP:
|
||||
if (i < size) {
|
||||
j = addparam_ship(param + i, &spobj);
|
||||
++c;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
j = -1;
|
||||
break;
|
||||
case P_SHIP:
|
||||
if (i < size) {
|
||||
j = addparam_ship(param + i, &spobj);
|
||||
++c;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
j = -1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
j = -1;
|
||||
break;
|
||||
}
|
||||
if (j < 0)
|
||||
fail = true;
|
||||
|
@ -2481,10 +2480,12 @@ static boolean is_moving_ship(const region * r, const ship * sh)
|
|||
|
||||
if (u)
|
||||
switch (get_keyword(u->thisorder)) {
|
||||
case K_ROUTE:
|
||||
case K_MOVE:
|
||||
case K_FOLLOW:
|
||||
return true;
|
||||
case K_ROUTE:
|
||||
case K_MOVE:
|
||||
case K_FOLLOW:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1328,12 +1328,14 @@ static int movement_speed(unit * u)
|
|||
assert(u->number);
|
||||
/* dragons have a fixed speed, and no other effects work on them: */
|
||||
switch (old_race(u->race)) {
|
||||
case RC_DRAGON:
|
||||
case RC_WYRM:
|
||||
case RC_FIREDRAGON:
|
||||
case RC_BIRTHDAYDRAGON:
|
||||
case RC_SONGDRAGON:
|
||||
return BP_DRAGON;
|
||||
case RC_DRAGON:
|
||||
case RC_WYRM:
|
||||
case RC_FIREDRAGON:
|
||||
case RC_BIRTHDAYDRAGON:
|
||||
case RC_SONGDRAGON:
|
||||
return BP_DRAGON;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (!init) {
|
||||
|
@ -1350,38 +1352,38 @@ static int movement_speed(unit * u)
|
|||
|
||||
switch (canride(u)) {
|
||||
|
||||
case 1: /* Pferd */
|
||||
mp = BP_RIDING;
|
||||
break;
|
||||
case 1: /* Pferd */
|
||||
mp = BP_RIDING;
|
||||
break;
|
||||
|
||||
case 2: /* Einhorn */
|
||||
mp = BP_UNICORN;
|
||||
break;
|
||||
case 2: /* Einhorn */
|
||||
mp = BP_UNICORN;
|
||||
break;
|
||||
|
||||
default:
|
||||
mp = BP_WALKING;
|
||||
default:
|
||||
mp = BP_WALKING;
|
||||
|
||||
/* Siebenmeilentee */
|
||||
if (get_effect(u, oldpotiontype[P_FAST]) >= u->number) {
|
||||
mp *= 2;
|
||||
change_effect(u, oldpotiontype[P_FAST], -u->number);
|
||||
}
|
||||
/* Siebenmeilentee */
|
||||
if (get_effect(u, oldpotiontype[P_FAST]) >= u->number) {
|
||||
mp *= 2;
|
||||
change_effect(u, oldpotiontype[P_FAST], -u->number);
|
||||
}
|
||||
|
||||
/* unicorn in inventory */
|
||||
if (u->number <= get_item(u, I_FEENSTIEFEL)) {
|
||||
/* unicorn in inventory */
|
||||
if (u->number <= get_item(u, I_FEENSTIEFEL)) {
|
||||
mp *= 2;
|
||||
}
|
||||
|
||||
/* Im Astralraum sind Tyb und Ill-Magier doppelt so schnell.
|
||||
* Nicht kumulativ mit anderen Beschleunigungen! */
|
||||
if (mp * dk <= BP_WALKING * u->race->speed && is_astral(u->region)
|
||||
&& is_mage(u)) {
|
||||
sc_mage *mage = get_mage(u);
|
||||
if (mage->magietyp == M_TYBIED || mage->magietyp == M_ILLAUN) {
|
||||
mp *= 2;
|
||||
}
|
||||
|
||||
/* Im Astralraum sind Tyb und Ill-Magier doppelt so schnell.
|
||||
* Nicht kumulativ mit anderen Beschleunigungen! */
|
||||
if (mp * dk <= BP_WALKING * u->race->speed && is_astral(u->region)
|
||||
&& is_mage(u)) {
|
||||
sc_mage *mage = get_mage(u);
|
||||
if (mage->magietyp == M_TYBIED || mage->magietyp == M_ILLAUN) {
|
||||
mp *= 2;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return (int)(dk * mp);
|
||||
}
|
||||
|
@ -1996,15 +1998,15 @@ static const region_list *travel_i(unit * u, const region_list * route_begin,
|
|||
return route_begin;
|
||||
}
|
||||
switch (canwalk(u)) {
|
||||
case E_CANWALK_TOOHEAVY:
|
||||
cmistake(u, ord, 57, MSG_MOVE);
|
||||
return route_begin;
|
||||
case E_CANWALK_TOOMANYHORSES:
|
||||
cmistake(u, ord, 56, MSG_MOVE);
|
||||
return route_begin;
|
||||
case E_CANWALK_TOOMANYCARTS:
|
||||
cmistake(u, ord, 42, MSG_MOVE);
|
||||
return route_begin;
|
||||
case E_CANWALK_TOOHEAVY:
|
||||
cmistake(u, ord, 57, MSG_MOVE);
|
||||
return route_begin;
|
||||
case E_CANWALK_TOOMANYHORSES:
|
||||
cmistake(u, ord, 56, MSG_MOVE);
|
||||
return route_begin;
|
||||
case E_CANWALK_TOOMANYCARTS:
|
||||
cmistake(u, ord, 42, MSG_MOVE);
|
||||
return route_begin;
|
||||
}
|
||||
route_end = cap_route(r, route_begin, route_end, movement_speed(u));
|
||||
|
||||
|
@ -2565,44 +2567,41 @@ void movement(void)
|
|||
}
|
||||
kword = get_keyword(u->thisorder);
|
||||
|
||||
switch (kword) {
|
||||
case K_ROUTE:
|
||||
case K_MOVE:
|
||||
/* after moving, the unit has no thisorder. this prevents
|
||||
* it from moving twice (or getting error messages twice).
|
||||
* UFL_NOTMOVING is set in combat if the unit is not allowed
|
||||
* to move because it was involved in a battle.
|
||||
*/
|
||||
if (fval(u, UFL_NOTMOVING)) {
|
||||
if (fval(u, UFL_LONGACTION)) {
|
||||
cmistake(u, u->thisorder, 52, MSG_MOVE);
|
||||
set_order(&u->thisorder, NULL);
|
||||
} else {
|
||||
cmistake(u, u->thisorder, 319, MSG_MOVE);
|
||||
set_order(&u->thisorder, NULL);
|
||||
}
|
||||
} else if (fval(u, UFL_MOVED)) {
|
||||
cmistake(u, u->thisorder, 187, MSG_MOVE);
|
||||
set_order(&u->thisorder, NULL);
|
||||
} else if (!can_move(u)) {
|
||||
cmistake(u, u->thisorder, 55, MSG_MOVE);
|
||||
if (kword == K_ROUTE || kword == K_MOVE) {
|
||||
/* after moving, the unit has no thisorder. this prevents
|
||||
* it from moving twice (or getting error messages twice).
|
||||
* UFL_NOTMOVING is set in combat if the unit is not allowed
|
||||
* to move because it was involved in a battle.
|
||||
*/
|
||||
if (fval(u, UFL_NOTMOVING)) {
|
||||
if (fval(u, UFL_LONGACTION)) {
|
||||
cmistake(u, u->thisorder, 52, MSG_MOVE);
|
||||
set_order(&u->thisorder, NULL);
|
||||
} else {
|
||||
if (ships) {
|
||||
if (u->ship && fval(u, UFL_OWNER)) {
|
||||
init_tokens(u->thisorder);
|
||||
skip_token();
|
||||
move(u, false);
|
||||
}
|
||||
} else {
|
||||
if (u->ship == NULL || !fval(u, UFL_OWNER)) {
|
||||
init_tokens(u->thisorder);
|
||||
skip_token();
|
||||
move(u, false);
|
||||
}
|
||||
cmistake(u, u->thisorder, 319, MSG_MOVE);
|
||||
set_order(&u->thisorder, NULL);
|
||||
}
|
||||
} else if (fval(u, UFL_MOVED)) {
|
||||
cmistake(u, u->thisorder, 187, MSG_MOVE);
|
||||
set_order(&u->thisorder, NULL);
|
||||
} else if (!can_move(u)) {
|
||||
cmistake(u, u->thisorder, 55, MSG_MOVE);
|
||||
set_order(&u->thisorder, NULL);
|
||||
} else {
|
||||
if (ships) {
|
||||
if (u->ship && fval(u, UFL_OWNER)) {
|
||||
init_tokens(u->thisorder);
|
||||
skip_token();
|
||||
move(u, false);
|
||||
}
|
||||
} else {
|
||||
if (u->ship == NULL || !fval(u, UFL_OWNER)) {
|
||||
init_tokens(u->thisorder);
|
||||
skip_token();
|
||||
move(u, false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (u->region == r) {
|
||||
/* not moved, use next unit */
|
||||
|
@ -2683,24 +2682,24 @@ void follow_unit(unit * u)
|
|||
}
|
||||
|
||||
switch (get_keyword(u2->thisorder)) {
|
||||
case K_MOVE:
|
||||
case K_ROUTE:
|
||||
case K_DRIVE:
|
||||
follow = true;
|
||||
break;
|
||||
default:
|
||||
for (ord = u2->orders; ord; ord = ord->next) {
|
||||
switch (get_keyword(ord)) {
|
||||
case K_FOLLOW:
|
||||
case K_PIRACY:
|
||||
follow = true;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
case K_MOVE:
|
||||
case K_ROUTE:
|
||||
case K_DRIVE:
|
||||
follow = true;
|
||||
break;
|
||||
default:
|
||||
for (ord = u2->orders; ord; ord = ord->next) {
|
||||
switch (get_keyword(ord)) {
|
||||
case K_FOLLOW:
|
||||
case K_PIRACY:
|
||||
follow = true;
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!follow) {
|
||||
attrib *a2 = a_find(u2->attribs, &at_follow);
|
||||
|
|
|
@ -195,33 +195,33 @@ static order_data *create_data(keyword_t kwd, const char *sptr, int lindex)
|
|||
if (kwd == K_STUDY) {
|
||||
skill_t sk = findskill(parse_token(&sptr), lang);
|
||||
switch (sk) {
|
||||
case NOSKILL: /* fehler */
|
||||
case NOSKILL: /* fehler */
|
||||
break;
|
||||
case SK_MAGIC: /* kann parameter haben */
|
||||
if (*sptr != 0)
|
||||
break;
|
||||
case SK_MAGIC: /* kann parameter haben */
|
||||
if (*sptr != 0)
|
||||
break;
|
||||
default: /* nur skill als Parameter, keine extras */
|
||||
data = locale_array[lindex]->study_orders[sk];
|
||||
if (data == NULL) {
|
||||
const char *skname = skillname(sk, lang);
|
||||
data = (order_data *) malloc(sizeof(order_data));
|
||||
locale_array[lindex]->study_orders[sk] = data;
|
||||
data->_keyword = kwd;
|
||||
data->_lindex = lindex;
|
||||
if (strchr(skname, ' ') != NULL) {
|
||||
size_t len = strlen(skname);
|
||||
data->_str = malloc(len + 3);
|
||||
data->_str[0] = '\"';
|
||||
memcpy(data->_str + 1, skname, len);
|
||||
data->_str[len + 1] = '\"';
|
||||
data->_str[len + 2] = '\0';
|
||||
} else {
|
||||
data->_str = strdup(skname);
|
||||
}
|
||||
data->_refcount = 1;
|
||||
default: /* nur skill als Parameter, keine extras */
|
||||
data = locale_array[lindex]->study_orders[sk];
|
||||
if (data == NULL) {
|
||||
const char *skname = skillname(sk, lang);
|
||||
data = (order_data *) malloc(sizeof(order_data));
|
||||
locale_array[lindex]->study_orders[sk] = data;
|
||||
data->_keyword = kwd;
|
||||
data->_lindex = lindex;
|
||||
if (strchr(skname, ' ') != NULL) {
|
||||
size_t len = strlen(skname);
|
||||
data->_str = malloc(len + 3);
|
||||
data->_str[0] = '\"';
|
||||
memcpy(data->_str + 1, skname, len);
|
||||
data->_str[len + 1] = '\"';
|
||||
data->_str[len + 2] = '\0';
|
||||
} else {
|
||||
data->_str = strdup(skname);
|
||||
}
|
||||
++data->_refcount;
|
||||
return data;
|
||||
data->_refcount = 1;
|
||||
}
|
||||
++data->_refcount;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -256,15 +256,15 @@ static order *create_order_i(keyword_t kwd, const char *sptr, int persistent,
|
|||
/* if this is just nonsense, then we skip it. */
|
||||
if (lomem) {
|
||||
switch (kwd) {
|
||||
case K_KOMMENTAR:
|
||||
case NOKEYWORD:
|
||||
return NULL;
|
||||
case K_LIEFERE:
|
||||
kwd = K_GIVE;
|
||||
persistent = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case K_KOMMENTAR:
|
||||
case NOKEYWORD:
|
||||
return NULL;
|
||||
case K_LIEFERE:
|
||||
kwd = K_GIVE;
|
||||
persistent = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -304,26 +304,26 @@ order *create_order(keyword_t kwd, const struct locale * lang,
|
|||
const char *s;
|
||||
++params;
|
||||
switch (*params) {
|
||||
case 's':
|
||||
s = va_arg(marker, const char *);
|
||||
bytes = (int)strlcpy(bufp, s, size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
break;
|
||||
case 'd':
|
||||
i = va_arg(marker, int);
|
||||
bytes = (int)strlcpy(bufp, itoa10(i), size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
break;
|
||||
case 'i':
|
||||
i = va_arg(marker, int);
|
||||
bytes = (int)strlcpy(bufp, itoa36(i), size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
break;
|
||||
default:
|
||||
assert(!"unknown format-character in create_order");
|
||||
case 's':
|
||||
s = va_arg(marker, const char *);
|
||||
bytes = (int)strlcpy(bufp, s, size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
break;
|
||||
case 'd':
|
||||
i = va_arg(marker, int);
|
||||
bytes = (int)strlcpy(bufp, itoa10(i), size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
break;
|
||||
case 'i':
|
||||
i = va_arg(marker, int);
|
||||
bytes = (int)strlcpy(bufp, itoa36(i), size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
break;
|
||||
default:
|
||||
assert(!"unknown format-character in create_order");
|
||||
}
|
||||
} else if (size > 0) {
|
||||
*bufp++ = *params;
|
||||
|
@ -379,55 +379,55 @@ boolean is_repeated(const order * ord)
|
|||
param_t param;
|
||||
|
||||
switch (kwd) {
|
||||
case K_CAST:
|
||||
case K_BUY:
|
||||
case K_SELL:
|
||||
case K_ROUTE:
|
||||
case K_DRIVE:
|
||||
case K_WORK:
|
||||
case K_BESIEGE:
|
||||
case K_ENTERTAIN:
|
||||
case K_TAX:
|
||||
case K_RESEARCH:
|
||||
case K_SPY:
|
||||
case K_STEAL:
|
||||
case K_SABOTAGE:
|
||||
case K_STUDY:
|
||||
case K_TEACH:
|
||||
case K_BREED:
|
||||
case K_PIRACY:
|
||||
case K_CAST:
|
||||
case K_BUY:
|
||||
case K_SELL:
|
||||
case K_ROUTE:
|
||||
case K_DRIVE:
|
||||
case K_WORK:
|
||||
case K_BESIEGE:
|
||||
case K_ENTERTAIN:
|
||||
case K_TAX:
|
||||
case K_RESEARCH:
|
||||
case K_SPY:
|
||||
case K_STEAL:
|
||||
case K_SABOTAGE:
|
||||
case K_STUDY:
|
||||
case K_TEACH:
|
||||
case K_BREED:
|
||||
case K_PIRACY:
|
||||
case K_PLANT:
|
||||
return true;
|
||||
|
||||
case K_FOLLOW:
|
||||
/* FOLLOW is only a long order if we are following a ship. */
|
||||
parser_pushstate();
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
param = getparam(lang);
|
||||
parser_popstate();
|
||||
|
||||
if (param == P_SHIP)
|
||||
return true;
|
||||
break;
|
||||
|
||||
case K_PLANT:
|
||||
case K_MAKE:
|
||||
/* Falls wir MACHE TEMP haben, ignorieren wir es. Alle anderen
|
||||
* Arten von MACHE zaehlen aber als neue defaults und werden
|
||||
* behandelt wie die anderen (deswegen kein break nach case
|
||||
* K_MAKE) - und in thisorder (der aktuelle 30-Tage Befehl)
|
||||
* abgespeichert). */
|
||||
parser_pushstate();
|
||||
init_tokens(ord); /* initialize token-parser */
|
||||
skip_token();
|
||||
param = getparam(lang);
|
||||
parser_popstate();
|
||||
|
||||
if (param != P_TEMP)
|
||||
return true;
|
||||
|
||||
case K_FOLLOW:
|
||||
/* FOLLOW is only a long order if we are following a ship. */
|
||||
parser_pushstate();
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
param = getparam(lang);
|
||||
parser_popstate();
|
||||
|
||||
if (param == P_SHIP)
|
||||
return true;
|
||||
break;
|
||||
|
||||
case K_MAKE:
|
||||
/* Falls wir MACHE TEMP haben, ignorieren wir es. Alle anderen
|
||||
* Arten von MACHE zaehlen aber als neue defaults und werden
|
||||
* behandelt wie die anderen (deswegen kein break nach case
|
||||
* K_MAKE) - und in thisorder (der aktuelle 30-Tage Befehl)
|
||||
* abgespeichert). */
|
||||
parser_pushstate();
|
||||
init_tokens(ord); /* initialize token-parser */
|
||||
skip_token();
|
||||
param = getparam(lang);
|
||||
parser_popstate();
|
||||
|
||||
if (param != P_TEMP)
|
||||
return true;
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -447,55 +447,55 @@ boolean is_exclusive(const order * ord)
|
|||
param_t param;
|
||||
|
||||
switch (kwd) {
|
||||
case K_MOVE:
|
||||
case K_WEREWOLF:
|
||||
/* these should not become persistent */
|
||||
case K_ROUTE:
|
||||
case K_DRIVE:
|
||||
case K_WORK:
|
||||
case K_BESIEGE:
|
||||
case K_ENTERTAIN:
|
||||
case K_TAX:
|
||||
case K_RESEARCH:
|
||||
case K_SPY:
|
||||
case K_STEAL:
|
||||
case K_SABOTAGE:
|
||||
case K_STUDY:
|
||||
case K_TEACH:
|
||||
case K_BREED:
|
||||
case K_PIRACY:
|
||||
case K_MOVE:
|
||||
case K_WEREWOLF:
|
||||
/* these should not become persistent */
|
||||
case K_ROUTE:
|
||||
case K_DRIVE:
|
||||
case K_WORK:
|
||||
case K_BESIEGE:
|
||||
case K_ENTERTAIN:
|
||||
case K_TAX:
|
||||
case K_RESEARCH:
|
||||
case K_SPY:
|
||||
case K_STEAL:
|
||||
case K_SABOTAGE:
|
||||
case K_STUDY:
|
||||
case K_TEACH:
|
||||
case K_BREED:
|
||||
case K_PIRACY:
|
||||
case K_PLANT:
|
||||
return true;
|
||||
|
||||
case K_FOLLOW:
|
||||
/* FOLLOW is only a long order if we are following a ship. */
|
||||
parser_pushstate();
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
param = getparam(lang);
|
||||
parser_popstate();
|
||||
|
||||
if (param == P_SHIP)
|
||||
return true;
|
||||
break;
|
||||
|
||||
case K_PLANT:
|
||||
case K_MAKE:
|
||||
/* Falls wir MACHE TEMP haben, ignorieren wir es. Alle anderen
|
||||
* Arten von MACHE zaehlen aber als neue defaults und werden
|
||||
* behandelt wie die anderen (deswegen kein break nach case
|
||||
* K_MAKE) - und in thisorder (der aktuelle 30-Tage Befehl)
|
||||
* abgespeichert). */
|
||||
parser_pushstate();
|
||||
init_tokens(ord); /* initialize token-parser */
|
||||
skip_token();
|
||||
param = getparam(lang);
|
||||
parser_popstate();
|
||||
|
||||
if (param != P_TEMP)
|
||||
return true;
|
||||
|
||||
case K_FOLLOW:
|
||||
/* FOLLOW is only a long order if we are following a ship. */
|
||||
parser_pushstate();
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
param = getparam(lang);
|
||||
parser_popstate();
|
||||
|
||||
if (param == P_SHIP)
|
||||
return true;
|
||||
break;
|
||||
|
||||
case K_MAKE:
|
||||
/* Falls wir MACHE TEMP haben, ignorieren wir es. Alle anderen
|
||||
* Arten von MACHE zaehlen aber als neue defaults und werden
|
||||
* behandelt wie die anderen (deswegen kein break nach case
|
||||
* K_MAKE) - und in thisorder (der aktuelle 30-Tage Befehl)
|
||||
* abgespeichert). */
|
||||
parser_pushstate();
|
||||
init_tokens(ord); /* initialize token-parser */
|
||||
skip_token();
|
||||
param = getparam(lang);
|
||||
parser_popstate();
|
||||
|
||||
if (param != P_TEMP)
|
||||
return true;
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -515,57 +515,57 @@ boolean is_long(const order * ord)
|
|||
param_t param;
|
||||
|
||||
switch (kwd) {
|
||||
case K_CAST:
|
||||
case K_BUY:
|
||||
case K_SELL:
|
||||
case K_MOVE:
|
||||
case K_WEREWOLF:
|
||||
case K_ROUTE:
|
||||
case K_DRIVE:
|
||||
case K_WORK:
|
||||
case K_BESIEGE:
|
||||
case K_ENTERTAIN:
|
||||
case K_TAX:
|
||||
case K_RESEARCH:
|
||||
case K_SPY:
|
||||
case K_STEAL:
|
||||
case K_SABOTAGE:
|
||||
case K_STUDY:
|
||||
case K_TEACH:
|
||||
case K_BREED:
|
||||
case K_PIRACY:
|
||||
case K_CAST:
|
||||
case K_BUY:
|
||||
case K_SELL:
|
||||
case K_MOVE:
|
||||
case K_WEREWOLF:
|
||||
case K_ROUTE:
|
||||
case K_DRIVE:
|
||||
case K_WORK:
|
||||
case K_BESIEGE:
|
||||
case K_ENTERTAIN:
|
||||
case K_TAX:
|
||||
case K_RESEARCH:
|
||||
case K_SPY:
|
||||
case K_STEAL:
|
||||
case K_SABOTAGE:
|
||||
case K_STUDY:
|
||||
case K_TEACH:
|
||||
case K_BREED:
|
||||
case K_PIRACY:
|
||||
case K_PLANT:
|
||||
return true;
|
||||
|
||||
case K_FOLLOW:
|
||||
/* FOLLOW is only a long order if we are following a ship. */
|
||||
parser_pushstate();
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
param = getparam(lang);
|
||||
parser_popstate();
|
||||
|
||||
if (param == P_SHIP)
|
||||
return true;
|
||||
break;
|
||||
|
||||
case K_PLANT:
|
||||
case K_MAKE:
|
||||
/* Falls wir MACHE TEMP haben, ignorieren wir es. Alle anderen
|
||||
* Arten von MACHE zaehlen aber als neue defaults und werden
|
||||
* behandelt wie die anderen (deswegen kein break nach case
|
||||
* K_MAKE) - und in thisorder (der aktuelle 30-Tage Befehl)
|
||||
* abgespeichert). */
|
||||
parser_pushstate();
|
||||
init_tokens(ord); /* initialize token-parser */
|
||||
skip_token();
|
||||
param = getparam(lang);
|
||||
parser_popstate();
|
||||
|
||||
if (param != P_TEMP)
|
||||
return true;
|
||||
|
||||
case K_FOLLOW:
|
||||
/* FOLLOW is only a long order if we are following a ship. */
|
||||
parser_pushstate();
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
param = getparam(lang);
|
||||
parser_popstate();
|
||||
|
||||
if (param == P_SHIP)
|
||||
return true;
|
||||
break;
|
||||
|
||||
case K_MAKE:
|
||||
/* Falls wir MACHE TEMP haben, ignorieren wir es. Alle anderen
|
||||
* Arten von MACHE zaehlen aber als neue defaults und werden
|
||||
* behandelt wie die anderen (deswegen kein break nach case
|
||||
* K_MAKE) - und in thisorder (der aktuelle 30-Tage Befehl)
|
||||
* abgespeichert). */
|
||||
parser_pushstate();
|
||||
init_tokens(ord); /* initialize token-parser */
|
||||
skip_token();
|
||||
param = getparam(lang);
|
||||
parser_popstate();
|
||||
|
||||
if (param != P_TEMP)
|
||||
return true;
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -584,18 +584,20 @@ boolean is_persistent(const order * ord)
|
|||
keyword_t kwd = ORD_KEYWORD(ord);
|
||||
boolean persist = ord->_persistent != 0;
|
||||
switch (kwd) {
|
||||
case K_MOVE:
|
||||
case K_WEREWOLF:
|
||||
case NOKEYWORD:
|
||||
/* lang, aber niemals persistent! */
|
||||
return false;
|
||||
case K_MOVE:
|
||||
case K_WEREWOLF:
|
||||
case NOKEYWORD:
|
||||
/* lang, aber niemals persistent! */
|
||||
return false;
|
||||
|
||||
case K_KOMMENTAR:
|
||||
case K_LIEFERE:
|
||||
return true;
|
||||
case K_KOMMENTAR:
|
||||
case K_LIEFERE:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return persist || is_repeated(ord);
|
||||
}
|
||||
|
||||
return persist || is_repeated(ord);
|
||||
}
|
||||
|
||||
char *write_order(const order * ord, char *buffer, size_t size)
|
||||
|
|
|
@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
#ifndef H_KRNL_REPORTS
|
||||
#define H_KRNL_REPORTS
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
|
@ -144,51 +144,29 @@ int freadstr(FILE * F, int encoding, char *start, size_t size)
|
|||
}
|
||||
}
|
||||
switch (c) {
|
||||
case EOF:
|
||||
return EOF;
|
||||
case '"':
|
||||
if (!quote && str != start) {
|
||||
log_error(
|
||||
("datafile contains a \" that isn't at the start of a string.\n"));
|
||||
assert
|
||||
(!"datafile contains a \" that isn't at the start of a string.\n");
|
||||
}
|
||||
if (quote) {
|
||||
*str = 0;
|
||||
return (int)(str - start);
|
||||
}
|
||||
quote = true;
|
||||
break;
|
||||
case '\\':
|
||||
c = fgetc(F);
|
||||
switch (c) {
|
||||
case EOF:
|
||||
return EOF;
|
||||
case '"':
|
||||
if (!quote && str != start) {
|
||||
log_error(
|
||||
("datafile contains a \" that isn't at the start of a string.\n"));
|
||||
assert
|
||||
(!"datafile contains a \" that isn't at the start of a string.\n");
|
||||
}
|
||||
if (quote) {
|
||||
*str = 0;
|
||||
return (int)(str - start);
|
||||
}
|
||||
quote = true;
|
||||
break;
|
||||
case '\\':
|
||||
c = fgetc(F);
|
||||
switch (c) {
|
||||
case EOF:
|
||||
return EOF;
|
||||
case 'n':
|
||||
if ((size_t) (str - start + 1) < size) {
|
||||
*str++ = '\n';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if ((size_t) (str - start + 1) < size) {
|
||||
if (encoding == XML_CHAR_ENCODING_8859_1 && c & 0x80) {
|
||||
char inbuf = (char)c;
|
||||
size_t inbytes = 1;
|
||||
size_t outbytes = size - (str - start);
|
||||
int ret =
|
||||
unicode_latin1_to_utf8(str, &outbytes, &inbuf, &inbytes);
|
||||
if (ret > 0)
|
||||
str += ret;
|
||||
else {
|
||||
log_error(
|
||||
("input data was not iso-8859-1! assuming utf-8\n"));
|
||||
encoding = XML_CHAR_ENCODING_ERROR;
|
||||
*str++ = (char)c;
|
||||
}
|
||||
} else {
|
||||
*str++ = (char)c;
|
||||
}
|
||||
}
|
||||
case 'n':
|
||||
if ((size_t) (str - start + 1) < size) {
|
||||
*str++ = '\n';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -209,6 +187,26 @@ int freadstr(FILE * F, int encoding, char *start, size_t size)
|
|||
*str++ = (char)c;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if ((size_t) (str - start + 1) < size) {
|
||||
if (encoding == XML_CHAR_ENCODING_8859_1 && c & 0x80) {
|
||||
char inbuf = (char)c;
|
||||
size_t inbytes = 1;
|
||||
size_t outbytes = size - (str - start);
|
||||
int ret = unicode_latin1_to_utf8(str, &outbytes, &inbuf, &inbytes);
|
||||
if (ret > 0)
|
||||
str += ret;
|
||||
else {
|
||||
log_error(("input data was not iso-8859-1! assuming utf-8\n"));
|
||||
encoding = XML_CHAR_ENCODING_ERROR;
|
||||
*str++ = (char)c;
|
||||
}
|
||||
} else {
|
||||
*str++ = (char)c;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -224,20 +222,20 @@ int fwritestr(FILE * F, const char *str)
|
|||
while (*str) {
|
||||
int c = (int)(unsigned char)*str++;
|
||||
switch (c) {
|
||||
case '"':
|
||||
case '\\':
|
||||
fputc('\\', F);
|
||||
fputc(c, F);
|
||||
nwrite += 2;
|
||||
break;
|
||||
case '\n':
|
||||
fputc('\\', F);
|
||||
fputc('n', F);
|
||||
nwrite += 2;
|
||||
break;
|
||||
default:
|
||||
fputc(c, F);
|
||||
++nwrite;
|
||||
case '"':
|
||||
case '\\':
|
||||
fputc('\\', F);
|
||||
fputc(c, F);
|
||||
nwrite += 2;
|
||||
break;
|
||||
case '\n':
|
||||
fputc('\\', F);
|
||||
fputc('n', F);
|
||||
nwrite += 2;
|
||||
break;
|
||||
default:
|
||||
fputc(c, F);
|
||||
++nwrite;
|
||||
}
|
||||
}
|
||||
fputc('\"', F);
|
||||
|
@ -300,23 +298,28 @@ static unit *unitorders(FILE * F, int enc, struct faction *f)
|
|||
boolean quit = false;
|
||||
param_t param = findparam(stok, u->faction->locale);
|
||||
switch (param) {
|
||||
case P_UNIT:
|
||||
case P_REGION:
|
||||
case P_UNIT:
|
||||
case P_REGION:
|
||||
quit = true;
|
||||
break;
|
||||
case P_FACTION:
|
||||
case P_NEXT:
|
||||
case P_GAMENAME:
|
||||
/* these terminate the orders, so we apply extra checking */
|
||||
if (strlen(stok) >= 3) {
|
||||
quit = true;
|
||||
break;
|
||||
case P_FACTION:
|
||||
case P_NEXT:
|
||||
case P_GAMENAME:
|
||||
/* these terminate the orders, so we apply extra checking */
|
||||
if (strlen(stok) >= 3) {
|
||||
quit = true;
|
||||
break;
|
||||
} else {
|
||||
quit = false;
|
||||
}
|
||||
}
|
||||
if (quit)
|
||||
} else {
|
||||
quit = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* TODO: syntax error message */
|
||||
break;
|
||||
}
|
||||
if (quit) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Nun wird der Befehl erzeut und eingehängt */
|
||||
*ordp = parse_order(s, u->faction->locale);
|
||||
|
@ -400,58 +403,58 @@ int readorders(const char *filename)
|
|||
const char *s;
|
||||
|
||||
switch (igetparam(b, lang)) {
|
||||
case P_LOCALE:
|
||||
s = getstrtoken();
|
||||
case P_LOCALE:
|
||||
s = getstrtoken();
|
||||
#undef LOCALE_CHANGE
|
||||
#ifdef LOCALE_CHANGE
|
||||
if (f && find_locale(s)) {
|
||||
f->locale = find_locale(s);
|
||||
}
|
||||
if (f && find_locale(s)) {
|
||||
f->locale = find_locale(s);
|
||||
}
|
||||
#endif
|
||||
|
||||
b = getbuf(F, enc_gamedata);
|
||||
break;
|
||||
case P_GAMENAME:
|
||||
case P_FACTION:
|
||||
f = factionorders();
|
||||
if (f) {
|
||||
++nfactions;
|
||||
}
|
||||
b = getbuf(F, enc_gamedata);
|
||||
break;
|
||||
case P_GAMENAME:
|
||||
case P_FACTION:
|
||||
f = factionorders();
|
||||
if (f) {
|
||||
++nfactions;
|
||||
}
|
||||
|
||||
b = getbuf(F, enc_gamedata);
|
||||
break;
|
||||
b = getbuf(F, enc_gamedata);
|
||||
break;
|
||||
|
||||
/* in factionorders wird nur eine zeile gelesen:
|
||||
* diejenige mit dem passwort. Die befehle der units
|
||||
* werden geloescht, und die Partei wird als aktiv
|
||||
* vermerkt. */
|
||||
/* in factionorders wird nur eine zeile gelesen:
|
||||
* diejenige mit dem passwort. Die befehle der units
|
||||
* werden geloescht, und die Partei wird als aktiv
|
||||
* vermerkt. */
|
||||
|
||||
case P_UNIT:
|
||||
if (!f || !unitorders(F, enc_gamedata, f))
|
||||
do {
|
||||
b = getbuf(F, enc_gamedata);
|
||||
if (!b)
|
||||
break;
|
||||
p = igetparam(b, lang);
|
||||
} while ((p != P_UNIT || !f) && p != P_FACTION && p != P_NEXT
|
||||
&& p != P_GAMENAME);
|
||||
break;
|
||||
case P_UNIT:
|
||||
if (!f || !unitorders(F, enc_gamedata, f))
|
||||
do {
|
||||
b = getbuf(F, enc_gamedata);
|
||||
if (!b)
|
||||
break;
|
||||
p = igetparam(b, lang);
|
||||
} while ((p != P_UNIT || !f) && p != P_FACTION && p != P_NEXT
|
||||
&& p != P_GAMENAME);
|
||||
break;
|
||||
|
||||
/* Falls in unitorders() abgebrochen wird, steht dort entweder eine neue
|
||||
* Partei, eine neue Einheit oder das File-Ende. Das switch() wird erneut
|
||||
* durchlaufen, und die entsprechende Funktion aufgerufen. Man darf buf
|
||||
* auf alle Fälle nicht überschreiben! Bei allen anderen Einträgen hier
|
||||
* muß buf erneut gefüllt werden, da die betreffende Information in nur
|
||||
* einer Zeile steht, und nun die nächste gelesen werden muß. */
|
||||
/* Falls in unitorders() abgebrochen wird, steht dort entweder eine neue
|
||||
* Partei, eine neue Einheit oder das File-Ende. Das switch() wird erneut
|
||||
* durchlaufen, und die entsprechende Funktion aufgerufen. Man darf buf
|
||||
* auf alle Fälle nicht überschreiben! Bei allen anderen Einträgen hier
|
||||
* muß buf erneut gefüllt werden, da die betreffende Information in nur
|
||||
* einer Zeile steht, und nun die nächste gelesen werden muß. */
|
||||
|
||||
case P_NEXT:
|
||||
f = NULL;
|
||||
b = getbuf(F, enc_gamedata);
|
||||
break;
|
||||
case P_NEXT:
|
||||
f = NULL;
|
||||
b = getbuf(F, enc_gamedata);
|
||||
break;
|
||||
|
||||
default:
|
||||
b = getbuf(F, enc_gamedata);
|
||||
break;
|
||||
default:
|
||||
b = getbuf(F, enc_gamedata);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -223,13 +223,15 @@ int rc_skillmod(const struct race *rc, const region * r, skill_t sk)
|
|||
{
|
||||
int mods;
|
||||
|
||||
if (!skill_enabled[sk])
|
||||
if (!skill_enabled[sk]) {
|
||||
return 0;
|
||||
}
|
||||
#ifdef FASTER_SKILLMOD
|
||||
unsigned int index = hashstring(rc->_name[0]) % RCMODMAXHASH;
|
||||
struct skillmods **imods = &modhash[index];
|
||||
while (*imods && (*imods)->race != rc)
|
||||
while (*imods && (*imods)->race != rc) {
|
||||
imods = &(*imods)->next;
|
||||
}
|
||||
if (*imods == NULL) {
|
||||
*imods = init_skills(rc);
|
||||
}
|
||||
|
@ -237,21 +239,19 @@ int rc_skillmod(const struct race *rc, const region * r, skill_t sk)
|
|||
#else
|
||||
mods = skill_mod(rc, sk, r->terrain);
|
||||
#endif
|
||||
if (rc == new_race[RC_ELF] && r_isforest(r))
|
||||
switch (sk) {
|
||||
case SK_PERCEPTION:
|
||||
if (rc == new_race[RC_ELF] && r_isforest(r)) {
|
||||
if (sk == SK_PERCEPTION) {
|
||||
++mods;
|
||||
} else if (sk == SK_STEALTH) {
|
||||
if (r_isforest(r)) {
|
||||
++mods;
|
||||
break;
|
||||
case SK_STEALTH:
|
||||
if (r_isforest(r))
|
||||
++mods;
|
||||
break;
|
||||
case SK_TACTICS:
|
||||
if (r_isforest(r))
|
||||
mods += 2;
|
||||
break;
|
||||
}
|
||||
} else if (sk == SK_TACTICS) {
|
||||
if (r_isforest(r)) {
|
||||
mods += 2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return mods;
|
||||
}
|
||||
|
||||
|
|
|
@ -170,7 +170,7 @@ enum {
|
|||
XMLSPL_WDWPYRAMID_ASTRAL = 185,
|
||||
XMLSPL_WDWPYRAMID_DRUIDE = 186,
|
||||
XMLSPL_WDWPYRAMID_BARDE = 187,
|
||||
XMLSPL_WDWPYRAMID_CHAOS = 188,
|
||||
XMLSPL_WDWPYRAMID_CHAOS = 188
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -60,7 +60,7 @@ static int txt_w_flt(struct storage *store, float arg)
|
|||
static float txt_r_flt(struct storage *store)
|
||||
{
|
||||
double result;
|
||||
fscanf((FILE *) store->userdata, "%f", &result);
|
||||
fscanf((FILE *) store->userdata, "%lf", &result);
|
||||
return (float)result;
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,7 @@ static int txt_open(struct storage *store, const char *filename, int mode)
|
|||
store->version = atoi(token);
|
||||
}
|
||||
} else if (store->encoding == XML_CHAR_ENCODING_UTF8) {
|
||||
fputs((const char*)utf8_bom, F);
|
||||
fputs((const char *)utf8_bom, F);
|
||||
fprintf(F, "%d\n", RELEASE_VERSION);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,18 +89,17 @@ int xecmd(unit * u, order * ord)
|
|||
|
||||
if (a_find(f->attribs, &at_xontormiaexpress)) {
|
||||
if (get_keyword(ord) == K_XE) {
|
||||
param_t param;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
switch (findparam(getstrtoken(), f->locale)) {
|
||||
case P_XEPOTION:
|
||||
xe_givepotion(u, ord);
|
||||
break;
|
||||
case P_XEBALLOON:
|
||||
xe_giveballon(u, ord);
|
||||
break;
|
||||
case P_XELAEN:
|
||||
xe_givelaen(u, ord);
|
||||
break;
|
||||
param = findparam(getstrtoken(), f->locale);
|
||||
if (param == P_XEPOTION) {
|
||||
xe_givepotion(u, ord);
|
||||
} else if (param == P_XEBALLOON) {
|
||||
xe_giveballon(u, ord);
|
||||
} else if (param == P_XELAEN) {
|
||||
xe_givelaen(u, ord);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue