// Add a gateway to the system bool gwNewGateway(SDWORD x1, SDWORD y1, SDWORD x2, SDWORD y2) { GATEWAY *psNew; SDWORD pos, temp; ASSERT_OR_RETURN(false, x1 >= 0 && x1 < gwMapWidth() && y1 >= 0 && y1 < gwMapHeight() && x2 >= 0 && x2 < gwMapWidth() && y2 >= 0 && y2 < gwMapHeight() && (x1 == x2 || y1 == y2), "Invalid gateway coordinates (%d, %d, %d, %d)", x1, y1, x2, y2); psNew = (GATEWAY*)malloc(sizeof(GATEWAY)); // make sure the first coordinate is always the smallest if (x2 < x1) { // y is the same, swap x temp = x2; x2 = x1; x1 = temp; } else if (y2 < y1) { // x is the same, swap y temp = y2; y2 = y1; y1 = temp; } // Initialise the gateway, correct out-of-map gateways psNew->x1 = MAX(3, x1); psNew->y1 = MAX(3, y1); psNew->x2 = MIN(x2, mapWidth - 4); psNew->y2 = MIN(y2, mapHeight - 4); // add the gateway to the list psNew->psNext = psGateways; psGateways = psNew; // set the map flags if (psNew->x1 == psNew->x2) { // vertical gateway for(pos = psNew->y1; pos <= psNew->y2; pos++) { gwSetGatewayFlag(psNew->x1, pos); } } else { // horizontal gateway for(pos = psNew->x1; pos <= psNew->x2; pos++) { gwSetGatewayFlag(pos, psNew->y1); } } return true; }
// Add a gateway to the system bool gwNewGateway(SDWORD x1, SDWORD y1, SDWORD x2, SDWORD y2) { GATEWAY *psNew; SDWORD pos, temp; if ((x1 < 0) || (x1 >= gwMapWidth()) || (y1 < 0) || (y1 >= gwMapHeight()) || (x2 < 0) || (x2 >= gwMapWidth()) || (y2 < 0) || (y2 >= gwMapHeight()) || ((x1 != x2) && (y1 != y2))) { ASSERT( false,"gwNewGateway: invalid coordinates" ); return false; } psNew = (GATEWAY*)malloc(sizeof(GATEWAY)); if (!psNew) { debug( LOG_FATAL, "gwNewGateway: out of memory" ); abort(); return false; } // make sure the first coordinate is always the smallest if (x2 < x1) { // y is the same, swap x temp = x2; x2 = x1; x1 = temp; } else if (y2 < y1) { // x is the same, swap y temp = y2; y2 = y1; y1 = temp; } // Initialise the gateway, correct out-of-map gateways psNew->x1 = MAX(3, x1); psNew->y1 = MAX(3, y1); psNew->x2 = MIN(x2, mapWidth - 4); psNew->y2 = MIN(y2, mapHeight - 4); // add the gateway to the list psNew->psNext = psGateways; psGateways = psNew; // set the map flags if (psNew->x1 == psNew->x2) { // vertical gateway for(pos = psNew->y1; pos <= psNew->y2; pos++) { gwSetGatewayFlag(psNew->x1, pos); } } else { // horizontal gateway for(pos = psNew->x1; pos <= psNew->x2; pos++) { gwSetGatewayFlag(pos, psNew->y1); } } return true; }