int resolve_borderid(variant id, void *addr)
{
    int result = 0;
    connection *b = NULL;
    if (id.i != 0) {
        b = find_border(id.i);
        if (b == NULL) {
            result = -1;
        }
    }
    *(connection **)addr = b;
    return result;
}
示例#2
0
static int resolve_buddy(variant data, void *addr)
{
    curse *result = NULL;
    bresolve *br = (bresolve *)data.v;
    connection *b;

    assert(br->id > 0);
    b = find_border(br->id);

    if (b && b->from && b->to) {
        attrib *a = a_find(b->from->attribs, &at_cursewall);
        while (a && a->data.v != br->self) {
            curse *c = (curse *)a->data.v;
            wallcurse *wc = (wallcurse *)c->data.v;
            if (wc->wall->id == br->id)
                break;
            a = a->next;
        }
        if (!a || a->type != &at_cursewall) {
            a = a_find(b->to->attribs, &at_cursewall);
            while (a && a->type == &at_cursewall && a->data.v != br->self) {
                curse *c = (curse *)a->data.v;
                wallcurse *wc = (wallcurse *)c->data.v;
                if (wc->wall->id == br->id)
                    break;
                a = a->next;
            }
        }
        if (a && a->type == &at_cursewall) {
            curse *c = (curse *)a->data.v;
            free(br);
            result = c;
        }
    }
    else {
        /* fail, object does not exist (but if you're still loading then
          * you may want to try again later) */
        *(curse **)addr = NULL;
        return -1;
    }
    *(curse **)addr = result;
    return 0;
}
示例#3
0
/* Add a pass through a mountain (at random) */
void add_pass(struct island_data *isle) {
	int x, y, room, loc;
	int sect = PLAINS;

	do {
		x = number(-1, 1);
		y = number(-1, 1);
	} while (x == 0 && y == 0);

	room = find_border(isle, x, y);

	/* invert directions */
	x *= -1;
	y *= -1;

	while (room != -1) {
		if (!terrains[grid[room].type].is_land) {
			return;
		}
		if (grid[room].type == PLAINS) {
			sect = PLAINS;
		}
		if (grid[room].type == DESERT) {
			sect = DESERT;
		}
		if (grid[room].type == MOUNTAIN) {
			change_grid(room, sect);
		}

		if ((loc = shift(room, 0, 1)) != -1 && grid[loc].type == MOUNTAIN) {
			change_grid(loc, sect);
		}
		if ((loc = shift(room, 1, 0)) != -1 && grid[loc].type == MOUNTAIN) {
			change_grid(loc, sect);
		}

		room = shift(room, x, y);
	}
}
示例#4
0
/* Add a river to the island */
void add_river(struct island_data *isle) {
	int x, y, room;
	int hor, ver, to;
	int found = 0;

	clear_pass();

	do {
		x = number(-1, 1);
		y = number(-1, 1);
	} while (x == 0 && y == 0);

	room = find_border(isle, x, y);

	/* invert directions */
	x *= -1;
	y *= -1;

	while (room != -1) {
		if (!terrains[grid[room].type].is_land)
			return;
		
		change_grid(room, RIVER);
		grid[room].pass = 1;
		
		for (hor = number(-1, 0); hor <= 1; ++hor) {
			for (ver = number(-1, 0); ver <= 1; ++ver) {
				if (hor == 0 && ver == 0) {
					// safe to skip self
					continue;
				}
				
				to = shift(room, hor, ver);
				if (to != -1) {
					// if we hit another river, stop AFTER this sect
					if (grid[to].type == RIVER && grid[to].pass == 0) {
						found = 1;
					}
				
					if (terrains[grid[to].type].is_land) {
						change_grid(to, RIVER);
						grid[to].pass = 1;
					}
				}
			}
		}

		if (found) {
			return;
		}

		/* Alter course */
		if (!number(0, 2)) {
			if (x == 0)
				x += number(-1, 1);
			else if (y == 0)
				y += number(-1, 1);
			else if (x > 0 && y > 0) {
				if ((y -= number(0, 1)))
					x -= number(0, 1);
			}
			else if (x < 0 && y < 0) {
				if ((y += number(0, 1)))
					x += number(0, 1);
			}
			else if (x < 0 && y > 0) {
				if ((y -= number(0, 1)))
					x += number(0, 1);
			}
			else if (y < 0 && x > 0) {
				if ((y += number(0, 1)))
					x -= number(0, 1);
			}
			
			// verify bounds to prevent leaps
			x = MAX(-1, MIN(x, 1));
			y = MAX(-1, MIN(y, 1));
		}

		room = shift(room, x, y);
	}
}
示例#5
0
/* Add a mountain range to an island */
void add_mountains(struct island_data *isle) {
	int x, y, room;
	int hor, ver, to;
	int found = 0;
	
	clear_pass();

	do {
		x = number(-1, 1);
		y = number(-1, 1);
	} while (x == 0 && y == 0);

	room = find_border(isle, x, y);

	/* invert directions */
	x *= -1;
	y *= -1;

	while (room != -1) {
		if (!terrains[grid[room].type].is_land)
			return;
		if (grid[room].type == MOUNTAIN && grid[room].pass == 0) {
			return;
		}
		
		if (grid[room].type == PLAINS) {
			change_grid(room, MOUNTAIN);
		}
		grid[room].pass = 1;

		for (hor = -2; hor <= 2; ++hor) {
			for (ver = -2; ver  <= 2; ++ver) {
				// skip the corners to make a "rounded brush"
				if (((hor == ver) || (hor == -1 * ver)) && (hor == -2 || hor == 2)) {
					continue;
				}
				
				to = shift(room, hor, ver);
				if (to != -1 && number(0, 10) && grid[to].type == PLAINS) {
					// if we find a mountain that already exists, we stop AFTER this round
					if (grid[to].type == MOUNTAIN && grid[to].pass == 0) {
						found = 1;
					}
					change_grid(to, MOUNTAIN);
					grid[to].pass = 1;
				}
			}
		}
		
		// break out
		if (found) {
			return;
		}

		/* Alter course */
		if (!number(0, 4)) {
			if (x == 0)
				x += number(-1, 1);
			else if (y == 0)
				y += number(-1, 1);
			else if (x > 0 && y > 0) {
				if ((y -= number(0, 1)))
					x -= number(0, 1);
			}
			else if (x < 0 && y < 0) {
				if ((y += number(0, 1)))
					x += number(0, 1);
			}
			else if (x < 0 && y > 0) {
				if ((y -= number(0, 1)))
					x += number(0, 1);
			}
			else if (y < 0 && x > 0) {
				if ((y += number(0, 1)))
					x -= number(0, 1);
			}
		}

		room = shift(room, x, y);
	}
}