diff --git a/polymer/eduke32/build/src/build.c b/polymer/eduke32/build/src/build.c index bea99872e..b946e7498 100644 --- a/polymer/eduke32/build/src/build.c +++ b/polymer/eduke32/build/src/build.c @@ -2642,6 +2642,99 @@ static int32_t vec2eq(const vec2_t *v1, const vec2_t *v2) return (v1->x==v2->x && v1->y==v2->y); } +// precondition: [numwalls, newnumwalls-1] form a new loop (may be of wrong orientation) +// returns: +// -1, -2: errors +// 0, 1: OK, 1 means it was an extended sector and an inner loop has been added automatically +static int32_t AddLoopToSector(int32_t k) +{ + int32_t extendedSector=0, firstwall, i, j; +#ifdef YAX_ENABLE + int16_t cbunch, fbunch; + int32_t newnumwalls2; + + yax_getbunches(k, &cbunch, &fbunch); + extendedSector = (cbunch>=0 || fbunch>=0); +#endif + j = newnumwalls-numwalls; +#ifdef YAX_ENABLE + newnumwalls2 = newnumwalls + j; + + if (extendedSector) + { + if ((cbunch>=0 && (sector[k].ceilingstat&2)) + || (fbunch>=0 && (sector[k].floorstat&2))) + { + message("Sloped extended sectors cannot be subdivided."); + newnumwalls--; + return -1; + } + + if (newnumwalls + j > MAXWALLS || numsectors+1 > MAXSECTORS) + { + message("Automatically adding inner sector to new extended sector would exceed limits!"); + newnumwalls--; + return -2; + } + } +#endif + if (clockdir(numwalls) == 0) + flipwalls(numwalls,newnumwalls); + + sector[k].wallnum += j; + for (i=k+1; i= firstwall) + wall[i].nextwall += j; + if (wall[i].point2 >= firstwall) + wall[i].point2 += j; + } +#ifdef YAX_ENABLE + yax_tweakwalls(firstwall, j); +#endif + + Bmemmove(&wall[firstwall+j], &wall[firstwall], (newnumwalls-firstwall)*sizeof(walltype)); + // add new loop to beginning of sector + Bmemmove(&wall[firstwall], &wall[newnumwalls], j*sizeof(walltype)); + + for (i=firstwall; i=0 || fbunch>=0); -#endif - j = newnumwalls-numwalls; -#ifdef YAX_ENABLE - newnumwalls2 = newnumwalls + j; - if (extendedSector) - { - if ((cbunch>=0 && (sector[k].ceilingstat&2)) - || (fbunch>=0 && (sector[k].floorstat&2))) - { - message("Sloped extended sectors cannot be subdivided."); - newnumwalls--; - goto end_space_handling; - } - - if (newnumwalls + j > MAXWALLS || numsectors+1 > MAXSECTORS) - { - message("Automatically adding inner sector to new extended sector would exceed limits!"); - newnumwalls--; - goto end_space_handling; - } - } -#endif - if (clockdir(numwalls) == 0) - flipwalls(numwalls,newnumwalls); - - sector[k].wallnum += j; - for (i=k+1; i= firstwall) - wall[i].nextwall += j; - if (wall[i].point2 >= firstwall) - wall[i].point2 += j; - } -#ifdef YAX_ENABLE - yax_tweakwalls(firstwall, j); -#endif - - Bmemmove(&wall[firstwall+j], &wall[firstwall], (newnumwalls-firstwall)*sizeof(walltype)); - Bmemmove(&wall[firstwall], &wall[newnumwalls], j*sizeof(walltype)); - - for (i=firstwall; i 0) printmessage16("Added inner loop to sector %d and made new inner sector", k); else #endif - printmessage16("Added inner loop to sector %d", k); + printmessage16("Added inner loop to sector %d", k); mkonwinvalid(); asksave = 1; }