old school hax

Started by sparky4, September 16, 2013, 11:19:26 PM

Previous topic - Next topic

sparky4

 :anisan:

your new maps will be textured like in trooper edition

vampirefrog

sparky that's not how you make a patch
plus you seem to have modified more than was necessary
plus you can just make a newmap and select the whole thing and texture it how you want and save it and make an alias and use that instead of /newmap


Index: octa.cpp
===================================================================
--- octa.cpp    (revision 4895)
+++ octa.cpp    (working copy)
@@ -59,7 +59,10 @@
         c->visible = 0;
         c->merged = 0;
         setfaces(*c, face);
-        loopl(6) c->texture[l] = DEFAULT_GEOM;
+        loopl(6)
+        {
+            c->texture[l] = 2+l;
+        }
         c->material = mat;
         c++;
     }
@@ -311,7 +314,8 @@
         texs[numtexs++] = tex;
     }
     loopirev(numtexs) if(!i || texs[i] > DEFAULT_SKY) return texs[i];
-    return DEFAULT_GEOM;
+    //----return DEFAULT_GEOM;
+    return p.texture[orient];
}

void forcemip(cube &c, bool fixtex)
@@ -660,7 +664,6 @@
{
     switch(i)
     {
-        default:
#define GENCUBEVERT(n, x, y, z) \
         case n: \
             v = T(edgeget(cubeedge(c, 0, y, z), x), \
@@ -674,9 +677,9 @@

void genfaceverts(const cube &c, int orient, ivec v[4])
{
+
     switch(orient)
     {
-        default:
#define GENFACEORIENT(o, v0, v1, v2, v3) \
         case o: v0 v1 v2 v3 break;
#define GENFACEVERT(o, n, x,y,z, xv,yv,zv) \
Index: octaedit.cpp
===================================================================
--- octaedit.cpp        (revision 4895)
+++ octaedit.cpp        (working copy)
@@ -59,7 +59,7 @@
     xtraverts += 2*int(xs+ys);
}

-selinfo sel, lastsel, savedsel;
+selinfo sel, lastsel;

int orient = 0;
int gridsize = 8;
@@ -82,16 +82,12 @@
     sel.orient = orient;
);

-int moving = 0;
-ICOMMAND(moving, "b", (int *n),
-{
-    if(*n >= 0)
-    {
-        if(!*n || (moving<=1 && !pointinsel(sel, cur.tovec().add(1)))) moving = 0;
-        else if(!moving) moving = 1;
-    }
-    intret(moving);
-});
+VARF(moving, 0, 0, 1,
+    if(!moving) return;
+    vec v(cur.v); v.add(1);
+    moving = pointinsel(sel, v);
+    if(moving) havesel = false; // tell cursorupdate to create handle
+);

VARF(gridpower, 0, 3, 12,
{
@@ -108,14 +104,11 @@

void forcenextundo() { lastsel.orient = -1; }

-extern void hmapcancel();
-
void cubecancel()
{
     havesel = false;
     moving = dragging = hmapedit = passthroughsel = 0;
     forcenextundo();
-    hmapcancel();
}

void cancelsel()
@@ -200,11 +193,6 @@
COMMAND(reorient, "");
COMMAND(selextend, "");

-ICOMMAND(selmoved, "", (), { if(noedit(true)) return; intret(sel.o != savedsel.o ? 1 : 0); });
-ICOMMAND(selsave, "", (), { if(noedit(true)) return; savedsel = sel; });
-ICOMMAND(selrestore, "", (), { if(noedit(true)) return; sel = savedsel; });
-ICOMMAND(selswap, "", (), { if(noedit(true)) return; swap(sel, savedsel); });
-
///////// selection support /////////////

cube &blockcube(int x, int y, int z, const block3 &b, int rgrid) // looks up a world cube, based on coordinates mapped by the block
@@ -229,8 +217,9 @@

void countselchild(cube *c, const ivec &cor, int size)
{
-    ivec ss = ivec(sel.s).mul(sel.grid);
-    loopoctaboxsize(cor, size, sel.o, ss)
+    ivec ss(sel.s);
+    ss.mul(sel.grid);
+    loopoctabox(cor, size, sel.o, ss)
     {
         ivec o(i, cor.x, cor.y, cor.z, size);
         if(c[i].children) countselchild(c[i].children, o, size/2);
@@ -273,17 +262,23 @@
     sel.s.z = abs(lastcur.z-cur.z)/sel.grid+1;
}

-bool editmoveplane(const vec &o, const vec &ray, int d, float off, vec &handle, vec &dest, bool first)
+void editmoveplane(const vec &o, const vec &ray, int d, float off, vec &handle, vec &dest, bool first)
{
     plane pl(d, off);
     float dist = 0.0f;
-    if(!pl.rayintersect(player->o, ray, dist))
-        return false;

-    dest = vec(ray).mul(dist).add(player->o);
-    if(first) handle = vec(dest).sub(o);
-    dest.sub(handle);
-    return true;
+    if(pl.rayintersect(player->o, ray, dist))
+    {
+        dest = ray;
+        dest.mul(dist);
+        dest.add(player->o);
+        if(first)
+        {
+            handle = dest;
+            handle.sub(o);
+        }
+        dest.sub(handle);
+    }
}

inline bool isheightmap(int orient, int d, bool empty, cube *c);
@@ -306,20 +301,19 @@

     if(moving)
     {
-        static vec dest, handle;
-        if(editmoveplane(sel.o.tovec(), camdir, od, sel.o[D[od]]+odc*sel.grid*sel.s[D[od]], handle, dest, moving==1))
+        ivec e;
+        static vec v, handle;
+        editmoveplane(sel.o.tovec(), camdir, od, sel.o[D[od]]+odc*sel.grid*sel.s[D[od]], handle, v, !havesel);
+        if(!havesel)
         {
-            if(moving==1)
-            {
-                dest.add(handle);
-                handle = ivec(handle).mask(~(sel.grid-1)).tovec();
-                dest.sub(handle);
-                moving = 2;
-            }
-            ivec o = ivec(dest).mask(~(sel.grid-1));
-            sel.o[R[od]] = o[R[od]];
-            sel.o[C[od]] = o[C[od]];
+            v.add(handle);
+            (e = handle).mask(~(sel.grid-1));
+            v.sub(handle = e.tovec());
+            havesel = true;
         }
+        (e = v).mask(~(sel.grid-1));
+        sel.o[R[od]] = e[R[od]];
+        sel.o[C[od]] = e[C[od]];
     }
     else
     if(entmoving)
@@ -339,7 +333,7 @@
                        | (passthroughcube==1 ? RAY_PASS : 0), gridsize, entorient, ent);

         if((havesel || dragging) && !passthroughsel && !hmapedit)     // now try selecting the selection
-            if(rayboxintersect(sel.o.tovec(), vec(sel.s.tovec()).mul(sel.grid), player->o, camdir, sdist, orient))
+            if(rayrectintersect(sel.o.tovec(), vec(sel.s.tovec()).mul(sel.grid), player->o, camdir, sdist, orient))
             {   // and choose the nearest of the two
                 if(sdist < wdist)
                 {
@@ -374,7 +368,7 @@
             if(gridlookup && !dragging && !moving && !havesel && hmapedit!=1) gridsize = lusize;
             int mag = lusize / gridsize;
             normalizelookupcube(int(w.x), int(w.y), int(w.z));
-            if(sdist == 0 || sdist > wdist) rayboxintersect(lu.tovec(), vec(gridsize), player->o, camdir, t=0, orient); // just getting orient
+            if(sdist == 0 || sdist > wdist) rayrectintersect(lu.tovec(), vec(gridsize), player->o, camdir, t=0, orient); // just getting orient
             cur = lu;
             cor = vec(w).mul(2).div(gridsize);
             od = dimension(orient);
@@ -458,7 +452,7 @@
     }

     // selections
-    if(havesel || moving)
+    if(havesel)
     {
         d = dimension(sel.orient);
         glColor3ub(50,50,50);   // grid
@@ -498,9 +492,9 @@

static bool haschanged = false;

-void readychanges(const ivec &bbmin, const ivec &bbmax, cube *c, const ivec &cor, int size)
+void readychanges(block3 &b, cube *c, const ivec &cor, int size)
{
-    loopoctabox(cor, size, bbmin, bbmax)
+    loopoctabox(cor, size, b.o, b.s)
     {
         ivec o(i, cor.x, cor.y, cor.z, size);
         if(c[i].ext)
@@ -523,7 +517,7 @@
                 discardchildren(c[i], true);
                 brightencube(c[i]);
             }
-            else readychanges(bbmin, bbmax, c[i].children, o, size/2);
+            else readychanges(b, c[i].children, o, size/2);
         }
         else brightencube(c[i]);
     }
@@ -550,7 +544,17 @@
void changed(const block3 &sel, bool commit = true)
{
     if(sel.s.iszero()) return;
-    readychanges(ivec(sel.o).sub(1), ivec(sel.s).mul(sel.grid).add(sel.o).add(1), worldroot, ivec(0, 0, 0), worldsize/2);
+    block3 b = sel;
+    loopi(3) b.s[i] *= b.grid;
+    b.grid = 1;
+    loopi(3)                    // the changed blocks are the selected cubes
+    {
+        b.o[i] -= 1;
+        b.s[i] += 2;
+        readychanges(b, worldroot, ivec(0, 0, 0), worldsize/2);
+        b.o[i] += 1;
+        b.s[i] -= 2;
+    }
     haschanged = true;

     if(commit) commitchanges();
@@ -920,58 +924,58 @@
     e = NULL;
}

-struct prefabheader
+struct octabrushheader
{
     char magic[4];
     int version;
};

-struct prefab : editinfo
+struct octabrush : editinfo
{
     char *name;

-    prefab() : name(NULL) {}
-    ~prefab() { DELETEA(name); if(copy) freeblock(copy); }
+    octabrush() : name(NULL) {}
+    ~octabrush() { DELETEA(name); if(copy) freeblock(copy); }
};

-static inline bool htcmp(const char *key, const prefab &b) { return !strcmp(key, b.name); }
+static inline bool htcmp(const char *key, const octabrush &b) { return !strcmp(key, b.name); }

-static hashset<prefab> prefabs;
+static hashset<octabrush> octabrushes;

-void delprefab(char *name)
+void delbrush(char *name)
{
-    if(prefabs.remove(name))
-        conoutf("deleted prefab %s", name);
+    if(octabrushes.remove(name))
+        conoutf("deleted brush %s", name);
}
-COMMAND(delprefab, "s");
+COMMAND(delbrush, "s");

-void saveprefab(char *name)
+void savebrush(char *name)
{
     if(!name[0] || noedit(true) || (nompedit && multiplayer())) return;
-    prefab *b = prefabs.access(name);
+    octabrush *b = octabrushes.access(name);
     if(!b)
     {
-        b = &prefabs[name];
+        b = &octabrushes[name];
         b->name = newstring(name);
     }
     if(b->copy) freeblock(b->copy);
     protectsel(b->copy = blockcopy(block3(sel), sel.grid));
     changed(sel);
-    defformatstring(filename)(strpbrk(name, "/\\") ? "packages/%s.obr" : "packages/prefab/%s.obr", name);
+    defformatstring(filename)(strpbrk(name, "/\\") ? "packages/%s.obr" : "packages/brush/%s.obr", name);
     path(filename);
     stream *f = opengzfile(filename, "wb");
-    if(!f) { conoutf(CON_ERROR, "could not write prefab to %s", filename); return; }
-    prefabheader hdr;
+    if(!f) { conoutf(CON_ERROR, "could not write brush to %s", filename); return; }
+    octabrushheader hdr;
     memcpy(hdr.magic, "OEBR", 4);
     hdr.version = 0;
     lilswap(&hdr.version, 1);
     f->write(&hdr, sizeof(hdr));
     streambuf<uchar> s(f);
-    if(!packblock(*b->copy, s)) { delete f; conoutf(CON_ERROR, "could not pack prefab %s", filename); return; }
+    if(!packblock(*b->copy, s)) { delete f; conoutf(CON_ERROR, "could not pack brush %s", filename); return; }
     delete f;
-    conoutf("wrote prefab file %s", filename);
+    conoutf("wrote brush file %s", filename);
}
-COMMAND(saveprefab, "s");
+COMMAND(savebrush, "s");

void pasteblock(block3 &b, selinfo &sel, bool local)
{
@@ -983,31 +987,31 @@
     sel.orient = o;
}

-void pasteprefab(char *name)
+void pastebrush(char *name)
{
     if(!name[0] || noedit() || (nompedit && multiplayer())) return;
-    prefab *b = prefabs.access(name);
+    octabrush *b = octabrushes.access(name);
     if(!b)
     {
-        defformatstring(filename)(strpbrk(name, "/\\") ? "packages/%s.obr" : "packages/prefab/%s.obr", name);
+        defformatstring(filename)(strpbrk(name, "/\\") ? "packages/%s.obr" : "packages/brush/%s.obr", name);
         path(filename);
         stream *f = opengzfile(filename, "rb");
-        if(!f) { conoutf(CON_ERROR, "could not read prefab %s", filename); return; }
-        prefabheader hdr;
-        if(f->read(&hdr, sizeof(hdr)) != sizeof(prefabheader) || memcmp(hdr.magic, "OEBR", 4)) { delete f; conoutf(CON_ERROR, "prefab %s has malformatted header", filename); return; }
+        if(!f) { conoutf(CON_ERROR, "could not read brush %s", filename); return; }
+        octabrushheader hdr;
+        if(f->read(&hdr, sizeof(hdr)) != sizeof(octabrushheader) || memcmp(hdr.magic, "OEBR", 4)) { delete f; conoutf(CON_ERROR, "brush %s has malformatted header", filename); return; }
         lilswap(&hdr.version, 1);
-        if(hdr.version != 0) { delete f; conoutf(CON_ERROR, "prefab %s uses unsupported version", filename); return; }
+        if(hdr.version != 0) { delete f; conoutf(CON_ERROR, "brush %s uses unsupported version", filename); return; }
         streambuf<uchar> s(f);
         block3 *copy = NULL;
-        if(!unpackblock(copy, s)) { delete f; conoutf(CON_ERROR, "could not unpack prefab %s", filename); return; }
+        if(!unpackblock(copy, s)) { delete f; conoutf(CON_ERROR, "could not unpack brush %s", filename); return; }
         delete f;
-        b = &prefabs[name];
+        b = &octabrushes[name];
         b->name = newstring(name);
         b->copy = copy;
     }
     pasteblock(*b->copy, sel, true);
}
-COMMAND(pasteprefab, "s");
+COMMAND(pastebrush, "s");

void mpcopy(editinfo *&e, selinfo &sel, bool local)
{
@@ -1107,8 +1111,7 @@

COMMAND(clearbrush, "");
COMMAND(brushvert, "iii");
-void hmapcancel() { htextures.setsize(0); }
-COMMAND(hmapcancel, "");
+ICOMMAND(hmapcancel, "", (), htextures.setsize(0); );
ICOMMAND(hmapselect, "", (),
     int t = lookupcube(cur.x, cur.y, cur.z).texture[orient];
     int i = htextures.find(t);
@@ -1118,12 +1121,21 @@
         htextures.remove(i);
);

+inline bool ishtexture(int t)
+{
+    loopv(htextures)
+        if(t == htextures[i])
+            return false;
+    return true;
+}
+
+VARP(bypassheightmapcheck, 0, 0, 1);    // temp
+
inline bool isheightmap(int o, int d, bool empty, cube *c)
{
     return havesel ||
            (empty && isempty(*c)) ||
-           htextures.empty() ||
-           htextures.find(c->texture[o]) >= 0;
+           ishtexture(c->texture[o]);
}

namespace hmap
@@ -1493,7 +1505,7 @@
                 solidfaces(c);
                 cube &o = blockcube(x, y, 1, sel, -sel.grid);
                 loopi(6)
-                    c.texture[i] = o.children ? DEFAULT_GEOM : o.texture[i];
+                    c.texture[i] = o.children ? 2+i : o.texture[i];
             }
             else
                 emptyfaces(c);

Suicizer

You could also just change default_map_settings.cfg

Zoocata