|
@@ -59,108 +59,108 @@ typedef struct ParentSpriteToDraw {
|
|
|
byte unk16;
|
|
|
byte tile_z;
|
|
|
byte tile_z_bottom;
|
|
|
} ParentSpriteToDraw;
|
|
|
|
|
|
// Quick hack to know how much memory to reserve when allocating from the spritelist
|
|
|
// to prevent a buffer overflow.
|
|
|
#define LARGEST_SPRITELIST_STRUCT ParentSpriteToDraw
|
|
|
|
|
|
typedef struct ViewportDrawer {
|
|
|
DrawPixelInfo dpi;
|
|
|
|
|
|
byte *spritelist_mem, *eof_spritelist_mem;
|
|
|
byte *spritelist_mem;
|
|
|
const byte *eof_spritelist_mem;
|
|
|
|
|
|
StringSpriteToDraw **last_string, *first_string;
|
|
|
TileSpriteToDraw **last_tile, *first_tile;
|
|
|
|
|
|
ChildScreenSpriteToDraw **last_child;
|
|
|
|
|
|
ParentSpriteToDraw **parent_list;
|
|
|
ParentSpriteToDraw **eof_parent_list;
|
|
|
ParentSpriteToDraw * const *eof_parent_list;
|
|
|
|
|
|
byte combine_sprites;
|
|
|
|
|
|
int offs_x, offs_y; // used when drawing ground sprites relative
|
|
|
bool ground_child;
|
|
|
} ViewportDrawer;
|
|
|
|
|
|
static ViewportDrawer *_cur_vd;
|
|
|
|
|
|
TileHighlightData _thd;
|
|
|
static TileInfo *_cur_ti;
|
|
|
|
|
|
|
|
|
Point MapXYZToViewport(ViewPort *vp, uint x, uint y, uint z)
|
|
|
static Point MapXYZToViewport(const ViewPort *vp, uint x, uint y, uint z)
|
|
|
{
|
|
|
Point p = RemapCoords(x, y, z);
|
|
|
p.x -= (vp->virtual_width>>1);
|
|
|
p.y -= (vp->virtual_height>>1);
|
|
|
p.x -= vp->virtual_width / 2;
|
|
|
p.y -= vp->virtual_height / 2;
|
|
|
return p;
|
|
|
}
|
|
|
|
|
|
void AssignWindowViewport(Window *w, int x, int y,
|
|
|
int width, int height, uint32 follow_flags, byte zoom)
|
|
|
{
|
|
|
ViewPort *vp;
|
|
|
Point pt;
|
|
|
byte z;
|
|
|
uint32 bit;
|
|
|
|
|
|
for(vp=_viewports,bit=1; ; vp++, bit<<=1) {
|
|
|
assert(vp!=endof(_viewports));
|
|
|
if (vp->width == 0)
|
|
|
break;
|
|
|
for (vp = _viewports, bit = 1; ; vp++, bit <<= 1) {
|
|
|
assert(vp != endof(_viewports));
|
|
|
if (vp->width == 0) break;
|
|
|
}
|
|
|
_active_viewports |= bit;
|
|
|
|
|
|
vp->left = x + w->left;
|
|
|
vp->top = y + w->top;
|
|
|
vp->width = width;
|
|
|
vp->height = height;
|
|
|
|
|
|
vp->zoom = zoom;
|
|
|
|
|
|
vp->virtual_width = width << zoom;
|
|
|
vp->virtual_height = height << zoom;
|
|
|
|
|
|
if (follow_flags & 0x80000000) {
|
|
|
Vehicle *veh;
|
|
|
WP(w,vp_d).follow_vehicle = (VehicleID)(follow_flags & 0xFFFF);
|
|
|
veh = GetVehicle(WP(w,vp_d).follow_vehicle);
|
|
|
const Vehicle *veh;
|
|
|
|
|
|
WP(w, vp_d).follow_vehicle = (VehicleID)(follow_flags & 0xFFFF);
|
|
|
veh = GetVehicle(WP(w, vp_d).follow_vehicle);
|
|
|
pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos);
|
|
|
} else {
|
|
|
int x = TileX(follow_flags) * 16;
|
|
|
int y = TileY(follow_flags) * 16;
|
|
|
WP(w,vp_d).follow_vehicle = INVALID_VEHICLE;
|
|
|
z = GetSlopeZ(x,y);
|
|
|
pt = MapXYZToViewport(vp, x,y, z);
|
|
|
uint x = TileX(follow_flags) * 16;
|
|
|
uint y = TileY(follow_flags) * 16;
|
|
|
|
|
|
WP(w, vp_d).follow_vehicle = INVALID_VEHICLE;
|
|
|
pt = MapXYZToViewport(vp, x, y, GetSlopeZ(x, y));
|
|
|
}
|
|
|
|
|
|
WP(w,vp_d).scrollpos_x = pt.x;
|
|
|
WP(w,vp_d).scrollpos_y = pt.y;
|
|
|
WP(w, vp_d).scrollpos_x = pt.x;
|
|
|
WP(w, vp_d).scrollpos_y = pt.y;
|
|
|
w->viewport = vp;
|
|
|
vp->virtual_left = 0;//pt.x;
|
|
|
vp->virtual_top = 0;//pt.y;
|
|
|
}
|
|
|
|
|
|
static Point _vp_move_offs;
|
|
|
|
|
|
static void DoSetViewportPosition(Window *w, int left, int top, int width, int height)
|
|
|
{
|
|
|
for (; w < _last_window; w++) {
|
|
|
if (left + width > w->left &&
|
|
|
w->left+w->width > left &&
|
|
|
w->left + w->width > left &&
|
|
|
top + height > w->top &&
|
|
|
w->top+w->height > top) {
|
|
|
w->top + w->height > top) {
|
|
|
|
|
|
if (left < w->left) {
|
|
|
DoSetViewportPosition(w, left, top, w->left - left, height);
|
|
|
DoSetViewportPosition(w, left + (w->left - left), top, width - (w->left - left), height);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (left + width > w->left + w->width) {
|
|
|
DoSetViewportPosition(w, left, top, (w->left + w->width - left), height);
|
|
|
DoSetViewportPosition(w, left + (w->left + w->width - left), top, width - (w->left + w->width - left) , height);
|
|
|
return;
|
|
|
}
|
|
@@ -178,25 +178,25 @@ static void DoSetViewportPosition(Window
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
{
|
|
|
int xo = _vp_move_offs.x;
|
|
|
int yo = _vp_move_offs.y;
|
|
|
|
|
|
if (abs(xo) >= width || abs(yo) >= height) {
|
|
|
/* fully_outside */
|
|
|
RedrawScreenRect(left, top, left+width, top+height);
|
|
|
RedrawScreenRect(left, top, left + width, top + height);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
GfxScroll(left, top, width, height, xo, yo);
|
|
|
|
|
|
if (xo > 0) {
|
|
|
RedrawScreenRect(left, top, xo + left, top + height);
|
|
|
left += xo;
|
|
|
width -= xo;
|
|
|
} else if (xo < 0) {
|
|
|
RedrawScreenRect(left+width+xo, top, left+width, top + height);
|
|
|
width += xo;
|
|
@@ -220,71 +220,69 @@ void SetViewportPosition(Window *w, int
|
|
|
|
|
|
vp->virtual_left = x;
|
|
|
vp->virtual_top = y;
|
|
|
|
|
|
old_left >>= vp->zoom;
|
|
|
old_top >>= vp->zoom;
|
|
|
x >>= vp->zoom;
|
|
|
y >>= vp->zoom;
|
|
|
|
|
|
old_left -= x;
|
|
|
old_top -= y;
|
|
|
|
|
|
if (old_top == 0 && old_left == 0)
|
|
|
return;
|
|
|
if (old_top == 0 && old_left == 0) return;
|
|
|
|
|
|
_vp_move_offs.x = old_left;
|
|
|
_vp_move_offs.y = old_top;
|
|
|
|
|
|
left = vp->left;
|
|
|
top = vp->top;
|
|
|
width = vp->width;
|
|
|
height = vp->height;
|
|
|
|
|
|
if (left < 0) {
|
|
|
width += left;
|
|
|
left = 0;
|
|
|
}
|
|
|
|
|
|
if ( (i=(left + width - _screen.width)) >= 0)
|
|
|
width -= i;
|
|
|
i = left + width - _screen.width;
|
|
|
if (i >= 0) width -= i;
|
|
|
|
|
|
if (width > 0) {
|
|
|
if (top < 0) {
|
|
|
height += top;
|
|
|
top = 0;
|
|
|
}
|
|
|
|
|
|
if ( (i=(top + height - _screen.height)) >= 0) {
|
|
|
height -= i;
|
|
|
}
|
|
|
i = top + height - _screen.height;
|
|
|
if (i >= 0) height -= i;
|
|
|
|
|
|
if (height > 0)
|
|
|
DoSetViewportPosition(w+1, left, top, width, height);
|
|
|
if (height > 0) DoSetViewportPosition(w + 1, left, top, width, height);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
ViewPort *IsPtInWindowViewport(Window *w, int x, int y)
|
|
|
ViewPort *IsPtInWindowViewport(const Window *w, int x, int y)
|
|
|
{
|
|
|
ViewPort *vp = w->viewport;
|
|
|
|
|
|
if (vp != NULL &&
|
|
|
IS_INT_INSIDE(x, vp->left, vp->left + vp->width) &&
|
|
|
IS_INT_INSIDE(y, vp->top, vp->top + vp->height))
|
|
|
return vp;
|
|
|
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
static Point TranslateXYToTileCoord(ViewPort *vp, int x, int y)
|
|
|
static Point TranslateXYToTileCoord(const ViewPort *vp, int x, int y)
|
|
|
{
|
|
|
int z;
|
|
|
Point pt;
|
|
|
int a,b;
|
|
|
|
|
|
if ( (uint)(x -= vp->left) >= (uint)vp->width ||
|
|
|
(uint)(y -= vp->top) >= (uint)vp->height) {
|
|
|
Point pt = {-1, -1};
|
|
|
return pt;
|
|
|
}
|
|
|
|
|
|
x = ((x << vp->zoom) + vp->virtual_left) >> 2;
|
|
@@ -335,47 +333,46 @@ Point GetTileBelowCursor(void)
|
|
|
return GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y, _cursor.pos.x, _cursor.pos.y);
|
|
|
}
|
|
|
|
|
|
|
|
|
Point GetTileZoomCenterWindow(bool in, Window * w)
|
|
|
{
|
|
|
int x, y;
|
|
|
ViewPort * vp;
|
|
|
|
|
|
vp = w->viewport;
|
|
|
|
|
|
if (in) {
|
|
|
x = ( (_cursor.pos.x - vp->left ) >> 1) + (vp->width >> 2);
|
|
|
y = ( (_cursor.pos.y - vp->top ) >> 1) + (vp->height >> 2);
|
|
|
}
|
|
|
else {
|
|
|
x = ((_cursor.pos.x - vp->left) >> 1) + (vp->width >> 2);
|
|
|
y = ((_cursor.pos.y - vp->top) >> 1) + (vp->height >> 2);
|
|
|
} else {
|
|
|
x = vp->width - (_cursor.pos.x - vp->left);
|
|
|
y = vp->height - (_cursor.pos.y - vp->top);
|
|
|
}
|
|
|
/* Get the tile below the cursor and center on the zoomed-out center */
|
|
|
return GetTileFromScreenXY(_cursor.pos.x, _cursor.pos.y, x + vp->left, y + vp->top);
|
|
|
}
|
|
|
|
|
|
void DrawGroundSpriteAt(uint32 image, int32 x, int32 y, byte z)
|
|
|
{
|
|
|
ViewportDrawer *vd = _cur_vd;
|
|
|
TileSpriteToDraw *ts;
|
|
|
|
|
|
assert( (image & 0x3fff) < NUM_SPRITES);
|
|
|
assert((image & 0x3FFF) < NUM_SPRITES);
|
|
|
|
|
|
ts = (TileSpriteToDraw*)vd->spritelist_mem;
|
|
|
if ((byte*)ts >= vd->eof_spritelist_mem) {
|
|
|
if (vd->spritelist_mem >= vd->eof_spritelist_mem) {
|
|
|
DEBUG(misc, 0) ("Out of sprite mem");
|
|
|
return;
|
|
|
}
|
|
|
ts = (TileSpriteToDraw*)vd->spritelist_mem;
|
|
|
|
|
|
vd->spritelist_mem += sizeof(TileSpriteToDraw);
|
|
|
|
|
|
ts->image = image;
|
|
|
ts->next = NULL;
|
|
|
ts->x = x;
|
|
|
ts->y = y;
|
|
|
ts->z = z;
|
|
|
*vd->last_tile = ts;
|
|
|
vd->last_tile = &ts->next;
|
|
|
}
|
|
|
|
|
@@ -391,63 +388,60 @@ void DrawGroundSprite(uint32 image)
|
|
|
}
|
|
|
|
|
|
|
|
|
void OffsetGroundSprite(int x, int y)
|
|
|
{
|
|
|
_cur_vd->offs_x = x;
|
|
|
_cur_vd->offs_y = y;
|
|
|
_offset_ground_sprites = true;
|
|
|
}
|
|
|
|
|
|
static void AddCombinedSprite(uint32 image, int x, int y, byte z)
|
|
|
{
|
|
|
ViewportDrawer *vd = _cur_vd;
|
|
|
int t;
|
|
|
uint32 image_org = image;
|
|
|
const SpriteDimension *sd;
|
|
|
const ViewportDrawer *vd = _cur_vd;
|
|
|
Point pt = RemapCoords(x, y, z);
|
|
|
const SpriteDimension *sd = GetSpriteDimension(image & 0x3FFF);
|
|
|
|
|
|
sd = GetSpriteDimension(image & 0x3FFF);
|
|
|
|
|
|
if ((t = pt.x + sd->xoffs) >= vd->dpi.left + vd->dpi.width ||
|
|
|
(t + sd->xsize) <= vd->dpi.left ||
|
|
|
(t = pt.y + sd->yoffs) >= vd->dpi.top + vd->dpi.height ||
|
|
|
(t + sd->ysize) <= vd->dpi.top)
|
|
|
if (pt.x + sd->xoffs >= vd->dpi.left + vd->dpi.width ||
|
|
|
pt.x + sd->xoffs + sd->xsize <= vd->dpi.left ||
|
|
|
pt.y + sd->yoffs >= vd->dpi.top + vd->dpi.height ||
|
|
|
pt.y + sd->yoffs + sd->ysize <= vd->dpi.top)
|
|
|
return;
|
|
|
|
|
|
AddChildSpriteScreen(image_org, pt.x - vd->parent_list[-1]->left, pt.y - vd->parent_list[-1]->top);
|
|
|
AddChildSpriteScreen(image, pt.x - vd->parent_list[-1]->left, pt.y - vd->parent_list[-1]->top);
|
|
|
}
|
|
|
|
|
|
|
|
|
void AddSortableSpriteToDraw(uint32 image, int x, int y, int w, int h, byte dz, byte z)
|
|
|
{
|
|
|
ViewportDrawer *vd = _cur_vd;
|
|
|
ParentSpriteToDraw *ps;
|
|
|
const SpriteDimension *sd;
|
|
|
Point pt;
|
|
|
|
|
|
assert( (image & 0x3fff) < NUM_SPRITES);
|
|
|
assert((image & 0x3FFF) < NUM_SPRITES);
|
|
|
|
|
|
if (vd->combine_sprites == 2) {
|
|
|
AddCombinedSprite(image, x, y, z);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
vd->last_child = NULL;
|
|
|
|
|
|
ps = (ParentSpriteToDraw*)vd->spritelist_mem;
|
|
|
if ((byte*)ps >= vd->eof_spritelist_mem) {
|
|
|
if (vd->spritelist_mem >= vd->eof_spritelist_mem) {
|
|
|
DEBUG(misc, 0) ("Out of sprite mem");
|
|
|
return;
|
|
|
}
|
|
|
ps = (ParentSpriteToDraw*)vd->spritelist_mem;
|
|
|
|
|
|
if (vd->parent_list >= vd->eof_parent_list) {
|
|
|
// This can happen rarely, mostly when you zoom out completely
|
|
|
// and have a lot of stuff that moves (and is added to the
|
|
|
// sort-list, this function). To solve it, increase
|
|
|
// parent_list somewhere below to a higher number.
|
|
|
// This can not really hurt you, it just gives some black
|
|
|
// spots on the screen ;)
|
|
|
DEBUG(misc, 0) ("Out of sprite mem (parent_list)");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
vd->spritelist_mem += sizeof(ParentSpriteToDraw);
|
|
@@ -469,144 +463,143 @@ void AddSortableSpriteToDraw(uint32 imag
|
|
|
(ps->right = (pt.x + sd->xsize)) <= vd->dpi.left ||
|
|
|
(ps->top = (pt.y += sd->yoffs)) >= vd->dpi.top + vd->dpi.height ||
|
|
|
(ps->bottom = (pt.y + sd->ysize)) <= vd->dpi.top) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
ps->unk16 = 0;
|
|
|
ps->child = NULL;
|
|
|
vd->last_child = &ps->child;
|
|
|
|
|
|
*vd->parent_list++ = ps;
|
|
|
|
|
|
if (vd->combine_sprites == 1) {
|
|
|
vd->combine_sprites = 2;
|
|
|
}
|
|
|
if (vd->combine_sprites == 1) vd->combine_sprites = 2;
|
|
|
}
|
|
|
|
|
|
void StartSpriteCombine(void)
|
|
|
{
|
|
|
_cur_vd->combine_sprites = 1;
|
|
|
}
|
|
|
|
|
|
void EndSpriteCombine(void)
|
|
|
{
|
|
|
_cur_vd->combine_sprites = 0;
|
|
|
}
|
|
|
|
|
|
void AddChildSpriteScreen(uint32 image, int x, int y)
|
|
|
{
|
|
|
ViewportDrawer *vd = _cur_vd;
|
|
|
ChildScreenSpriteToDraw *cs;
|
|
|
|
|
|
assert( (image & 0x3fff) < NUM_SPRITES);
|
|
|
assert((image & 0x3FFF) < NUM_SPRITES);
|
|
|
|
|
|
cs = (ChildScreenSpriteToDraw*) vd->spritelist_mem;
|
|
|
if ((byte*)cs >= vd->eof_spritelist_mem) {
|
|
|
if (vd->spritelist_mem >= vd->eof_spritelist_mem) {
|
|
|
DEBUG(misc, 0) ("Out of sprite mem");
|
|
|
return;
|
|
|
}
|
|
|
cs = (ChildScreenSpriteToDraw*)vd->spritelist_mem;
|
|
|
|
|
|
if (vd->last_child == NULL)
|
|
|
return;
|
|
|
if (vd->last_child == NULL) return;
|
|
|
|
|
|
vd->spritelist_mem += sizeof(ChildScreenSpriteToDraw);
|
|
|
|
|
|
*vd->last_child = cs;
|
|
|
vd->last_child = &cs->next;
|
|
|
|
|
|
cs->image = image;
|
|
|
cs->x = x;
|
|
|
cs->y = y;
|
|
|
cs->next = NULL;
|
|
|
}
|
|
|
|
|
|
/* Returns a StringSpriteToDraw */
|
|
|
void *AddStringToDraw(int x, int y, StringID string, uint32 params_1, uint32 params_2, uint32 params_3)
|
|
|
{
|
|
|
ViewportDrawer *vd = _cur_vd;
|
|
|
StringSpriteToDraw *ss;
|
|
|
|
|
|
ss = (StringSpriteToDraw*)vd->spritelist_mem;
|
|
|
if ((byte*)ss >= vd->eof_spritelist_mem) {
|
|
|
if (vd->spritelist_mem >= vd->eof_spritelist_mem) {
|
|
|
DEBUG(misc, 0) ("Out of sprite mem");
|
|
|
return NULL;
|
|
|
}
|
|
|
ss = (StringSpriteToDraw*)vd->spritelist_mem;
|
|
|
|
|
|
vd->spritelist_mem += sizeof(StringSpriteToDraw);
|
|
|
|
|
|
ss->string = string;
|
|
|
ss->next = NULL;
|
|
|
ss->x = x;
|
|
|
ss->y = y;
|
|
|
ss->params[0] = params_1;
|
|
|
ss->params[1] = params_2;
|
|
|
ss->params[2] = params_3;
|
|
|
ss->width = 0;
|
|
|
|
|
|
*vd->last_string = ss;
|
|
|
vd->last_string = &ss->next;
|
|
|
|
|
|
return ss;
|
|
|
}
|
|
|
|
|
|
/* Debugging code */
|
|
|
|
|
|
#ifdef DEBUG_TILE_PUSH
|
|
|
static int _num_push;
|
|
|
static uint _num_push;
|
|
|
static TileIndex _pushed_tile[200];
|
|
|
static int _pushed_track[200];
|
|
|
|
|
|
static TileIndex _stored_tile[200];
|
|
|
static int _stored_track[200];
|
|
|
static int _num_stored;
|
|
|
static uint _num_stored;
|
|
|
|
|
|
void dbg_store_path(void)
|
|
|
{
|
|
|
memcpy(_stored_tile, _pushed_tile, sizeof(_stored_tile));
|
|
|
memcpy(_stored_track, _pushed_track, sizeof(_stored_tile));
|
|
|
_num_stored = _num_push;
|
|
|
MarkWholeScreenDirty();
|
|
|
}
|
|
|
|
|
|
void dbg_push_tile(TileIndex tile, int track)
|
|
|
{
|
|
|
_pushed_tile[_num_push] = tile;
|
|
|
_pushed_track[_num_push++] = track;
|
|
|
dbg_store_path();
|
|
|
}
|
|
|
|
|
|
void dbg_pop_tile(void)
|
|
|
{
|
|
|
assert(_num_push > 0)
|
|
|
_num_push--;
|
|
|
}
|
|
|
|
|
|
static const uint16 _dbg_track_sprite[] = {
|
|
|
0x3F4,
|
|
|
0x3F3,
|
|
|
0x3F5,
|
|
|
0x3F6,
|
|
|
0x3F8,
|
|
|
0x3F7,
|
|
|
};
|
|
|
|
|
|
static int dbg_draw_pushed(const TileInfo *ti)
|
|
|
{
|
|
|
int i;
|
|
|
if (ti->tile==0)
|
|
|
return 0;
|
|
|
for(i=0; i!=_num_stored; i++)
|
|
|
uint i;
|
|
|
|
|
|
if (ti->tile == 0) return 0;
|
|
|
for (i = 0; i != _num_stored; i++) {
|
|
|
if (_stored_tile[i] == ti->tile) {
|
|
|
DrawGroundSpriteAt(_dbg_track_sprite[_stored_track[i]&7], ti->x, ti->y, ti->z);
|
|
|
}
|
|
|
}
|
|
|
return -1;
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
static void DrawSelectionSprite(uint32 image, const TileInfo *ti)
|
|
|
{
|
|
|
if (_added_tile_sprite && !(_thd.drawstyle & HT_LINE)) { // draw on real ground
|
|
|
DrawGroundSpriteAt(image, ti->x, ti->y, ti->z + 7);
|
|
|
} else { // draw on top of foundation
|
|
|
AddSortableSpriteToDraw(image, ti->x, ti->y, 0x10, 0x10, 1, ti->z + 7);
|
|
|
}
|
|
@@ -650,68 +643,69 @@ static void DrawTileSelection(const Tile
|
|
|
|
|
|
#ifdef DEBUG_TILE_PUSH
|
|
|
dbg_draw_pushed(ti);
|
|
|
#endif
|
|
|
|
|
|
// Draw a red error square?
|
|
|
if (_thd.redsq != 0 && _thd.redsq == ti->tile) {
|
|
|
DrawSelectionSprite(PALETTE_TILE_RED_PULSATING | (SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh]), ti);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// no selection active?
|
|
|
if (_thd.drawstyle == 0)
|
|
|
return;
|
|
|
if (_thd.drawstyle == 0) return;
|
|
|
|
|
|
// Inside the inner area?
|
|
|
if (IS_INSIDE_1D(ti->x, _thd.pos.x, _thd.size.x) && IS_INSIDE_1D(ti->y, _thd.pos.y, _thd.size.y)) {
|
|
|
if (IS_INSIDE_1D(ti->x, _thd.pos.x, _thd.size.x) &&
|
|
|
IS_INSIDE_1D(ti->y, _thd.pos.y, _thd.size.y)) {
|
|
|
if (_thd.drawstyle & HT_RECT) {
|
|
|
image = SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh];
|
|
|
if (_thd.make_square_red) image |= PALETTE_SEL_TILE_RED;
|
|
|
DrawSelectionSprite(image, ti);
|
|
|
} else if (_thd.drawstyle & HT_POINT) {
|
|
|
// Figure out the Z coordinate for the single dot.
|
|
|
byte z = ti->z;
|
|
|
if (ti->tileh & 8) {
|
|
|
z += 8;
|
|
|
if (!(ti->tileh & 2) && (IsSteepTileh(ti->tileh))) {
|
|
|
z += 8;
|
|
|
}
|
|
|
if (!(ti->tileh & 2) && (IsSteepTileh(ti->tileh))) z += 8;
|
|
|
}
|
|
|
DrawGroundSpriteAt(_cur_dpi->zoom != 2 ? SPR_DOT : SPR_DOT_SMALL, ti->x, ti->y, z);
|
|
|
} else if (_thd.drawstyle & HT_RAIL /*&& _thd.place_mode == VHM_RAIL*/) { // autorail highlight piece under cursor
|
|
|
int type = _thd.drawstyle & 0xF;
|
|
|
assert(type<=5);
|
|
|
image = SPR_AUTORAIL_BASE + AutorailTilehSprite[ ti->tileh ][ AutorailType[type][0] ];
|
|
|
} else if (_thd.drawstyle & HT_RAIL /*&& _thd.place_mode == VHM_RAIL*/) {
|
|
|
// autorail highlight piece under cursor
|
|
|
uint type = _thd.drawstyle & 0xF;
|
|
|
assert(type <= 5);
|
|
|
image = SPR_AUTORAIL_BASE + AutorailTilehSprite[ti->tileh][AutorailType[type][0]];
|
|
|
|
|
|
if (_thd.make_square_red) image |= PALETTE_SEL_TILE_RED;
|
|
|
DrawSelectionSprite(image, ti);
|
|
|
|
|
|
} else if (IsPartOfAutoLine(ti->x, ti->y)) { // autorail highlighting long line
|
|
|
int dir = _thd.drawstyle & ~0xF0;
|
|
|
TileIndex start = TileVirtXY(_thd.selstart.x, _thd.selstart.y);
|
|
|
int diffx, diffy;
|
|
|
int side;
|
|
|
|
|
|
diffx = myabs(TileX(start)-TileX(ti->tile));
|
|
|
diffy = myabs(TileY(start)-TileY(ti->tile));
|
|
|
} else if (IsPartOfAutoLine(ti->x, ti->y)) {
|
|
|
// autorail highlighting long line
|
|
|
int dir = _thd.drawstyle & ~0xF0;
|
|
|
uint side;
|
|
|
|
|
|
side = myabs( diffx-diffy );
|
|
|
if(dir<2) side = 0;
|
|
|
if (dir < 2) {
|
|
|
side = 0;
|
|
|
} else {
|
|
|
TileIndex start = TileVirtXY(_thd.selstart.x, _thd.selstart.y);
|
|
|
int diffx = myabs(TileX(start) - TileX(ti->tile));
|
|
|
int diffy = myabs(TileY(start) - TileY(ti->tile));
|
|
|
side = myabs(diffx - diffy);
|
|
|
}
|
|
|
|
|
|
image = SPR_AUTORAIL_BASE + AutorailTilehSprite[ ti->tileh ][ AutorailType[dir][side] ];
|
|
|
image = SPR_AUTORAIL_BASE + AutorailTilehSprite[ti->tileh][AutorailType[dir][side]];
|
|
|
|
|
|
if (_thd.make_square_red) image |= PALETTE_SEL_TILE_RED;
|
|
|
DrawSelectionSprite(image, ti);
|
|
|
}
|
|
|
if (_thd.make_square_red) image |= PALETTE_SEL_TILE_RED;
|
|
|
DrawSelectionSprite(image, ti);
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// Check if it's inside the outer area?
|
|
|
if (_thd.outersize.x &&
|
|
|
_thd.size.x < _thd.size.x + _thd.outersize.x &&
|
|
|
IS_INSIDE_1D(ti->x, _thd.pos.x + _thd.offs.x, _thd.size.x + _thd.outersize.x) &&
|
|
|
IS_INSIDE_1D(ti->y, _thd.pos.y + _thd.offs.y, _thd.size.y + _thd.outersize.y)) {
|
|
|
// Draw a blue rect.
|
|
|
DrawSelectionSprite(PALETTE_SEL_TILE_BLUE | (SPR_SELECT_TILE + _tileh_to_sprite[ti->tileh]), ti);
|
|
|
return;
|
|
|
}
|
|
@@ -1043,63 +1037,65 @@ static void ViewportAddWaypoints(DrawPix
|
|
|
if (sstd != NULL) {
|
|
|
sstd->width = wp->sign.width_2 | 0x8000;
|
|
|
sstd->color = (wp->deleted ? 0xE : 11);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void UpdateViewportSignPos(ViewportSign *sign, int left, int top, StringID str)
|
|
|
{
|
|
|
char buffer[128];
|
|
|
int w;
|
|
|
uint w;
|
|
|
|
|
|
sign->top = top;
|
|
|
|
|
|
GetString(buffer, str);
|
|
|
w = GetStringWidth(buffer) + 3;
|
|
|
sign->width_1 = w;
|
|
|
sign->left = left - (w >> 1);
|
|
|
sign->left = left - w / 2;
|
|
|
|
|
|
// zoomed out version
|
|
|
_stringwidth_base = 0xE0;
|
|
|
w = GetStringWidth(buffer) + 3;
|
|
|
_stringwidth_base = 0;
|
|
|
sign->width_2 = w;
|
|
|
}
|
|
|
|
|
|
|
|
|
static void ViewportDrawTileSprites(TileSpriteToDraw *ts)
|
|
|
{
|
|
|
do {
|
|
|
Point pt = RemapCoords(ts->x, ts->y, ts->z);
|
|
|
DrawSprite(ts->image, pt.x, pt.y);
|
|
|
} while ( (ts = ts->next) != NULL);
|
|
|
ts = ts->next;
|
|
|
} while (ts != NULL);
|
|
|
}
|
|
|
|
|
|
static void ViewportSortParentSprites(ParentSpriteToDraw **psd)
|
|
|
static void ViewportSortParentSprites(ParentSpriteToDraw* psd[])
|
|
|
{
|
|
|
ParentSpriteToDraw *ps, *ps2,*ps3, **psd2, **psd3;
|
|
|
while (*psd != NULL) {
|
|
|
ParentSpriteToDraw* ps = *psd;
|
|
|
|
|
|
while((ps=*psd) != NULL) {
|
|
|
if (!(ps->unk16 & 1)) {
|
|
|
ParentSpriteToDraw** psd2 = psd;
|
|
|
|
|
|
ps->unk16 |= 1;
|
|
|
psd2 = psd;
|
|
|
|
|
|
while ( (ps2=*++psd2) != NULL) {
|
|
|
while (*++psd2 != NULL) {
|
|
|
ParentSpriteToDraw* ps2 = *psd2;
|
|
|
bool mustswap = false;
|
|
|
|
|
|
if (ps2->unk16 & 1)
|
|
|
continue;
|
|
|
if (ps2->unk16 & 1) continue;
|
|
|
|
|
|
// Decide which sort order algorithm to use, based on whether the sprites have some overlapping area.
|
|
|
if (((ps2->tile_x > ps->tile_x && ps2->tile_x < ps->tile_right) ||
|
|
|
(ps2->tile_right > ps->tile_x && ps2->tile_x < ps->tile_right)) && // overlap in X
|
|
|
((ps2->tile_y > ps->tile_y && ps2->tile_y < ps->tile_bottom) ||
|
|
|
(ps2->tile_bottom > ps->tile_y && ps2->tile_y < ps->tile_bottom)) && // overlap in Y
|
|
|
((ps2->tile_z > ps->tile_z && ps2->tile_z < ps->tile_z_bottom) ||
|
|
|
(ps2->tile_z_bottom > ps->tile_z && ps2->tile_z < ps->tile_z_bottom)) ) { // overlap in Z
|
|
|
// Sprites overlap.
|
|
|
// Use X+Y+Z as the sorting order, so sprites nearer the bottom of the screen,
|
|
|
// and with higher Z elevation, draw in front.
|
|
|
// Here X,Y,Z are the coordinates of the "center of mass" of the sprite,
|
|
@@ -1109,116 +1105,129 @@ static void ViewportSortParentSprites(Pa
|
|
|
ps2->tile_x + ps2->tile_right + ps2->tile_y + ps2->tile_bottom + ps2->tile_z + ps2->tile_z_bottom;
|
|
|
} else {
|
|
|
// No overlap; use the original TTD sort algorithm.
|
|
|
mustswap = (ps->tile_right >= ps2->tile_x &&
|
|
|
ps->tile_bottom >= ps2->tile_y &&
|
|
|
ps->tile_z_bottom >= ps2->tile_z &&
|
|
|
(ps->tile_x >= ps2->tile_right ||
|
|
|
ps->tile_y >= ps2->tile_bottom ||
|
|
|
ps->tile_z >= ps2->tile_z_bottom));
|
|
|
}
|
|
|
if (mustswap) {
|
|
|
// Swap the two sprites ps and ps2 using bubble-sort algorithm.
|
|
|
psd3 = psd;
|
|
|
ParentSpriteToDraw** psd3 = psd;
|
|
|
|
|
|
do {
|
|
|
ps3 = *psd3;
|
|
|
ParentSpriteToDraw* temp = *psd3;
|
|
|
*psd3 = ps2;
|
|
|
ps2 = ps3;
|
|
|
ps2 = temp;
|
|
|
|
|
|
psd3++;
|
|
|
} while (psd3 <= psd2);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
psd++;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static void ViewportDrawParentSprites(ParentSpriteToDraw **psd)
|
|
|
static void ViewportDrawParentSprites(ParentSpriteToDraw *psd[])
|
|
|
{
|
|
|
ParentSpriteToDraw *ps;
|
|
|
ChildScreenSpriteToDraw *cs;
|
|
|
for (; *psd != NULL; psd++) {
|
|
|
const ParentSpriteToDraw* ps = *psd;
|
|
|
Point pt = RemapCoords(ps->tile_x, ps->tile_y, ps->tile_z);
|
|
|
const ChildScreenSpriteToDraw* cs;
|
|
|
|
|
|
for (;(ps=*psd) != NULL;psd++) {
|
|
|
Point pt = RemapCoords(ps->tile_x, ps->tile_y, ps->tile_z);
|
|
|
DrawSprite(ps->image, pt.x, pt.y);
|
|
|
|
|
|
cs = ps->child;
|
|
|
while (cs) {
|
|
|
for (cs = ps->child; cs != NULL; cs = cs->next) {
|
|
|
DrawSprite(cs->image, ps->left + cs->x, ps->top + cs->y);
|
|
|
cs = cs->next;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static void ViewportDrawStrings(DrawPixelInfo *dpi, StringSpriteToDraw *ss)
|
|
|
static void ViewportDrawStrings(DrawPixelInfo *dpi, const StringSpriteToDraw *ss)
|
|
|
{
|
|
|
DrawPixelInfo dp;
|
|
|
byte zoom;
|
|
|
|
|
|
_cur_dpi = &dp;
|
|
|
dp = *dpi;
|
|
|
|
|
|
zoom = (byte)dp.zoom;
|
|
|
zoom = dp.zoom;
|
|
|
dp.zoom = 0;
|
|
|
|
|
|
dp.left >>= zoom;
|
|
|
dp.top >>= zoom;
|
|
|
dp.width >>= zoom;
|
|
|
dp.height >>= zoom;
|
|
|
|
|
|
do {
|
|
|
if (ss->width != 0) {
|
|
|
int x, y, w, bottom;
|
|
|
int x = (ss->x >> zoom) - 1;
|
|
|
int y = (ss->y >> zoom) - 1;
|
|
|
int bottom = y + 11;
|
|
|
int w = ss->width;
|
|
|
|
|
|
x = (ss->x >> zoom) - 1;
|
|
|
y = (ss->y >> zoom) - 1;
|
|
|
|
|
|
bottom = y + 11;
|
|
|
|
|
|
w = ss->width;
|
|
|
if (w & 0x8000) {
|
|
|
w &= ~0x8000;
|
|
|
y--;
|
|
|
bottom -= 6;
|
|
|
w -= 3;
|
|
|
}
|
|
|
|
|
|
/* Draw the rectangle if 'tranparent station signs' is off, or if we are drawing a general text sign (STR_2806) */
|
|
|
if(!(_display_opt & DO_TRANS_SIGNS) || ss->string == STR_2806)
|
|
|
DrawFrameRect(x,y, x+w, bottom, ss->color, (_display_opt & DO_TRANS_BUILDINGS) ? FR_TRANSPARENT | FR_NOBORDER : 0);
|
|
|
/* Draw the rectangle if 'tranparent station signs' is off,
|
|
|
* or if we are drawing a general text sign (STR_2806) */
|
|
|
if (!(_display_opt & DO_TRANS_SIGNS) || ss->string == STR_2806)
|
|
|
DrawFrameRect(
|
|
|
x, y, x + w, bottom, ss->color,
|
|
|
(_display_opt & DO_TRANS_BUILDINGS) ? FR_TRANSPARENT | FR_NOBORDER : 0
|
|
|
);
|
|
|
}
|
|
|
|
|
|
SetDParam(0, ss->params[0]);
|
|
|
SetDParam(1, ss->params[1]);
|
|
|
SetDParam(2, ss->params[2]);
|
|
|
/* if we didnt draw a rectangle, or if transparant building is on, draw the text in the color the rectangle would have */
|
|
|
if (((_display_opt & DO_TRANS_BUILDINGS) || (_display_opt & DO_TRANS_SIGNS && ss->string != STR_2806)) && ss->width != 0) {
|
|
|
/* Real colors need the IS_PALETTE_COLOR flag, otherwise colors from _string_colormap are assumed. */
|
|
|
DrawString(ss->x >> zoom, (ss->y >> zoom) - (ss->width&0x8000?2:0), ss->string,
|
|
|
(_color_list[ss->color].window_color_bgb | IS_PALETTE_COLOR));
|
|
|
/* if we didn't draw a rectangle, or if transparant building is on,
|
|
|
* draw the text in the color the rectangle would have */
|
|
|
if ((
|
|
|
(_display_opt & DO_TRANS_BUILDINGS) ||
|
|
|
(_display_opt & DO_TRANS_SIGNS && ss->string != STR_2806)
|
|
|
) && ss->width != 0) {
|
|
|
/* Real colors need the IS_PALETTE_COLOR flag
|
|
|
* otherwise colors from _string_colormap are assumed. */
|
|
|
DrawString(
|
|
|
ss->x >> zoom, (ss->y >> zoom) - (ss->width & 0x8000 ? 2 : 0),
|
|
|
ss->string, (_color_list[ss->color].window_color_bgb | IS_PALETTE_COLOR)
|
|
|
);
|
|
|
} else {
|
|
|
DrawString(ss->x >> zoom, (ss->y >> zoom) - (ss->width&0x8000?2:0), ss->string, 16);
|
|
|
DrawString(
|
|
|
ss->x >> zoom, (ss->y >> zoom) - (ss->width & 0x8000 ? 2 : 0),
|
|
|
ss->string, 16
|
|
|
);
|
|
|
}
|
|
|
} while ( (ss = ss->next) != NULL);
|
|
|
|
|
|
ss = ss->next;
|
|
|
} while (ss != NULL);
|
|
|
|
|
|
_cur_dpi = dpi;
|
|
|
}
|
|
|
|
|
|
void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom)
|
|
|
{
|
|
|
ViewportDrawer vd;
|
|
|
int mask;
|
|
|
int x,y;
|
|
|
int x;
|
|
|
int y;
|
|
|
DrawPixelInfo *old_dpi;
|
|
|
|
|
|
byte mem[VIEWPORT_DRAW_MEM];
|
|
|
ParentSpriteToDraw *parent_list[6144];
|
|
|
|
|
|
_cur_vd = &vd;
|
|
|
|
|
|
old_dpi = _cur_dpi;
|
|
|
_cur_dpi = &vd.dpi;
|
|
|
|
|
|
vd.dpi.zoom = vp->zoom;
|
|
|
mask = (-1) << vp->zoom;
|
|
@@ -1229,58 +1238,56 @@ void ViewportDoDraw(const ViewPort *vp,
|
|
|
vd.dpi.width = (right - left) & mask;
|
|
|
vd.dpi.height = (bottom - top) & mask;
|
|
|
vd.dpi.left = left & mask;
|
|
|
vd.dpi.top = top & mask;
|
|
|
vd.dpi.pitch = old_dpi->pitch;
|
|
|
|
|
|
x = ((vd.dpi.left - (vp->virtual_left&mask)) >> vp->zoom) + vp->left;
|
|
|
y = ((vd.dpi.top - (vp->virtual_top&mask)) >> vp->zoom) + vp->top;
|
|
|
|
|
|
vd.dpi.dst_ptr = old_dpi->dst_ptr + x - old_dpi->left + (y - old_dpi->top) * old_dpi->pitch;
|
|
|
|
|
|
vd.parent_list = parent_list;
|
|
|
vd.eof_parent_list = &parent_list[lengthof(parent_list)];
|
|
|
vd.eof_parent_list = endof(parent_list);
|
|
|
vd.spritelist_mem = mem;
|
|
|
vd.eof_spritelist_mem = &mem[sizeof(mem) - sizeof(LARGEST_SPRITELIST_STRUCT)];
|
|
|
vd.eof_spritelist_mem = endof(mem) - sizeof(LARGEST_SPRITELIST_STRUCT);
|
|
|
vd.last_string = &vd.first_string;
|
|
|
vd.first_string = NULL;
|
|
|
vd.last_tile = &vd.first_tile;
|
|
|
vd.first_tile = NULL;
|
|
|
|
|
|
ViewportAddLandscape();
|
|
|
#if !defined(NEW_ROTATION)
|
|
|
ViewportAddVehicles(&vd.dpi);
|
|
|
DrawTextEffects(&vd.dpi);
|
|
|
|
|
|
ViewportAddTownNames(&vd.dpi);
|
|
|
ViewportAddStationNames(&vd.dpi);
|
|
|
ViewportAddSigns(&vd.dpi);
|
|
|
ViewportAddWaypoints(&vd.dpi);
|
|
|
#endif
|
|
|
|
|
|
// This assert should never happen (because the length of the parent_list
|
|
|
// is checked)
|
|
|
assert(vd.parent_list <= endof(parent_list));
|
|
|
|
|
|
if (vd.first_tile != NULL)
|
|
|
ViewportDrawTileSprites(vd.first_tile);
|
|
|
if (vd.first_tile != NULL) ViewportDrawTileSprites(vd.first_tile);
|
|
|
|
|
|
/* null terminate parent sprite list */
|
|
|
*vd.parent_list = NULL;
|
|
|
|
|
|
ViewportSortParentSprites(parent_list);
|
|
|
ViewportDrawParentSprites(parent_list);
|
|
|
|
|
|
if (vd.first_string != NULL)
|
|
|
ViewportDrawStrings(&vd.dpi, vd.first_string);
|
|
|
if (vd.first_string != NULL) ViewportDrawStrings(&vd.dpi, vd.first_string);
|
|
|
|
|
|
_cur_dpi = old_dpi;
|
|
|
}
|
|
|
|
|
|
// Make sure we don't draw a too big area at a time.
|
|
|
// If we do, the sprite memory will overflow.
|
|
|
static void ViewportDrawChk(ViewPort *vp, int left, int top, int right, int bottom)
|
|
|
{
|
|
|
if (((bottom - top) * (right - left) << vp->zoom) > 180000) {
|
|
|
if ((bottom - top) > (right - left)) {
|
|
|
int t = (top + bottom) >> 1;
|
|
|
ViewportDrawChk(vp, left, top, right, t);
|
|
@@ -1293,171 +1300,161 @@ static void ViewportDrawChk(ViewPort *vp
|
|
|
} else {
|
|
|
ViewportDoDraw(vp,
|
|
|
((left - vp->left) << vp->zoom) + vp->virtual_left,
|
|
|
((top - vp->top) << vp->zoom) + vp->virtual_top,
|
|
|
((right - vp->left) << vp->zoom) + vp->virtual_left,
|
|
|
((bottom - vp->top) << vp->zoom) + vp->virtual_top
|
|
|
);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static inline void ViewportDraw(ViewPort *vp, int left, int top, int right, int bottom)
|
|
|
{
|
|
|
int t;
|
|
|
if (right <= vp->left || bottom <= vp->top) return;
|
|
|
|
|
|
if (right <= vp->left ||
|
|
|
bottom <= vp->top)
|
|
|
return;
|
|
|
|
|
|
if (left >= (t=vp->left + vp->width))
|
|
|
return;
|
|
|
if (left >= vp->left + vp->width) return;
|
|
|
|
|
|
if (left < vp->left) left = vp->left;
|
|
|
if (right > t) right = t;
|
|
|
if (right > vp->left + vp->width) right = vp->left + vp->width;
|
|
|
|
|
|
if (top >= (t = vp->top + vp->height))
|
|
|
return;
|
|
|
if (top >= vp->top + vp->height) return;
|
|
|
|
|
|
if (top < vp->top) top = vp->top;
|
|
|
if (bottom > t) bottom = t;
|
|
|
if (bottom > vp->top + vp->height) bottom = vp->top + vp->height;
|
|
|
|
|
|
ViewportDrawChk(vp, left, top, right, bottom);
|
|
|
}
|
|
|
|
|
|
void DrawWindowViewport(Window *w) {
|
|
|
void DrawWindowViewport(Window *w)
|
|
|
{
|
|
|
DrawPixelInfo *dpi = _cur_dpi;
|
|
|
|
|
|
dpi->left += w->left;
|
|
|
dpi->top += w->top;
|
|
|
|
|
|
ViewportDraw(w->viewport, dpi->left, dpi->top, dpi->left + dpi->width, dpi->top + dpi->height);
|
|
|
|
|
|
dpi->left -= w->left;
|
|
|
dpi->top -= w->top;
|
|
|
|
|
|
}
|
|
|
|
|
|
void UpdateViewportPosition(Window *w)
|
|
|
{
|
|
|
ViewPort *vp = w->viewport;
|
|
|
const ViewPort *vp = w->viewport;
|
|
|
|
|
|
if (WP(w,vp_d).follow_vehicle != INVALID_VEHICLE) {
|
|
|
Vehicle *veh;
|
|
|
Point pt;
|
|
|
if (WP(w, vp_d).follow_vehicle != INVALID_VEHICLE) {
|
|
|
const Vehicle* veh = GetVehicle(WP(w,vp_d).follow_vehicle);
|
|
|
Point pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos);
|
|
|
|
|
|
veh = GetVehicle(WP(w,vp_d).follow_vehicle);
|
|
|
pt = MapXYZToViewport(vp, veh->x_pos, veh->y_pos, veh->z_pos);
|
|
|
SetViewportPosition(w, pt.x, pt.y);
|
|
|
} else {
|
|
|
#if !defined(NEW_ROTATION)
|
|
|
int x;
|
|
|
int y;
|
|
|
int vx;
|
|
|
int vy;
|
|
|
|
|
|
// Center of the viewport is hot spot
|
|
|
x = WP(w,vp_d).scrollpos_x + vp->virtual_width / 2;
|
|
|
y = WP(w,vp_d).scrollpos_y + vp->virtual_height / 2;
|
|
|
// Convert viewport coordinates to map coordinates
|
|
|
// Calculation is scaled by 4 to avoid rounding errors
|
|
|
vx = -x + y * 2;
|
|
|
vy = x + y * 2;
|
|
|
// clamp to size of map
|
|
|
vx = clamp(vx, 0 * 4, MapMaxX() * 16 * 4);
|
|
|
vy = clamp(vy, 0 * 4, MapMaxY() * 16 * 4);
|
|
|
// Convert map coordinates to viewport coordinates
|
|
|
x = (-vx + vy) / 2;
|
|
|
y = ( vx + vy) / 4;
|
|
|
// Set position
|
|
|
WP(w,vp_d).scrollpos_x = x - vp->virtual_width / 2;
|
|
|
WP(w,vp_d).scrollpos_y = y - vp->virtual_height / 2;
|
|
|
WP(w, vp_d).scrollpos_x = x - vp->virtual_width / 2;
|
|
|
WP(w, vp_d).scrollpos_y = y - vp->virtual_height / 2;
|
|
|
#else
|
|
|
int x,y,t;
|
|
|
int err;
|
|
|
|
|
|
x = WP(w,vp_d).scrollpos_x >> 2;
|
|
|
y = WP(w,vp_d).scrollpos_y >> 1;
|
|
|
|
|
|
t = x;
|
|
|
x = x + y;
|
|
|
y = x - y;
|
|
|
err= 0;
|
|
|
|
|
|
if (err != 0) {
|
|
|
/* coordinate remap */
|
|
|
Point pt = RemapCoords(x, y, 0);
|
|
|
t = (-1) << vp->zoom;
|
|
|
WP(w,vp_d).scrollpos_x = pt.x & t;
|
|
|
WP(w,vp_d).scrollpos_y = pt.y & t;
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
SetViewportPosition(w, WP(w,vp_d).scrollpos_x, WP(w,vp_d).scrollpos_y);
|
|
|
SetViewportPosition(w, WP(w, vp_d).scrollpos_x, WP(w, vp_d).scrollpos_y);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static void MarkViewportDirty(ViewPort *vp, int left, int top, int right, int bottom)
|
|
|
static void MarkViewportDirty(const ViewPort *vp, int left, int top, int right, int bottom)
|
|
|
{
|
|
|
if ( (right -= vp->virtual_left) <= 0)
|
|
|
return;
|
|
|
right -= vp->virtual_left;
|
|
|
if (right <= 0) return;
|
|
|
|
|
|
if ( (bottom -= vp->virtual_top) <= 0)
|
|
|
return;
|
|
|
bottom -= vp->virtual_top;
|
|
|
if (bottom <= 0) return;
|
|
|
|
|
|
if ( (left -= vp->virtual_left) < 0)
|
|
|
left = 0;
|
|
|
left = max(0, left - vp->virtual_left);
|
|
|
|
|
|
if ((uint)left >= (uint)vp->virtual_width)
|
|
|
return;
|
|
|
if (left >= vp->virtual_width) return;
|
|
|
|
|
|
if ( (top -= vp->virtual_top) < 0)
|
|
|
top = 0;
|
|
|
top = max(0, top - vp->virtual_top);
|
|
|
|
|
|
if ((uint)top >= (uint)vp->virtual_height)
|
|
|
return;
|
|
|
if (top >= vp->virtual_height) return;
|
|
|
|
|
|
SetDirtyBlocks(
|
|
|
(left >> vp->zoom) + vp->left,
|
|
|
(top >> vp->zoom) + vp->top,
|
|
|
(right >> vp->zoom) + vp->left,
|
|
|
(bottom >> vp->zoom) + vp->top
|
|
|
);
|
|
|
}
|
|
|
|
|
|
void MarkAllViewportsDirty(int left, int top, int right, int bottom)
|
|
|
{
|
|
|
ViewPort *vp = _viewports;
|
|
|
const ViewPort *vp = _viewports;
|
|
|
uint32 act = _active_viewports;
|
|
|
do {
|
|
|
if (act & 1) {
|
|
|
assert(vp->width != 0);
|
|
|
MarkViewportDirty(vp, left, top, right, bottom);
|
|
|
}
|
|
|
} while (vp++,act>>=1);
|
|
|
}
|
|
|
|
|
|
void MarkTileDirtyByTile(TileIndex tile) {
|
|
|
void MarkTileDirtyByTile(TileIndex tile)
|
|
|
{
|
|
|
Point pt = RemapCoords(TileX(tile) * 16, TileY(tile) * 16, GetTileZ(tile));
|
|
|
MarkAllViewportsDirty(
|
|
|
pt.x - 31,
|
|
|
pt.y - 122,
|
|
|
pt.x - 31 + 67,
|
|
|
pt.y - 122 + 154
|
|
|
);
|
|
|
}
|
|
|
|
|
|
void MarkTileDirty(int x, int y)
|
|
|
{
|
|
|
int z = 0;
|
|
|
uint z = 0;
|
|
|
Point pt;
|
|
|
|
|
|
if (IS_INT_INSIDE(x, 0, MapSizeX() * 16) &&
|
|
|
IS_INT_INSIDE(y, 0, MapSizeY() * 16))
|
|
|
z = GetTileZ(TileVirtXY(x, y));
|
|
|
pt = RemapCoords(x, y, z);
|
|
|
|
|
|
MarkAllViewportsDirty(
|
|
|
pt.x - 31,
|
|
|
pt.y - 122,
|
|
|
pt.x - 31 + 67,
|
|
|
pt.y - 122 + 154
|
|
|
);
|
|
|
}
|
|
@@ -1492,30 +1489,29 @@ static void SetSelectionTilesDirty(void)
|
|
|
y = y_bk;
|
|
|
} while ( (x+=16) != x_size);
|
|
|
}
|
|
|
|
|
|
|
|
|
void SetSelectionRed(bool b)
|
|
|
{
|
|
|
_thd.make_square_red = b;
|
|
|
SetSelectionTilesDirty();
|
|
|
}
|
|
|
|
|
|
|
|
|
static bool CheckClickOnTown(ViewPort *vp, int x, int y)
|
|
|
static bool CheckClickOnTown(const ViewPort *vp, int x, int y)
|
|
|
{
|
|
|
Town *t;
|
|
|
const Town *t;
|
|
|
|
|
|
if (!(_display_opt & DO_SHOW_TOWN_NAMES))
|
|
|
return false;
|
|
|
if (!(_display_opt & DO_SHOW_TOWN_NAMES)) return false;
|
|
|
|
|
|
if (vp->zoom < 1) {
|
|
|
x = x - vp->left + vp->virtual_left;
|
|
|
y = y - vp->top + vp->virtual_top;
|
|
|
|
|
|
FOR_ALL_TOWNS(t) {
|
|
|
if (t->xy &&
|
|
|
y >= t->sign.top &&
|
|
|
y < t->sign.top + 12 &&
|
|
|
x >= t->sign.left &&
|
|
|
x < t->sign.left + t->sign.width_1) {
|
|
|
ShowTownViewWindow(t->index);
|
|
@@ -1544,30 +1540,29 @@ static bool CheckClickOnTown(ViewPort *v
|
|
|
y < t->sign.top + 24 &&
|
|
|
x >= t->sign.left &&
|
|
|
x < t->sign.left + t->sign.width_2 * 4) {
|
|
|
ShowTownViewWindow(t->index);
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
static bool CheckClickOnStation(ViewPort *vp, int x, int y)
|
|
|
static bool CheckClickOnStation(const ViewPort *vp, int x, int y)
|
|
|
{
|
|
|
Station *st;
|
|
|
const Station *st;
|
|
|
|
|
|
if (!(_display_opt & DO_SHOW_STATION_NAMES))
|
|
|
return false;
|
|
|
if (!(_display_opt & DO_SHOW_STATION_NAMES)) return false;
|
|
|
|
|
|
if (vp->zoom < 1) {
|
|
|
x = x - vp->left + vp->virtual_left;
|
|
|
y = y - vp->top + vp->virtual_top;
|
|
|
|
|
|
FOR_ALL_STATIONS(st) {
|
|
|
if (st->xy &&
|
|
|
y >= st->sign.top &&
|
|
|
y < st->sign.top + 12 &&
|
|
|
x >= st->sign.left &&
|
|
|
x < st->sign.left + st->sign.width_1) {
|
|
|
ShowStationViewWindow(st->index);
|
|
@@ -1596,30 +1591,29 @@ static bool CheckClickOnStation(ViewPort
|
|
|
y < st->sign.top + 24 &&
|
|
|
x >= st->sign.left &&
|
|
|
x < st->sign.left + st->sign.width_2 * 4) {
|
|
|
ShowStationViewWindow(st->index);
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
static bool CheckClickOnSign(ViewPort *vp, int x, int y)
|
|
|
static bool CheckClickOnSign(const ViewPort *vp, int x, int y)
|
|
|
{
|
|
|
SignStruct *ss;
|
|
|
const SignStruct *ss;
|
|
|
|
|
|
if (!(_display_opt & DO_SHOW_SIGNS))
|
|
|
return false;
|
|
|
if (!(_display_opt & DO_SHOW_SIGNS)) return false;
|
|
|
|
|
|
if (vp->zoom < 1) {
|
|
|
x = x - vp->left + vp->virtual_left;
|
|
|
y = y - vp->top + vp->virtual_top;
|
|
|
|
|
|
FOR_ALL_SIGNS(ss) {
|
|
|
if (ss->str &&
|
|
|
y >= ss->sign.top &&
|
|
|
y < ss->sign.top + 12 &&
|
|
|
x >= ss->sign.left &&
|
|
|
x < ss->sign.left + ss->sign.width_1) {
|
|
|
ShowRenameSignWindow(ss);
|
|
@@ -1648,30 +1642,29 @@ static bool CheckClickOnSign(ViewPort *v
|
|
|
y < ss->sign.top + 24 &&
|
|
|
x >= ss->sign.left &&
|
|
|
x < ss->sign.left + ss->sign.width_2 * 4) {
|
|
|
ShowRenameSignWindow(ss);
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
static bool CheckClickOnWaypoint(ViewPort *vp, int x, int y)
|
|
|
static bool CheckClickOnWaypoint(const ViewPort *vp, int x, int y)
|
|
|
{
|
|
|
Waypoint *wp;
|
|
|
const Waypoint *wp;
|
|
|
|
|
|
if (!(_display_opt & DO_WAYPOINTS))
|
|
|
return false;
|
|
|
if (!(_display_opt & DO_WAYPOINTS)) return false;
|
|
|
|
|
|
if (vp->zoom < 1) {
|
|
|
x = x - vp->left + vp->virtual_left;
|
|
|
y = y - vp->top + vp->virtual_top;
|
|
|
|
|
|
FOR_ALL_WAYPOINTS(wp) {
|
|
|
if (wp->xy &&
|
|
|
y >= wp->sign.top &&
|
|
|
y < wp->sign.top + 12 &&
|
|
|
x >= wp->sign.left &&
|
|
|
x < wp->sign.left + wp->sign.width_1) {
|
|
|
ShowRenameWaypointWindow(wp);
|
|
@@ -1701,158 +1694,133 @@ static bool CheckClickOnWaypoint(ViewPor
|
|
|
x >= wp->sign.left &&
|
|
|
x < wp->sign.left + wp->sign.width_2 * 4) {
|
|
|
ShowRenameWaypointWindow(wp);
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
|
|
|
static void CheckClickOnLandscape(ViewPort *vp, int x, int y)
|
|
|
static void CheckClickOnLandscape(const ViewPort *vp, int x, int y)
|
|
|
{
|
|
|
Point pt = TranslateXYToTileCoord(vp,x,y);
|
|
|
Point pt = TranslateXYToTileCoord(vp, x, y);
|
|
|
|
|
|
if (pt.x != -1) ClickTile(TileVirtXY(pt.x, pt.y));
|
|
|
}
|
|
|
|
|
|
void HandleClickOnTrain(Vehicle *v);
|
|
|
void HandleClickOnRoadVeh(Vehicle *v);
|
|
|
void HandleClickOnAircraft(Vehicle *v);
|
|
|
void HandleClickOnShip(Vehicle *v);
|
|
|
static void HandleClickOnSpecialVeh(Vehicle *v) {}
|
|
|
void HandleClickOnDisasterVeh(Vehicle *v);
|
|
|
typedef void OnVehicleClickProc(Vehicle *v);
|
|
|
static OnVehicleClickProc * const _on_vehicle_click_proc[6] = {
|
|
|
HandleClickOnTrain,
|
|
|
HandleClickOnRoadVeh,
|
|
|
HandleClickOnShip,
|
|
|
HandleClickOnAircraft,
|
|
|
HandleClickOnSpecialVeh,
|
|
|
HandleClickOnDisasterVeh,
|
|
|
};
|
|
|
|
|
|
void HandleViewportClicked(ViewPort *vp, int x, int y)
|
|
|
void HandleViewportClicked(const ViewPort *vp, int x, int y)
|
|
|
{
|
|
|
if (CheckClickOnTown(vp, x, y))
|
|
|
return;
|
|
|
Vehicle* v;
|
|
|
|
|
|
if (CheckClickOnStation(vp, x, y))
|
|
|
return;
|
|
|
|
|
|
if (CheckClickOnSign(vp, x, y))
|
|
|
return;
|
|
|
|
|
|
if (CheckClickOnWaypoint(vp, x, y))
|
|
|
return;
|
|
|
|
|
|
if (CheckClickOnTown(vp, x, y)) return;
|
|
|
if (CheckClickOnStation(vp, x, y)) return;
|
|
|
if (CheckClickOnSign(vp, x, y)) return;
|
|
|
if (CheckClickOnWaypoint(vp, x, y)) return;
|
|
|
CheckClickOnLandscape(vp, x, y);
|
|
|
|
|
|
{
|
|
|
Vehicle *v = CheckClickOnVehicle(vp, x, y);
|
|
|
if (v) _on_vehicle_click_proc[v->type - 0x10](v);
|
|
|
}
|
|
|
v = CheckClickOnVehicle(vp, x, y);
|
|
|
if (v != NULL) _on_vehicle_click_proc[v->type - 0x10](v);
|
|
|
}
|
|
|
|
|
|
Vehicle *CheckMouseOverVehicle(void)
|
|
|
{
|
|
|
Window *w;
|
|
|
ViewPort *vp;
|
|
|
const Window* w;
|
|
|
const ViewPort* vp;
|
|
|
|
|
|
int x = _cursor.pos.x;
|
|
|
int y = _cursor.pos.y;
|
|
|
|
|
|
w = FindWindowFromPt(x, y);
|
|
|
if (w == NULL)
|
|
|
return NULL;
|
|
|
if (w == NULL) return NULL;
|
|
|
|
|
|
vp = IsPtInWindowViewport(w, x, y);
|
|
|
if (vp) {
|
|
|
return CheckClickOnVehicle(vp, x, y);
|
|
|
} else {
|
|
|
return NULL;
|
|
|
}
|
|
|
return (vp != NULL) ? CheckClickOnVehicle(vp, x, y) : NULL;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PlaceObject(void)
|
|
|
{
|
|
|
Point pt;
|
|
|
Window *w;
|
|
|
WindowEvent e;
|
|
|
|
|
|
pt = GetTileBelowCursor();
|
|
|
if (pt.x == -1)
|
|
|
return;
|
|
|
if (pt.x == -1) return;
|
|
|
|
|
|
if (_thd.place_mode == VHM_POINT) {
|
|
|
pt.x += 8;
|
|
|
pt.y += 8;
|
|
|
}
|
|
|
|
|
|
_tile_fract_coords.x = pt.x & 0xF;
|
|
|
_tile_fract_coords.y = pt.y & 0xF;
|
|
|
|
|
|
if ((w = GetCallbackWnd()) != NULL) {
|
|
|
w = GetCallbackWnd();
|
|
|
if (w != NULL) {
|
|
|
WindowEvent e;
|
|
|
|
|
|
e.event = WE_PLACE_OBJ;
|
|
|
e.place.pt = pt;
|
|
|
e.place.tile = TileVirtXY(pt.x, pt.y);
|
|
|
w->wndproc(w, &e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/* scrolls the viewport in a window to a given location */
|
|
|
bool ScrollWindowTo(int x , int y, Window * w)
|
|
|
bool ScrollWindowTo(int x , int y, Window* w)
|
|
|
{
|
|
|
Point pt;
|
|
|
|
|
|
pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(x, y));
|
|
|
WP(w,vp_d).follow_vehicle = -1;
|
|
|
WP(w, vp_d).follow_vehicle = INVALID_VEHICLE;
|
|
|
|
|
|
if (WP(w,vp_d).scrollpos_x == pt.x &&
|
|
|
WP(w,vp_d).scrollpos_y == pt.y)
|
|
|
return false;
|
|
|
if (WP(w, vp_d).scrollpos_x == pt.x && WP(w, vp_d).scrollpos_y == pt.y)
|
|
|
return false;
|
|
|
|
|
|
WP(w,vp_d).scrollpos_x = pt.x;
|
|
|
WP(w,vp_d).scrollpos_y = pt.y;
|
|
|
WP(w, vp_d).scrollpos_x = pt.x;
|
|
|
WP(w, vp_d).scrollpos_y = pt.y;
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/* scrolls the viewport in a window to a given tile */
|
|
|
bool ScrollWindowToTile(TileIndex tile, Window * w)
|
|
|
bool ScrollWindowToTile(TileIndex tile, Window* w)
|
|
|
{
|
|
|
return ScrollWindowTo(TileX(tile) * 16 + 8, TileY(tile) * 16 + 8, w);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ScrollMainWindowTo(int x, int y)
|
|
|
{
|
|
|
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
|
|
|
Point pt;
|
|
|
|
|
|
pt = MapXYZToViewport(w->viewport, x, y, GetSlopeZ(x, y));
|
|
|
WP(w,vp_d).follow_vehicle = -1;
|
|
|
|
|
|
if (WP(w,vp_d).scrollpos_x == pt.x &&
|
|
|
WP(w,vp_d).scrollpos_y == pt.y)
|
|
|
return false;
|
|
|
|
|
|
WP(w,vp_d).scrollpos_x = pt.x;
|
|
|
WP(w,vp_d).scrollpos_y = pt.y;
|
|
|
return true;
|
|
|
return ScrollWindowTo(x, y, FindWindowById(WC_MAIN_WINDOW, 0));
|
|
|
}
|
|
|
|
|
|
|
|
|
bool ScrollMainWindowToTile(TileIndex tile)
|
|
|
{
|
|
|
return ScrollMainWindowTo(TileX(tile) * 16 + 8, TileY(tile) * 16 + 8);
|
|
|
}
|
|
|
|
|
|
void SetRedErrorSquare(TileIndex tile)
|
|
|
{
|
|
|
TileIndex old;
|
|
|
|
|
@@ -1864,91 +1832,89 @@ void SetRedErrorSquare(TileIndex tile)
|
|
|
if (old != 0) MarkTileDirtyByTile(old);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void SetTileSelectSize(int w, int h)
|
|
|
{
|
|
|
_thd.new_size.x = w * 16;
|
|
|
_thd.new_size.y = h * 16;
|
|
|
_thd.new_outersize.x = 0;
|
|
|
_thd.new_outersize.y = 0;
|
|
|
}
|
|
|
|
|
|
void SetTileSelectBigSize(int ox, int oy, int sx, int sy) {
|
|
|
void SetTileSelectBigSize(int ox, int oy, int sx, int sy)
|
|
|
{
|
|
|
_thd.offs.x = ox * 16;
|
|
|
_thd.offs.y = oy * 16;
|
|
|
_thd.new_outersize.x = sx * 16;
|
|
|
_thd.new_outersize.y = sy * 16;
|
|
|
}
|
|
|
|
|
|
/* returns the best autorail highlight type from map coordinates */
|
|
|
static byte GetAutorailHT(int x, int y)
|
|
|
{
|
|
|
byte i;
|
|
|
i = AutorailPiece[x&0xF][y&0xF];
|
|
|
return HT_RAIL | i;
|
|
|
return HT_RAIL | AutorailPiece[x & 0xF][y & 0xF];
|
|
|
}
|
|
|
|
|
|
// called regular to update tile highlighting in all cases
|
|
|
void UpdateTileSelection(void)
|
|
|
{
|
|
|
Point pt;
|
|
|
int x1,y1;
|
|
|
int x1;
|
|
|
int y1;
|
|
|
|
|
|
_thd.new_drawstyle = 0;
|
|
|
|
|
|
if (_thd.place_mode == VHM_SPECIAL) {
|
|
|
x1 = _thd.selend.x;
|
|
|
y1 = _thd.selend.y;
|
|
|
if (x1 != -1) {
|
|
|
int x2 = _thd.selstart.x;
|
|
|
int y2 = _thd.selstart.y;
|
|
|
x1 &= ~0xF;
|
|
|
y1 &= ~0xF;
|
|
|
|
|
|
if (x1 >= x2) intswap(x1,x2);
|
|
|
if (y1 >= y2) intswap(y1,y2);
|
|
|
_thd.new_pos.x = x1;
|
|
|
_thd.new_pos.y = y1;
|
|
|
_thd.new_size.x = x2 - x1 + 16;
|
|
|
_thd.new_size.y = y2 - y1 + 16;
|
|
|
_thd.new_drawstyle = _thd.next_drawstyle;
|
|
|
}
|
|
|
} else if (_thd.place_mode != VHM_NONE) {
|
|
|
pt = GetTileBelowCursor();
|
|
|
Point pt = GetTileBelowCursor();
|
|
|
x1 = pt.x;
|
|
|
y1 = pt.y;
|
|
|
if (x1 != -1) {
|
|
|
switch (_thd.place_mode) {
|
|
|
case VHM_RECT:
|
|
|
_thd.new_drawstyle = HT_RECT;
|
|
|
break;
|
|
|
case VHM_POINT:
|
|
|
_thd.new_drawstyle = HT_POINT;
|
|
|
x1 += 8;
|
|
|
y1 += 8;
|
|
|
break;
|
|
|
case VHM_RAIL:
|
|
|
_thd.new_drawstyle = GetAutorailHT(pt.x, pt.y); // draw one highlighted tile
|
|
|
}
|
|
|
_thd.new_pos.x = x1 & ~0xF;
|
|
|
_thd.new_pos.y = y1 & ~0xF;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// redraw selection
|
|
|
if (_thd.drawstyle != _thd.new_drawstyle ||
|
|
|
_thd.pos.x != _thd.new_pos.x || _thd.pos.y != _thd.new_pos.y ||
|
|
|
_thd.size.x != _thd.new_size.x || _thd.size.y != _thd.new_size.y) {
|
|
|
|
|
|
// clear the old selection?
|
|
|
if (_thd.drawstyle) SetSelectionTilesDirty();
|
|
|
|
|
|
_thd.drawstyle = _thd.new_drawstyle;
|
|
|
_thd.pos = _thd.new_pos;
|
|
|
_thd.size = _thd.new_size;
|
|
|
_thd.outersize = _thd.new_outersize;
|
|
|
_thd.dirty = 0xff;
|
|
|
|
|
|
// draw the new selection?
|
|
|
if (_thd.new_drawstyle) SetSelectionTilesDirty();
|
|
|
}
|
|
@@ -2034,178 +2000,209 @@ static byte Check2x1AutoRail(int mode)
|
|
|
static void CalcRaildirsDrawstyle(TileHighlightData *thd, int x, int y, int method)
|
|
|
{
|
|
|
int d;
|
|
|
byte b=6;
|
|
|
uint w,h;
|
|
|
|
|
|
int dx = thd->selstart.x - (thd->selend.x&~0xF);
|
|
|
int dy = thd->selstart.y - (thd->selend.y&~0xF);
|
|
|
w = myabs(dx) + 16;
|
|
|
h = myabs(dy) + 16;
|
|
|
|
|
|
if (TileVirtXY(thd->selstart.x, thd->selstart.y) == TileVirtXY(x, y)) { // check if we're only within one tile
|
|
|
if(method == VPM_RAILDIRS)
|
|
|
b = GetAutorailHT(x, y);
|
|
|
else // rect for autosignals on one tile
|
|
|
b = HT_RECT;
|
|
|
if (method == VPM_RAILDIRS)
|
|
|
b = GetAutorailHT(x, y);
|
|
|
else // rect for autosignals on one tile
|
|
|
b = HT_RECT;
|
|
|
} else if (h == 16) { // Is this in X direction?
|
|
|
if (dx==16) // 2x1 special handling
|
|
|
if (dx == 16) // 2x1 special handling
|
|
|
b = (Check2x1AutoRail(3)) | HT_LINE;
|
|
|
else if (dx==-16)
|
|
|
else if (dx == -16)
|
|
|
b = (Check2x1AutoRail(2)) | HT_LINE;
|
|
|
else
|
|
|
b = HT_LINE | HT_DIR_X;
|
|
|
y = thd->selstart.y;
|
|
|
} else if (w == 16) { // Or Y direction?
|
|
|
if (dy==16) // 2x1 special handling
|
|
|
if (dy == 16) // 2x1 special handling
|
|
|
b = (Check2x1AutoRail(1)) | HT_LINE;
|
|
|
else if (dy==-16) // 2x1 other direction
|
|
|
else if (dy == -16) // 2x1 other direction
|
|
|
b = (Check2x1AutoRail(0)) | HT_LINE;
|
|
|
else
|
|
|
b = HT_LINE | HT_DIR_Y;
|
|
|
x = thd->selstart.x;
|
|
|
} else if (w > h * 2) { // still count as x dir?
|
|
|
b = HT_LINE | HT_DIR_X;
|
|
|
b = HT_LINE | HT_DIR_X;
|
|
|
y = thd->selstart.y;
|
|
|
} else if (h > w * 2) { // still count as y dir?
|
|
|
b = HT_LINE | HT_DIR_Y;
|
|
|
b = HT_LINE | HT_DIR_Y;
|
|
|
x = thd->selstart.x;
|
|
|
} else { // complicated direction
|
|
|
d = w - h;
|
|
|
thd->selend.x = thd->selend.x&~0xF;
|
|
|
thd->selend.y = thd->selend.y&~0xF;
|
|
|
thd->selend.x = thd->selend.x & ~0xF;
|
|
|
thd->selend.y = thd->selend.y & ~0xF;
|
|
|
|
|
|
// four cases.
|
|
|
if (x > thd->selstart.x) {
|
|
|
if (y > thd->selstart.y) {
|
|
|
// south
|
|
|
if (d ==0) b = (x & 0xF) > (y & 0xF) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR;
|
|
|
else if (d >= 0) { x = thd->selstart.x + h; b = HT_LINE | HT_DIR_VL; } // return px == py || px == py + 16;
|
|
|
else { y = thd->selstart.y + w; b = HT_LINE | HT_DIR_VR; } // return px == py || px == py - 16;
|
|
|
if (d == 0) {
|
|
|
b = (x & 0xF) > (y & 0xF) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR;
|
|
|
} else if (d >= 0) {
|
|
|
x = thd->selstart.x + h;
|
|
|
b = HT_LINE | HT_DIR_VL;
|
|
|
// return px == py || px == py + 16;
|
|
|
} else {
|
|
|
y = thd->selstart.y + w;
|
|
|
b = HT_LINE | HT_DIR_VR;
|
|
|
} // return px == py || px == py - 16;
|
|
|
} else {
|
|
|
// west
|
|
|
if (d ==0) b = (x & 0xF) + (y & 0xF) >= 0x10 ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU;
|
|
|
else if (d >= 0) { x = thd->selstart.x + h; b = HT_LINE | HT_DIR_HL; }
|
|
|
else { y = thd->selstart.y - w; b = HT_LINE | HT_DIR_HU; }
|
|
|
if (d == 0) {
|
|
|
b = (x & 0xF) + (y & 0xF) >= 0x10 ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU;
|
|
|
} else if (d >= 0) {
|
|
|
x = thd->selstart.x + h;
|
|
|
b = HT_LINE | HT_DIR_HL;
|
|
|
} else {
|
|
|
y = thd->selstart.y - w;
|
|
|
b = HT_LINE | HT_DIR_HU;
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
if (y > thd->selstart.y) {
|
|
|
// east
|
|
|
if (d ==0) b = (x & 0xF) + (y & 0xF) >= 0x10 ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU;
|
|
|
else if (d >= 0) { x = thd->selstart.x - h; b = HT_LINE | HT_DIR_HU; } // return px == -py || px == -py - 16;
|
|
|
else { y = thd->selstart.y + w; b = HT_LINE | HT_DIR_HL; } // return px == -py || px == -py + 16;
|
|
|
if (d == 0) {
|
|
|
b = (x & 0xF) + (y & 0xF) >= 0x10 ? HT_LINE | HT_DIR_HL : HT_LINE | HT_DIR_HU;
|
|
|
} else if (d >= 0) {
|
|
|
x = thd->selstart.x - h;
|
|
|
b = HT_LINE | HT_DIR_HU;
|
|
|
// return px == -py || px == -py - 16;
|
|
|
} else {
|
|
|
y = thd->selstart.y + w;
|
|
|
b = HT_LINE | HT_DIR_HL;
|
|
|
} // return px == -py || px == -py + 16;
|
|
|
} else {
|
|
|
// north
|
|
|
if (d ==0) b = (x & 0xF) > (y & 0xF) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR;
|
|
|
else if (d >= 0) { x = thd->selstart.x - h; b = HT_LINE | HT_DIR_VR; } // return px == py || px == py - 16;
|
|
|
else { y = thd->selstart.y - w; b = HT_LINE | HT_DIR_VL; } //return px == py || px == py + 16;
|
|
|
if (d == 0) {
|
|
|
b = (x & 0xF) > (y & 0xF) ? HT_LINE | HT_DIR_VL : HT_LINE | HT_DIR_VR;
|
|
|
} else if (d >= 0) {
|
|
|
x = thd->selstart.x - h;
|
|
|
b = HT_LINE | HT_DIR_VR;
|
|
|
// return px == py || px == py - 16;
|
|
|
} else {
|
|
|
y = thd->selstart.y - w;
|
|
|
b = HT_LINE | HT_DIR_VL;
|
|
|
} //return px == py || px == py + 16;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
thd->selend.x = x;
|
|
|
thd->selend.y = y;
|
|
|
thd->next_drawstyle = b;
|
|
|
}
|
|
|
|
|
|
// while dragging
|
|
|
void VpSelectTilesWithMethod(int x, int y, int method)
|
|
|
{
|
|
|
int sx,sy;
|
|
|
int sx;
|
|
|
int sy;
|
|
|
|
|
|
if (x == -1) {
|
|
|
_thd.selend.x = -1;
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// allow drag in any rail direction
|
|
|
if (method == VPM_RAILDIRS || method == VPM_SIGNALDIRS) {
|
|
|
_thd.selend.x = x;
|
|
|
_thd.selend.y = y;
|
|
|
CalcRaildirsDrawstyle(&_thd, x, y, method);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (_thd.next_drawstyle == HT_POINT) { x += 8; y += 8; }
|
|
|
if (_thd.next_drawstyle == HT_POINT) {
|
|
|
x += 8;
|
|
|
y += 8;
|
|
|
}
|
|
|
|
|
|
sx = _thd.selstart.x;
|
|
|
sy = _thd.selstart.y;
|
|
|
|
|
|
switch(method) {
|
|
|
case VPM_FIX_X:
|
|
|
x = sx;
|
|
|
break;
|
|
|
switch (method) {
|
|
|
case VPM_FIX_X:
|
|
|
x = sx;
|
|
|
break;
|
|
|
|
|
|
case VPM_FIX_Y:
|
|
|
y = sy;
|
|
|
break;
|
|
|
case VPM_FIX_Y:
|
|
|
y = sy;
|
|
|
break;
|
|
|
|
|
|
case VPM_X_OR_Y:
|
|
|
if (myabs(sy - y) < myabs(sx - x)) y = sy; else x = sx;
|
|
|
break;
|
|
|
case VPM_X_OR_Y:
|
|
|
if (myabs(sy - y) < myabs(sx - x)) y = sy; else x = sx;
|
|
|
break;
|
|
|
|
|
|
case VPM_X_AND_Y:
|
|
|
break;
|
|
|
case VPM_X_AND_Y:
|
|
|
break;
|
|
|
|
|
|
// limit the selected area to a 10x10 rect.
|
|
|
case VPM_X_AND_Y_LIMITED: {
|
|
|
int limit = (_thd.sizelimit - 1) * 16;
|
|
|
x = sx + clamp(x - sx, -limit, limit);
|
|
|
y = sy + clamp(y - sy, -limit, limit);
|
|
|
break;
|
|
|
}
|
|
|
// limit the selected area to a 10x10 rect.
|
|
|
case VPM_X_AND_Y_LIMITED: {
|
|
|
int limit = (_thd.sizelimit - 1) * 16;
|
|
|
x = sx + clamp(x - sx, -limit, limit);
|
|
|
y = sy + clamp(y - sy, -limit, limit);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
_thd.selend.x = x;
|
|
|
_thd.selend.y = y;
|
|
|
}
|
|
|
|
|
|
// while dragging
|
|
|
bool VpHandlePlaceSizingDrag(void)
|
|
|
{
|
|
|
Window *w;
|
|
|
WindowEvent e;
|
|
|
|
|
|
if (_special_mouse_mode != WSM_SIZING)
|
|
|
return true;
|
|
|
if (_special_mouse_mode != WSM_SIZING) return true;
|
|
|
|
|
|
e.place.userdata = _thd.userdata;
|
|
|
|
|
|
// stop drag mode if the window has been closed
|
|
|
w = FindWindowById(_thd.window_class,_thd.window_number);
|
|
|
if (w == NULL) {
|
|
|
ResetObjectToPlace();
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// while dragging execute the drag procedure of the corresponding window (mostly VpSelectTilesWithMethod() )
|
|
|
if (_left_button_down) {
|
|
|
e.event = WE_PLACE_DRAG;
|
|
|
e.place.pt = GetTileBelowCursor();
|
|
|
w->wndproc(w, &e);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// mouse button released..
|
|
|
// keep the selected tool, but reset it to the original mode.
|
|
|
_special_mouse_mode = WSM_NONE;
|
|
|
if (_thd.next_drawstyle == HT_RECT)
|
|
|
if (_thd.next_drawstyle == HT_RECT) {
|
|
|
_thd.place_mode = VHM_RECT;
|
|
|
else if ((e.place.userdata & 0xF) == VPM_SIGNALDIRS) // some might call this a hack... -- Dominik
|
|
|
} else if ((e.place.userdata & 0xF) == VPM_SIGNALDIRS) { // some might call this a hack... -- Dominik
|
|
|
_thd.place_mode = VHM_RECT;
|
|
|
else if (_thd.next_drawstyle & HT_LINE)
|
|
|
} else if (_thd.next_drawstyle & HT_LINE) {
|
|
|
_thd.place_mode = VHM_RAIL;
|
|
|
} else if (_thd.next_drawstyle & HT_RAIL) {
|
|
|
_thd.place_mode = VHM_RAIL;
|
|
|
else if (_thd.next_drawstyle & HT_RAIL)
|
|
|
_thd.place_mode = VHM_RAIL;
|
|
|
else
|
|
|
} else {
|
|
|
_thd.place_mode = VHM_POINT;
|
|
|
}
|
|
|
SetTileSelectSize(1, 1);
|
|
|
|
|
|
// and call the mouseup event.
|
|
|
e.event = WE_PLACE_MOUSEUP;
|
|
|
e.place.pt = _thd.selend;
|
|
|
e.place.tile = TileVirtXY(e.place.pt.x, e.place.pt.y);
|
|
|
e.place.starttile = TileVirtXY(_thd.selstart.x, _thd.selstart.y);
|
|
|
w->wndproc(w, &e);
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -2215,26 +2212,25 @@ void SetObjectToPlaceWnd(CursorID icon,
|
|
|
}
|
|
|
|
|
|
#include "table/animcursors.h"
|
|
|
|
|
|
void SetObjectToPlace(CursorID icon, byte mode, WindowClass window_class, WindowNumber window_num)
|
|
|
{
|
|
|
Window *w;
|
|
|
|
|
|
// undo clicking on button
|
|
|
if (_thd.place_mode != 0) {
|
|
|
_thd.place_mode = 0;
|
|
|
w = FindWindowById(_thd.window_class, _thd.window_number);
|
|
|
if (w != NULL)
|
|
|
CallWindowEventNP(w, WE_ABORT_PLACE_OBJ);
|
|
|
if (w != NULL) CallWindowEventNP(w, WE_ABORT_PLACE_OBJ);
|
|
|
}
|
|
|
|
|
|
SetTileSelectSize(1, 1);
|
|
|
|
|
|
_thd.make_square_red = false;
|
|
|
|
|
|
if (mode == VHM_DRAG) { // mode 4 is for dragdropping trains in the depot window
|
|
|
mode = 0;
|
|
|
_special_mouse_mode = WSM_DRAGDROP;
|
|
|
} else {
|
|
|
_special_mouse_mode = WSM_NONE;
|
|
|
}
|