long computer_check_neutral_places(struct Computer2 *comp, struct ComputerCheck * check) { SYNCDBG(8,"Starting"); //return _DK_computer_check_neutral_places(comp, check); struct Comp2_UnkStr1 *rel; rel = &comp->unkarr_A10[game.neutral_player_num]; struct Room *near_room; struct Coord3d *near_pos; int near_dist; near_room = INVALID_ROOM; near_dist = 2147483647; near_pos = &rel->pos_A[0]; int i; for (i=0; i < 64; i++) { struct Coord3d *place; place = &rel->pos_A[i]; if ((place->x.val == 0) || (place->y.val == 0)) { continue; } struct Room *room; room = INVALID_ROOM; if (computer_finds_nearest_room_to_pos(comp, &room, place)) { MapSubtlDelta dx,dy; dx = abs((int)room->central_stl_x - (MapSubtlDelta)place->x.stl.num); dy = abs((int)room->central_stl_y - (MapSubtlDelta)place->y.stl.num); if (near_dist > dx+dy) { near_room = room; near_pos = place; near_dist = dx+dy; } } } if (room_is_invalid(near_room)) { return 4; } struct Coord3d endpos; struct Coord3d startpos; endpos.x.val = near_pos->x.val; endpos.y.val = near_pos->y.val; endpos.z.val = near_pos->z.val; startpos.x.val = subtile_coord_center(stl_slab_center_subtile(near_room->central_stl_x)); startpos.y.val = subtile_coord_center(stl_slab_center_subtile(near_room->central_stl_y)); startpos.z.val = subtile_coord(1,0); if (!create_task_dig_to_neutral(comp, startpos, endpos)) { return 4; } near_pos->x.val = 0; near_pos->y.val = 0; near_pos->z.val = 0; return 1; }
TbBool sibling_line_of_sight_ignoring_door(const struct Coord3d *prevpos, const struct Coord3d *nextpos, const struct Thing *doortng) { // If we don't want to ignore any doors if (thing_is_invalid(doortng)) { // Check for door at central subtile if (subtile_is_door(stl_slab_center_subtile(nextpos->x.stl.num),stl_slab_center_subtile(nextpos->y.stl.num))) { return false; } } // If only one dimensions changed, allow the pass // (in that case the outcome has been decided before this call) if ((nextpos->x.stl.num == prevpos->x.stl.num) || (nextpos->y.stl.num == prevpos->y.stl.num)) { // change is (x,0) or (0,x) return true; } struct Coord3d posmvx; struct Coord3d posmvy; MapSubtlDelta subdelta_x, subdelta_y; subdelta_x = (nextpos->x.stl.num - (MapSubtlDelta)prevpos->x.stl.num); subdelta_y = (nextpos->y.stl.num - (MapSubtlDelta)prevpos->y.stl.num); switch (subdelta_x + 2 * subdelta_y) { case -3: posmvx.x.val = prevpos->x.val - COORD_PER_STL; posmvx.y.val = prevpos->y.val; posmvx.z.val = prevpos->z.val; posmvy.x.val = prevpos->x.val; posmvy.y.val = prevpos->y.val - COORD_PER_STL; posmvy.z.val = prevpos->z.val; if (point_in_map_is_solid_ignoring_door(&posmvx, doortng)) { SYNCDBG(17, "Cannot see through (%d,%d) with delta (%d,%d) X",(int)posmvx.x.stl.num,(int)posmvx.y.stl.num,(int)subdelta_x,(int)subdelta_y); return false; } if (point_in_map_is_solid_ignoring_door(&posmvy, doortng)) { SYNCDBG(17, "Cannot see through (%d,%d) with delta (%d,%d) Y",(int)posmvy.x.stl.num,(int)posmvy.y.stl.num,(int)subdelta_x,(int)subdelta_y); return false; } break; case -1: posmvx.x.val = prevpos->x.val + COORD_PER_STL; posmvx.y.val = prevpos->y.val; posmvx.z.val = prevpos->z.val; posmvy.x.val = prevpos->x.val; posmvy.y.val = prevpos->y.val - COORD_PER_STL; posmvy.z.val = prevpos->z.val; if (point_in_map_is_solid_ignoring_door(&posmvx, doortng)) { SYNCDBG(17, "Cannot see through (%d,%d) with delta (%d,%d) X",(int)posmvx.x.stl.num,(int)posmvx.y.stl.num,(int)subdelta_x,(int)subdelta_y); return false; } if (point_in_map_is_solid_ignoring_door(&posmvy, doortng)) { SYNCDBG(17, "Cannot see through (%d,%d) with delta (%d,%d) Y",(int)posmvy.x.stl.num,(int)posmvy.y.stl.num,(int)subdelta_x,(int)subdelta_y); return false; } break; case 1: posmvx.x.val = prevpos->x.val - COORD_PER_STL; posmvx.y.val = prevpos->y.val; posmvx.z.val = prevpos->z.val; posmvy.x.val = prevpos->x.val; posmvy.y.val = prevpos->y.val + COORD_PER_STL; posmvy.z.val = prevpos->z.val; if (point_in_map_is_solid_ignoring_door(&posmvx, doortng)) { SYNCDBG(17, "Cannot see through (%d,%d) with delta (%d,%d) X",(int)posmvx.x.stl.num,(int)posmvx.y.stl.num,(int)subdelta_x,(int)subdelta_y); return false; } if (point_in_map_is_solid_ignoring_door(&posmvy, doortng)) { SYNCDBG(17, "Cannot see through (%d,%d) with delta (%d,%d) Y",(int)posmvy.x.stl.num,(int)posmvy.y.stl.num,(int)subdelta_x,(int)subdelta_y); return false; } break; case 3: posmvx.x.val = prevpos->x.val + COORD_PER_STL; posmvx.y.val = prevpos->y.val; posmvx.z.val = prevpos->z.val; posmvy.x.val = prevpos->x.val; posmvy.y.val = prevpos->y.val + COORD_PER_STL; posmvy.z.val = prevpos->z.val; if (point_in_map_is_solid_ignoring_door(&posmvx, doortng)) { SYNCDBG(17, "Cannot see through (%d,%d) with delta (%d,%d) X",(int)posmvx.x.stl.num,(int)posmvx.y.stl.num,(int)subdelta_x,(int)subdelta_y); return false; } if (point_in_map_is_solid_ignoring_door(&posmvy, doortng)) { SYNCDBG(17, "Cannot see through (%d,%d) with delta (%d,%d) Y",(int)posmvy.x.stl.num,(int)posmvy.y.stl.num,(int)subdelta_x,(int)subdelta_y); return false; } break; default: ERRORDBG(8,"Invalid use of sibling function, delta (%d,%d)",(int)subdelta_x,(int)subdelta_y); break; } return true; }
TbBool sibling_line_of_sight_3d_including_lava_check_ignoring_own_door(const struct Coord3d *prevpos, const struct Coord3d *nextpos, PlayerNumber plyr_idx) { // Check for door at central subtile if (subtile_is_door(stl_slab_center_subtile(nextpos->x.stl.num), stl_slab_center_subtile(nextpos->y.stl.num))) { return false; } // If only one dimensions changed, allow the pass // (in that case the outcome has been decided before this call) if ((nextpos->x.stl.num == prevpos->x.stl.num) || (nextpos->y.stl.num == prevpos->y.stl.num)) { // change is (x,0) or (0,x) return true; } struct Coord3d posmvy; struct Coord3d posmvx; int subdelta_x, subdelta_y; subdelta_x = (nextpos->x.stl.num - (MapSubtlDelta)prevpos->x.stl.num); subdelta_y = (nextpos->y.stl.num - (MapSubtlDelta)prevpos->y.stl.num); switch (subdelta_x + 2 * subdelta_y) { case -3: // change is (-1,-1) posmvx.x.val = prevpos->x.val - subtile_coord(1,0); posmvx.y.val = prevpos->y.val; posmvx.z.val = prevpos->z.val; posmvy.x.val = prevpos->x.val; posmvy.y.val = prevpos->y.val - subtile_coord(1,0); posmvy.z.val = prevpos->z.val; if (get_point_in_map_solid_flags_ignoring_own_door(&posmvy, plyr_idx) & 0x01) { return false; } if (get_point_in_map_solid_flags_ignoring_own_door(&posmvx, plyr_idx) & 0x01) { return false; } break; case -1: // change is (1,-1) as (-1,0) was eliminated earlier posmvx.x.val = prevpos->x.val + subtile_coord(1,0); posmvx.y.val = prevpos->y.val; posmvx.z.val = prevpos->z.val; posmvy.x.val = prevpos->x.val; posmvy.y.val = prevpos->y.val - subtile_coord(1,0); posmvy.z.val = prevpos->z.val; if (get_point_in_map_solid_flags_ignoring_own_door(&posmvy, plyr_idx) & 0x01) { return false; } if (get_point_in_map_solid_flags_ignoring_own_door(&posmvx, plyr_idx) & 0x01) { return false; } break; case 1: // change is (-1,1) as (1,0) was eliminated earlier posmvx.x.val = prevpos->x.val - subtile_coord(1,0); posmvx.y.val = prevpos->y.val; posmvx.z.val = prevpos->z.val; posmvy.x.val = prevpos->x.val; posmvy.y.val = prevpos->y.val + subtile_coord(1,0); posmvy.z.val = prevpos->z.val; if (get_point_in_map_solid_flags_ignoring_own_door(&posmvy, plyr_idx) & 0x01) { return false; } if (get_point_in_map_solid_flags_ignoring_own_door(&posmvx, plyr_idx) & 0x01) { return false; } break; case 3: // change is (1,1) posmvx.x.val = prevpos->x.val + subtile_coord(1,0); posmvx.y.val = prevpos->y.val; posmvx.z.val = prevpos->z.val; posmvy.x.val = prevpos->x.val; posmvy.y.val = prevpos->y.val + subtile_coord(1,0); posmvy.z.val = prevpos->z.val; if (get_point_in_map_solid_flags_ignoring_own_door(&posmvy, plyr_idx) & 0x01) { return false; } if (get_point_in_map_solid_flags_ignoring_own_door(&posmvx, plyr_idx) & 0x01) { return false; } break; default: ERRORDBG(8,"Invalid use of sibling function, delta (%d,%d)",(int)subdelta_x,(int)subdelta_y); break; } return true; }
long computer_check_neutral_places(struct Computer2 *comp, struct ComputerCheck * check) { if (is_newdig_enabled(comp)) return 4; SYNCDBG(8,"Starting"); struct Dungeon *dungeon; dungeon = comp->dungeon; if (dungeon_invalid(dungeon) || !player_has_heart(dungeon->owner)) { SYNCDBG(7,"Computer players %d dungeon in invalid or has no heart",(int)dungeon->owner); return CTaskRet_Unk4; } struct OpponentRelation *oprel; oprel = &comp->opponent_relations[game.neutral_player_num]; struct Room *near_room; struct Coord3d *near_pos; int near_dist; near_room = INVALID_ROOM; near_dist = LONG_MAX; near_pos = &oprel->pos_A[0]; int i; for (i=0; i < COMPUTER_SPARK_POSITIONS_COUNT; i++) { struct Coord3d *place; place = &oprel->pos_A[i]; if ((place->x.val == 0) || (place->y.val == 0)) { continue; } struct Room *room; room = INVALID_ROOM; if (computer_finds_nearest_room_to_pos(comp, &room, place)) { MapSubtlDelta dx,dy; dx = abs((int)room->central_stl_x - (MapSubtlDelta)place->x.stl.num); dy = abs((int)room->central_stl_y - (MapSubtlDelta)place->y.stl.num); if (near_dist > dx+dy) { near_room = room; near_pos = place; near_dist = dx+dy; } } } if (room_is_invalid(near_room)) { return CTaskRet_Unk4; } struct Coord3d endpos; struct Coord3d startpos; endpos.x.val = near_pos->x.val; endpos.y.val = near_pos->y.val; endpos.z.val = near_pos->z.val; startpos.x.val = subtile_coord_center(stl_slab_center_subtile(near_room->central_stl_x)); startpos.y.val = subtile_coord_center(stl_slab_center_subtile(near_room->central_stl_y)); startpos.z.val = subtile_coord(1,0); if (!create_task_dig_to_neutral(comp, startpos, endpos)) { return CTaskRet_Unk4; } near_pos->x.val = 0; near_pos->y.val = 0; near_pos->z.val = 0; return CTaskRet_Unk1; }