- fixed bug that caused coordinates in planes to be adjusted in the wrong way.
This commit is contained in:
Enno Rehling 2010-01-20 08:05:55 +00:00
parent 610f278461
commit 4babc4e4c9
11 changed files with 33 additions and 45 deletions

View File

@ -310,8 +310,9 @@ cr_region(variant var, char * buffer, const void * userdata)
region * r = (region *)var.v;
if (r) {
plane * pl = rplane(r);
int nx = region_x(r, report), ny = region_y(r, report);
int nx = r->x, ny = r->y;
pnormalize(&nx, &ny, pl);
adjust_coordinates(report, &nx, &ny, pl, r);
sprintf(buffer, "%d %d %d", nx, ny, plane_id(pl));
return 0;
}
@ -424,9 +425,10 @@ cr_regions(variant var, char * buffer, const void * userdata)
plane * pl = rplane(r);
int i, z = plane_id(pl);
char * wp = buffer;
int nx = region_x(r, f), ny = region_y(r, f);
int nx = r->x, ny = r->y;
pnormalize(&nx, &ny, pl);
adjust_coordinates(f, &nx, &ny, pl, r);
wp += sprintf(wp, "\"%d %d %d", nx, ny, z);
for (i=1;i!=rdata->nregions;++i) {
r = rdata->regions[i];
@ -1147,9 +1149,9 @@ cr_output_region(FILE * F, report_context * ctx, seen_region * sr)
nx = r->x;
ny = r->y;
} else {
nx = region_x(r, f);
ny = region_y(r, f);
nx = r->x, ny = r->y;
pnormalize(&nx, &ny, pl);
adjust_coordinates(f, &nx, &ny, pl, r);
}
if (pl) {
@ -1278,8 +1280,10 @@ cr_output_region(FILE * F, report_context * ctx, seen_region * sr)
region_list *rl2 = rl;
while(rl2) {
region * r = rl2->data;
int nx = region_x(r, f), ny = region_y(r, f);
int nx = r->x, ny = r->y;
pnormalize(&nx, &ny, pl);
adjust_coordinates(f, &nx, &ny, pl, r);
fprintf(F, "SCHEMEN %d %d\n", nx, ny);
fprintf(F, "\"%s\";Name\n", rname(r, f->locale));
rl2 = rl2->next;
@ -1481,9 +1485,11 @@ report_computer(const char * filename, report_context * ctx, const char * charse
for (bm=f->battles;bm;bm=bm->next) {
plane * pl = rplane(bm->r);
int plid = plane_id(pl);
int nx = region_x(bm->r, f), ny = region_y(bm->r, f);
region * r = bm->r;
int nx = r->x, ny = r->y;
pnormalize(&nx, &ny, pl);
adjust_coordinates(f, &nx, &ny, pl, r);
if (!plid) fprintf(F, "BATTLE %d %d\n", nx, ny);
else {
fprintf(F, "BATTLE %d %d %d\n", nx, ny, plid);

View File

@ -1409,9 +1409,10 @@ report_template(const char * filename, report_context * ctx, const char * charse
order * ord;
if (!dh) {
plane * pl = getplane(r);
int nx = region_x(r, f), ny = region_y(r, f);
int nx = r->x, ny = r->y;
pnormalize(&nx, &ny, pl);
adjust_coordinates(f, &nx, &ny, pl, r);
rps_nowrap(F, "");
rnl(F);
if (pl && pl->id != 0) {

View File

@ -593,8 +593,10 @@ xml_region(report_context * ctx, seen_region * sr)
ship * sh = r->ships;
building * b = r->buildings;
plane * pl = rplane(r);
int nx = region_x(r, ctx->f), ny = region_y(r, ctx->f);
int nx = r->x, ny = r->y;
pnormalize(&nx, &ny, pl);
adjust_coordinates(ctx->f, &nx, &ny, pl, r);
/* TODO: entertain-quota, recruits, salary, prices, curses, borders, apparitions (Schemen), spells, travelthru, messages */
xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, xml_ref_region(r));

View File

@ -190,34 +190,6 @@ plane_center_y(const plane *pl)
return(pl->miny + pl->maxy)/2;
}
int
region_x(const region *r, const faction *f)
{
plane *pl = rplane(r);
int x = r->x - plane_center_x(pl);
if (f) {
int width = plane_width(pl);
int width_2 = width/2;
x -= ursprung_x(f, pl, r);
if (x>width_2) x -= width;
}
return x;
}
int
region_y(const region *r, const faction *f)
{
plane *pl = rplane(r);
int y = r->y - plane_center_y(pl);
if (f) {
int height = plane_height(pl);
int height_2 = height/2;
y -= ursprung_y(f, pl, r);
if (y>height_2) y -= height;
}
return y;
}
void
adjust_coordinates(const faction *f, int *x, int *y, const plane * pl, const region * r)
{

View File

@ -66,8 +66,6 @@ struct plane *findplane(int x, int y);
void init_planes(void);
int getplaneid(const struct region *r);
struct plane * getplanebyid(int id);
int region_x(const struct region *r, const struct faction *f);
int region_y(const struct region *r, const struct faction *f);
int plane_center_x(const struct plane *pl);
int plane_center_y(const struct plane *pl);
void set_ursprung(struct faction *f, int id, int x, int y);

View File

@ -119,8 +119,9 @@ write_regionname(const region * r, const faction * f, char * buffer, size_t size
strcpy(buf, "(null)");
} else {
plane * pl = rplane(r);
int nx = region_x(r, f), ny = region_y(r, f);
int nx = r->x, ny = r->y;
pnormalize(&nx, &ny, pl);
adjust_coordinates(f, &nx, &ny, pl, r);
snprintf(buf, size, "%s (%d,%d)", rname(r, lang), nx, ny);
}
buf[size-1] = 0;

View File

@ -36,6 +36,7 @@
/* libc includes */
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

View File

@ -105,11 +105,10 @@ trigger_type tt_changerace = {
trigger *
trigger_changerace(struct unit * u, const struct race * prace, const struct race * irace)
{
const race * uirace = u_irace(u);
trigger * t = t_new(&tt_changerace);
changerace_data * td = (changerace_data*)t->data.v;
assert(u->race==uirace || "!changerace-triggers cannot stack!");
assert(u->race==u_irace(u) || "!changerace-triggers cannot stack!");
td->u = u;
td->race = prace;
td->irace = irace;

View File

@ -11,6 +11,12 @@ EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "util", "common\util.vcproj", "{F70CFB27-8A2F-E447-B452-4E1C590EDA6D}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "eressea-lua", "eressea\eressea-lua.vcproj", "{75501170-51C2-E641-BA8B-EDC008184192}"
ProjectSection(ProjectDependencies) = postProject
{6F104C0A-DDF5-A34B-A89C-0DC278DCEF6D} = {6F104C0A-DDF5-A34B-A89C-0DC278DCEF6D}
{F70CFB27-8A2F-E447-B452-4E1C590EDA6D} = {F70CFB27-8A2F-E447-B452-4E1C590EDA6D}
{1E8BFF9E-3044-0742-992F-C5765B80FE65} = {1E8BFF9E-3044-0742-992F-C5765B80FE65}
{D893D6B3-805D-9848-8EA4-CDA1B79151F6} = {D893D6B3-805D-9848-8EA4-CDA1B79151F6}
EndProjectSection
EndProject
Global
GlobalSection(SubversionScc) = preSolution
@ -27,20 +33,22 @@ Global
{6F104C0A-DDF5-A34B-A89C-0DC278DCEF6D}.Profile|Win32.ActiveCfg = Profile|Win32
{6F104C0A-DDF5-A34B-A89C-0DC278DCEF6D}.Profile|Win32.Build.0 = Profile|Win32
{6F104C0A-DDF5-A34B-A89C-0DC278DCEF6D}.Release|Win32.ActiveCfg = Release|Win32
{6F104C0A-DDF5-A34B-A89C-0DC278DCEF6D}.Release|Win32.Build.0 = Release|Win32
{1E8BFF9E-3044-0742-992F-C5765B80FE65}.Debug|Win32.ActiveCfg = Debug|Win32
{1E8BFF9E-3044-0742-992F-C5765B80FE65}.Profile|Win32.ActiveCfg = Profile|Win32
{1E8BFF9E-3044-0742-992F-C5765B80FE65}.Profile|Win32.Build.0 = Profile|Win32
{1E8BFF9E-3044-0742-992F-C5765B80FE65}.Release|Win32.ActiveCfg = Release|Win32
{1E8BFF9E-3044-0742-992F-C5765B80FE65}.Release|Win32.Build.0 = Release|Win32
{D893D6B3-805D-9848-8EA4-CDA1B79151F6}.Debug|Win32.ActiveCfg = Debug|Win32
{D893D6B3-805D-9848-8EA4-CDA1B79151F6}.Profile|Win32.ActiveCfg = Profile|Win32
{D893D6B3-805D-9848-8EA4-CDA1B79151F6}.Profile|Win32.Build.0 = Profile|Win32
{D893D6B3-805D-9848-8EA4-CDA1B79151F6}.Release|Win32.ActiveCfg = Release|Win32
{D893D6B3-805D-9848-8EA4-CDA1B79151F6}.Release|Win32.Build.0 = Release|Win32
{AD80EB0B-7CB4-42F2-9C95-8CCEF68DB387}.Debug|Win32.ActiveCfg = Debug|Win32
{AD80EB0B-7CB4-42F2-9C95-8CCEF68DB387}.Debug|Win32.Build.0 = Debug|Win32
{AD80EB0B-7CB4-42F2-9C95-8CCEF68DB387}.Profile|Win32.ActiveCfg = Release|Win32
{AD80EB0B-7CB4-42F2-9C95-8CCEF68DB387}.Profile|Win32.Build.0 = Release|Win32
{AD80EB0B-7CB4-42F2-9C95-8CCEF68DB387}.Release|Win32.ActiveCfg = Release|Win32
{AD80EB0B-7CB4-42F2-9C95-8CCEF68DB387}.Release|Win32.Build.0 = Release|Win32
{F70CFB27-8A2F-E447-B452-4E1C590EDA6D}.Debug|Win32.ActiveCfg = Debug|Win32
{F70CFB27-8A2F-E447-B452-4E1C590EDA6D}.Profile|Win32.ActiveCfg = Profile|Win32
{F70CFB27-8A2F-E447-B452-4E1C590EDA6D}.Profile|Win32.Build.0 = Profile|Win32

View File

@ -210,7 +210,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="3"
AdditionalIncludeDirectories="..;../common"
AdditionalIncludeDirectories="..;../common;../external"
PreprocessorDefinitions="WIN32;_CRT_SECURE_NO_DEPRECATE;NDEBUG"
StringPooling="true"
RuntimeLibrary="2"

View File

@ -700,9 +700,9 @@ tolua_get_region(lua_State* L)
{
int x = (int)tolua_tonumber(L, 1, 0);
int y = (int)tolua_tonumber(L, 2, 0);
struct plane * pl = findplane(x, y);
region * r;
assert(!pnormalize(&x, &y, pl));
assert(!pnormalize(&x, &y, findplane(x, y)));
r = findregion(x, y);
tolua_pushusertype(L, r, TOLUA_CAST "region");