forked from github/server
refactor: extract cycle_route and test it (with PAUSE).
This commit is contained in:
parent
915706d6f8
commit
fc4b7ba73d
|
@ -43,7 +43,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
typedef enum {
|
||||
typedef enum dict_type {
|
||||
TNONE = 0, TINTEGER = 1, TREAL = 2
|
||||
} dict_type;
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ extern "C"
|
|||
|
||||
struct locale;
|
||||
|
||||
typedef enum {
|
||||
typedef enum direction_t {
|
||||
D_NORTHWEST,
|
||||
D_NORTHEAST,
|
||||
D_EAST,
|
||||
|
|
|
@ -3548,7 +3548,7 @@ enum {
|
|||
PROC_LONGORDER = 1 << 1
|
||||
};
|
||||
|
||||
typedef enum { PR_GLOBAL, PR_REGION_PRE, PR_UNIT, PR_ORDER, PR_REGION_POST } processor_t;
|
||||
typedef enum processor_t { PR_GLOBAL, PR_REGION_PRE, PR_UNIT, PR_ORDER, PR_REGION_POST } processor_t;
|
||||
|
||||
typedef struct processor {
|
||||
struct processor *next;
|
||||
|
|
22
src/move.c
22
src/move.c
|
@ -1052,7 +1052,7 @@ int movewhere(const unit * u, const char *token, region * r, region ** resultp)
|
|||
return E_MOVE_OK;
|
||||
}
|
||||
|
||||
static void cycle_route(order * ord, unit * u, int gereist)
|
||||
order * cycle_route(order * ord, const struct locale *lang, int gereist)
|
||||
{
|
||||
int cm = 0;
|
||||
char tail[1024], *bufp = tail;
|
||||
|
@ -1067,11 +1067,10 @@ static void cycle_route(order * ord, unit * u, int gereist)
|
|||
assert(getkeyword(ord) == K_ROUTE);
|
||||
tail[0] = '\0';
|
||||
neworder[0] = '\0';
|
||||
init_order(ord, u->faction->locale);
|
||||
init_order(ord, lang);
|
||||
|
||||
for (cm = 0;; ++cm) {
|
||||
const char *s;
|
||||
const struct locale *lang = u->faction->locale;
|
||||
pause = false;
|
||||
s = gettoken(token, sizeof(token));
|
||||
if (s && *s) {
|
||||
|
@ -1087,7 +1086,7 @@ static void cycle_route(order * ord, unit * u, int gereist)
|
|||
break;
|
||||
}
|
||||
if (cm < gereist) {
|
||||
/* hier sollte keine PAUSE auftreten */
|
||||
/* TODO: hier sollte keine PAUSE auftreten */
|
||||
assert(!pause);
|
||||
if (!pause) {
|
||||
const char *loc = LOC(lang, shortdirections[d]);
|
||||
|
@ -1124,13 +1123,12 @@ static void cycle_route(order * ord, unit * u, int gereist)
|
|||
}
|
||||
|
||||
if (neworder[0]) {
|
||||
norder = create_order(K_ROUTE, u->faction->locale, "%s %s", neworder, tail);
|
||||
norder = create_order(K_ROUTE, lang, "%s %s", neworder, tail);
|
||||
}
|
||||
else {
|
||||
norder = create_order(K_ROUTE, u->faction->locale, "%s", tail);
|
||||
norder = create_order(K_ROUTE, lang, "%s", tail);
|
||||
}
|
||||
replace_order(&u->orders, ord, norder);
|
||||
free_order(norder);
|
||||
return norder;
|
||||
}
|
||||
|
||||
static bool transport(unit * ut, unit * u)
|
||||
|
@ -1605,7 +1603,9 @@ static const region_list *travel_route(unit * u,
|
|||
|
||||
setguard(u, false);
|
||||
if (getkeyword(ord) == K_ROUTE) {
|
||||
cycle_route(ord, u, steps);
|
||||
order * norder = cycle_route(ord, u->faction->locale, steps);
|
||||
replace_order(&u->orders, ord, norder);
|
||||
free_order(norder);
|
||||
}
|
||||
|
||||
if (mode == TRAVEL_RUNNING) {
|
||||
|
@ -1937,7 +1937,9 @@ static void sail(unit * u, order * ord, region_list ** routep, bool drifting)
|
|||
/* nachdem alle Richtungen abgearbeitet wurden, und alle Einheiten
|
||||
* transferiert wurden, kann der aktuelle Befehl gelöscht werden. */
|
||||
if (getkeyword(ord) == K_ROUTE) {
|
||||
cycle_route(ord, u, step);
|
||||
order * norder = cycle_route(ord, u->faction->locale, step);
|
||||
replace_order(&u->orders, ord, norder);
|
||||
free_order(norder);
|
||||
}
|
||||
set_order(&u->thisorder, NULL);
|
||||
set_coast(sh, last_point, current_point);
|
||||
|
|
|
@ -26,12 +26,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct unit;
|
||||
struct attrib_type;
|
||||
struct building_type;
|
||||
struct locale;
|
||||
struct order;
|
||||
struct region;
|
||||
struct region_list;
|
||||
struct ship;
|
||||
struct building_type;
|
||||
struct order;
|
||||
struct unit;
|
||||
|
||||
extern struct attrib_type at_shiptrail;
|
||||
extern int *storms;
|
||||
|
@ -95,6 +97,7 @@ extern "C" {
|
|||
|
||||
int check_ship_allowed(struct ship *sh, const struct region * r);
|
||||
direction_t drift_target(struct ship *sh);
|
||||
struct order * cycle_route(struct order * ord, const struct locale *lang, int gereist);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -593,6 +593,30 @@ static void test_route_cycle(CuTest *tc) {
|
|||
test_teardown();
|
||||
}
|
||||
|
||||
static void test_cycle_route(CuTest *tc) {
|
||||
struct locale *lang;
|
||||
char buffer[32];
|
||||
order *ord, *onew;
|
||||
|
||||
test_setup();
|
||||
lang = test_create_locale();
|
||||
CuAssertPtrNotNull(tc, LOC(lang, shortdirections[D_WEST]));
|
||||
|
||||
ord = create_order(K_ROUTE, lang, "WEST EAST PAUSE NW");
|
||||
CuAssertStrEquals(tc, "route WEST EAST PAUSE NW", get_command(ord, lang, buffer, sizeof(buffer)));
|
||||
|
||||
onew = cycle_route(ord, lang, 1);
|
||||
CuAssertStrEquals(tc, "route east PAUSE nw west", get_command(onew, lang, buffer, sizeof(buffer)));
|
||||
free_order(onew);
|
||||
|
||||
onew = cycle_route(ord, lang, 2);
|
||||
CuAssertStrEquals(tc, "route nw west east PAUSE", get_command(onew, lang, buffer, sizeof(buffer)));
|
||||
free_order(onew);
|
||||
|
||||
free_order(ord);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
static void test_route_pause(CuTest *tc) {
|
||||
unit *u;
|
||||
region *r;
|
||||
|
@ -658,6 +682,7 @@ CuSuite *get_move_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_follow_ship_msg);
|
||||
SUITE_ADD_TEST(suite, test_drifting_ships);
|
||||
SUITE_ADD_TEST(suite, test_route_cycle);
|
||||
SUITE_ADD_TEST(suite, test_cycle_route);
|
||||
SUITE_ADD_TEST(suite, test_route_pause);
|
||||
return suite;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue