forked from github/server
Merge pull request #91 from badgerman/master
kill EnhancedQuit and other dead code
This commit is contained in:
commit
14bb27d89c
|
@ -112,7 +112,13 @@ static int object_read(attrib * a, void *owner, struct storage *store)
|
|||
break;
|
||||
case TREAL:
|
||||
READ_FLT(store, &flt);
|
||||
if ((int)flt == flt) {
|
||||
data->type = TINTEGER;
|
||||
data->data.i = (int)flt;
|
||||
}
|
||||
else {
|
||||
data->data.real = flt;
|
||||
}
|
||||
break;
|
||||
case TSTRING:
|
||||
READ_STR(store, name, sizeof(name));
|
||||
|
|
|
@ -885,7 +885,7 @@ static int read_newunitid(const faction * f, const region * r)
|
|||
|
||||
int read_unitid(const faction * f, const region * r)
|
||||
{
|
||||
char token[8];
|
||||
char token[16];
|
||||
const char *s = gettoken(token, sizeof(token));
|
||||
|
||||
/* Da s nun nur einen string enthaelt, suchen wir ihn direkt in der
|
||||
|
|
69
src/laws.c
69
src/laws.c
|
@ -63,7 +63,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/unit.h>
|
||||
|
||||
/* attributes includes */
|
||||
#include <attributes/object.h>
|
||||
#include <attributes/racename.h>
|
||||
#include <attributes/raceprefix.h>
|
||||
#include <attributes/stealth.h>
|
||||
|
@ -819,20 +818,6 @@ static void inactivefaction(faction * f)
|
|||
}
|
||||
}
|
||||
|
||||
static void transfer_faction(faction * f, faction * f2)
|
||||
{
|
||||
unit *u, *un;
|
||||
|
||||
for (u = f->units; u;) {
|
||||
un = u->nextF;
|
||||
if (!unit_has_cursed_item(u)
|
||||
&& !has_skill(u, SK_MAGIC) && !has_skill(u, SK_ALCHEMY)) {
|
||||
u_setfaction(u, f2);
|
||||
}
|
||||
u = un;
|
||||
}
|
||||
}
|
||||
|
||||
/* test if the unit can slip through a siege undetected.
|
||||
* returns 0 if siege is successful, or 1 if the building is either
|
||||
* not besieged or the unit can slip through the siege due to better stealth.
|
||||
|
@ -934,16 +919,6 @@ int leave_cmd(unit * u, struct order *ord)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static bool EnhancedQuit(void)
|
||||
{
|
||||
static int value = -1;
|
||||
if (value < 0) {
|
||||
const char *str = get_param(global.parameters, "alliance.transferquit");
|
||||
value = (str != 0 && strcmp(str, "true") == 0);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
int quit_cmd(unit * u, struct order *ord)
|
||||
{
|
||||
char token[128];
|
||||
|
@ -955,31 +930,6 @@ int quit_cmd(unit * u, struct order *ord)
|
|||
assert(kwd == K_QUIT);
|
||||
passwd = gettoken(token, sizeof(token));
|
||||
if (checkpasswd(f, (const char *)passwd)) {
|
||||
if (EnhancedQuit()) {
|
||||
int f2_id = getid();
|
||||
if (f2_id > 0) {
|
||||
faction *f2 = findfaction(f2_id);
|
||||
|
||||
if (f2 == NULL) {
|
||||
cmistake(u, ord, 66, MSG_EVENT);
|
||||
return 0;
|
||||
}
|
||||
else if (!u->faction->alliance
|
||||
|| u->faction->alliance != f2->alliance) {
|
||||
cmistake(u, ord, 315, MSG_EVENT);
|
||||
return 0;
|
||||
}
|
||||
else if (!alliedfaction(NULL, f, f2, HELP_MONEY)) {
|
||||
cmistake(u, ord, 316, MSG_EVENT);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
variant var;
|
||||
var.i = f2_id;
|
||||
a_add(&f->attribs, object_create("quit", TINTEGER, var));
|
||||
}
|
||||
}
|
||||
}
|
||||
fset(f, FFL_QUIT);
|
||||
}
|
||||
else {
|
||||
|
@ -1299,25 +1249,6 @@ void quit(void)
|
|||
while (*fptr) {
|
||||
faction *f = *fptr;
|
||||
if (f->flags & FFL_QUIT) {
|
||||
if (EnhancedQuit()) {
|
||||
/* this doesn't work well (use object_name()) */
|
||||
attrib *a = a_find(f->attribs, &at_object);
|
||||
if (a) {
|
||||
variant var;
|
||||
object_type type;
|
||||
var.i = 0;
|
||||
object_get(a, &type, &var);
|
||||
assert(var.i && type == TINTEGER);
|
||||
if (var.i) {
|
||||
int f2_id = var.i;
|
||||
faction *f2 = findfaction(f2_id);
|
||||
|
||||
assert(f2_id > 0);
|
||||
assert(f2 != NULL);
|
||||
transfer_faction(f, f2);
|
||||
}
|
||||
}
|
||||
}
|
||||
destroyfaction(f);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -120,7 +120,7 @@ void skip_token(void)
|
|||
}
|
||||
}
|
||||
|
||||
char *parse_token(const char **str, char *lbuf, size_t len)
|
||||
char *parse_token(const char **str, char *lbuf, size_t buflen)
|
||||
{
|
||||
char *cursor = lbuf;
|
||||
char quotechar = 0;
|
||||
|
@ -132,12 +132,12 @@ char *parse_token(const char **str, char *lbuf, size_t len)
|
|||
}
|
||||
eatwhitespace_c(&ctoken);
|
||||
if (!*ctoken) {
|
||||
if (len > 0) {
|
||||
if (buflen > 0) {
|
||||
*cursor = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
while (*ctoken && cursor-len < lbuf-1) {
|
||||
while (*ctoken) {
|
||||
ucs4_t ucs;
|
||||
size_t len;
|
||||
bool copy = false;
|
||||
|
@ -188,13 +188,14 @@ char *parse_token(const char **str, char *lbuf, size_t len)
|
|||
copy = true;
|
||||
}
|
||||
if (copy) {
|
||||
if (cursor - buflen < lbuf - 1) {
|
||||
memcpy(cursor, ctoken, len);
|
||||
cursor += len;
|
||||
}
|
||||
ctoken += len;
|
||||
}
|
||||
}
|
||||
|
||||
assert(cursor - len < lbuf - 1); // TODO: handle too-small buffers
|
||||
*cursor = '\0';
|
||||
*str = ctoken;
|
||||
return lbuf;
|
||||
|
@ -232,7 +233,7 @@ unsigned int getuint(void)
|
|||
|
||||
int getid(void)
|
||||
{
|
||||
char token[16];
|
||||
char token[8];
|
||||
const char *str = gettoken(token, sizeof(token));
|
||||
int i = str ? atoi36(str) : 0;
|
||||
if (i < 0) {
|
||||
|
|
|
@ -15,6 +15,18 @@ static void test_gettoken(CuTest *tc) {
|
|||
CuAssertStrEquals(tc, "", token);
|
||||
}
|
||||
|
||||
static void test_gettoken_short(CuTest *tc) {
|
||||
char token[3];
|
||||
init_tokens_str("HELP ONE TWO THREE");
|
||||
CuAssertStrEquals(tc, "HE", gettoken(token, sizeof(token)));
|
||||
CuAssertStrEquals(tc, "HE", token);
|
||||
CuAssertStrEquals(tc, "ON", gettoken(token, sizeof(token)));
|
||||
CuAssertStrEquals(tc, "TW", gettoken(token, sizeof(token)));
|
||||
CuAssertStrEquals(tc, "TH", gettoken(token, sizeof(token)));
|
||||
CuAssertPtrEquals(tc, NULL, (void *)gettoken(token, sizeof(token)));
|
||||
CuAssertStrEquals(tc, "", token);
|
||||
}
|
||||
|
||||
static void test_skip_token(CuTest *tc) {
|
||||
char token[128];
|
||||
init_tokens_str("HELP ONE TWO THREE");
|
||||
|
@ -53,6 +65,7 @@ CuSuite *get_parser_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_atoip);
|
||||
SUITE_ADD_TEST(suite, test_skip_token);
|
||||
SUITE_ADD_TEST(suite, test_gettoken);
|
||||
SUITE_ADD_TEST(suite, test_gettoken_short);
|
||||
SUITE_ADD_TEST(suite, test_getintegers);
|
||||
SUITE_ADD_TEST(suite, test_getstrtoken);
|
||||
return suite;
|
||||
|
|
Loading…
Reference in New Issue