crashfix mapper

Lua: get_region_by_id
This commit is contained in:
Enno Rehling 2008-05-30 16:08:35 +00:00
parent ae68d8fd79
commit 47989da257
3 changed files with 28 additions and 20 deletions

View file

@ -277,12 +277,15 @@ cursor_region(const view * v, const coordinate * c)
coordinate relpos;
int cx, cy;
if (c) {
relpos.x = c->x - v->topleft.x;
relpos.y = c->y - v->topleft.y;
cy = relpos.y;
cx = relpos.x + cy/2;
return mr_get(v, cx, cy);
}
return NULL;
}
static void
draw_cursor(WINDOW * win, selection * s, const view * v, const coordinate * c, int show)
@ -294,6 +297,8 @@ draw_cursor(WINDOW * win, selection * s, const view * v, const coordinate * c, i
coordinate relpos;
int cx, cy;
if (!mr) return;
relpos.x = c->x - v->topleft.x;
relpos.y = c->y - v->topleft.y;
cy = relpos.y;
@ -790,6 +795,7 @@ handlekey(state * st, int c)
case 0x09: /* tab = next selected*/
if (regions!=NULL) {
map_region * mr = cursor_region(&st->display, cursor);
if (mr) {
region * first = mr->r;
region * cur = (first&&first->next)?first->next:regions;
while (cur!=first) {
@ -805,12 +811,13 @@ handlekey(state * st, int c)
if (!cur && first) cur = regions;
}
}
}
break;
case 'a':
if (regions!=NULL) {
map_region * mr = cursor_region(&st->display, cursor);
if (mr->r) {
if (mr && mr->r) {
region * cur = mr->r;
if (cur->planep==NULL) {
cur = r_standard_to_astral(cur);
@ -968,7 +975,7 @@ handlekey(state * st, int c)
} else if (findmode && regions!=NULL) {
struct faction * f = NULL;
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') {
sprintf(sbuffer, "find-faction: %s", locate);

View file

@ -26,7 +26,7 @@ region *
current_region(void)
{
map_region * mr = cursor_region(&current_state->display, &current_state->cursor);
return mr->r;
return mr?mr->r:NULL;
}
static tag *

View file

@ -349,6 +349,7 @@ bind_region(lua_State * L)
module(L)[
def("regions", &get_regions, return_stl_iterator),
def("get_region", &findregion),
def("get_region_by_id", &findregionbyid),
def("terraform", &region_terraform),
def("distance", &distance),
def("remove_region", &region_remove),