forked from github/server
crashfix mapper
Lua: get_region_by_id
This commit is contained in:
parent
ae68d8fd79
commit
47989da257
3 changed files with 28 additions and 20 deletions
|
@ -277,11 +277,14 @@ cursor_region(const view * v, const coordinate * c)
|
||||||
coordinate relpos;
|
coordinate relpos;
|
||||||
int cx, cy;
|
int cx, cy;
|
||||||
|
|
||||||
relpos.x = c->x - v->topleft.x;
|
if (c) {
|
||||||
relpos.y = c->y - v->topleft.y;
|
relpos.x = c->x - v->topleft.x;
|
||||||
cy = relpos.y;
|
relpos.y = c->y - v->topleft.y;
|
||||||
cx = relpos.x + cy/2;
|
cy = relpos.y;
|
||||||
return mr_get(v, cx, cy);
|
cx = relpos.x + cy/2;
|
||||||
|
return mr_get(v, cx, cy);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -294,6 +297,8 @@ draw_cursor(WINDOW * win, selection * s, const view * v, const coordinate * c, i
|
||||||
coordinate relpos;
|
coordinate relpos;
|
||||||
int cx, cy;
|
int cx, cy;
|
||||||
|
|
||||||
|
if (!mr) return;
|
||||||
|
|
||||||
relpos.x = c->x - v->topleft.x;
|
relpos.x = c->x - v->topleft.x;
|
||||||
relpos.y = c->y - v->topleft.y;
|
relpos.y = c->y - v->topleft.y;
|
||||||
cy = relpos.y;
|
cy = relpos.y;
|
||||||
|
@ -790,19 +795,21 @@ handlekey(state * st, int c)
|
||||||
case 0x09: /* tab = next selected*/
|
case 0x09: /* tab = next selected*/
|
||||||
if (regions!=NULL) {
|
if (regions!=NULL) {
|
||||||
map_region * mr = cursor_region(&st->display, cursor);
|
map_region * mr = cursor_region(&st->display, cursor);
|
||||||
region * first = mr->r;
|
if (mr) {
|
||||||
region * cur = (first&&first->next)?first->next:regions;
|
region * first = mr->r;
|
||||||
while (cur!=first) {
|
region * cur = (first&&first->next)?first->next:regions;
|
||||||
coordinate coord;
|
while (cur!=first) {
|
||||||
region2coord(cur, &coord);
|
coordinate coord;
|
||||||
if (tagged_region(st->selected, &coord)) {
|
region2coord(cur, &coord);
|
||||||
st->cursor = coord;
|
if (tagged_region(st->selected, &coord)) {
|
||||||
st->wnd_info->update |= 1;
|
st->cursor = coord;
|
||||||
st->wnd_status->update |= 1;
|
st->wnd_info->update |= 1;
|
||||||
break;
|
st->wnd_status->update |= 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cur = cur->next;
|
||||||
|
if (!cur && first) cur = regions;
|
||||||
}
|
}
|
||||||
cur = cur->next;
|
|
||||||
if (!cur && first) cur = regions;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -810,7 +817,7 @@ handlekey(state * st, int c)
|
||||||
case 'a':
|
case 'a':
|
||||||
if (regions!=NULL) {
|
if (regions!=NULL) {
|
||||||
map_region * mr = cursor_region(&st->display, cursor);
|
map_region * mr = cursor_region(&st->display, cursor);
|
||||||
if (mr->r) {
|
if (mr && mr->r) {
|
||||||
region * cur = mr->r;
|
region * cur = mr->r;
|
||||||
if (cur->planep==NULL) {
|
if (cur->planep==NULL) {
|
||||||
cur = r_standard_to_astral(cur);
|
cur = r_standard_to_astral(cur);
|
||||||
|
@ -968,7 +975,7 @@ handlekey(state * st, int c)
|
||||||
} else if (findmode && regions!=NULL) {
|
} else if (findmode && regions!=NULL) {
|
||||||
struct faction * f = NULL;
|
struct faction * f = NULL;
|
||||||
map_region * mr = cursor_region(&st->display, cursor);
|
map_region * mr = cursor_region(&st->display, cursor);
|
||||||
region * first = (mr->r && mr->r->next)?mr->r->next:regions;
|
region * first = (mr && mr->r && mr->r->next)?mr->r->next:regions;
|
||||||
|
|
||||||
if (findmode=='f') {
|
if (findmode=='f') {
|
||||||
sprintf(sbuffer, "find-faction: %s", locate);
|
sprintf(sbuffer, "find-faction: %s", locate);
|
||||||
|
|
|
@ -26,7 +26,7 @@ region *
|
||||||
current_region(void)
|
current_region(void)
|
||||||
{
|
{
|
||||||
map_region * mr = cursor_region(¤t_state->display, ¤t_state->cursor);
|
map_region * mr = cursor_region(¤t_state->display, ¤t_state->cursor);
|
||||||
return mr->r;
|
return mr?mr->r:NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static tag *
|
static tag *
|
||||||
|
|
|
@ -349,6 +349,7 @@ bind_region(lua_State * L)
|
||||||
module(L)[
|
module(L)[
|
||||||
def("regions", &get_regions, return_stl_iterator),
|
def("regions", &get_regions, return_stl_iterator),
|
||||||
def("get_region", &findregion),
|
def("get_region", &findregion),
|
||||||
|
def("get_region_by_id", &findregionbyid),
|
||||||
def("terraform", ®ion_terraform),
|
def("terraform", ®ion_terraform),
|
||||||
def("distance", &distance),
|
def("distance", &distance),
|
||||||
def("remove_region", ®ion_remove),
|
def("remove_region", ®ion_remove),
|
||||||
|
|
Loading…
Reference in a new issue