#1 2015-06-24 23:10:28

gaya
Member

Still trying to make a weapon that modifies blocks

I'm trying to replicate the following Cube 2 mod in Tesseract:

https://www.youtube.com/watch?v=dKng8p4YNlM

So far, i dug around octaedit.cpp and weapon.cpp, and made the following modification to the hit() method:

Added this:

selinfo sel;
sel.cx = 0;
sel.cy = 0;
sel.cxs = sel.s[R[0]]*2;
sel.cys = sel.s[C[0]]*2;
sel.o = at.o;
edittrigger(sel, EDIT_DELCUBE)

But nothing happens. Does anyone know i can trigger block changes to whatever wall a weapon hits? EDIT_DELCUBE is just an example. I'll make a struct for different types of weapons, determining which weapon does what. One creates cubes, another deletes, another can push the edges, one can paint textures, etc, etc.

Last edited by gaya (2015-06-24 23:19:25)

Offline

#2 2015-10-13 21:58:38

chasester
Member

Re: Still trying to make a weapon that modifies blocks

void edittrigger(const selinfo &sel, int op, int arg1, int arg2, int arg3, const VSlot *vs)
    {
        if(m_edit) switch(op)
        {
         ...
         }
     }

m_edit litterally stands for mode edit so if your not in edit mode, then non of that code will run (rendering your entire endever useless. My suggestion is just temperary changing m_edit to true then back to false so that it will work :) or just do

void edittrigger(const selinfo &sel, int op, int arg1, int arg2, int arg3, const VSlot *vs, bool force = false)

but the former seems much easier :)

@edit edittrigger just tells the server whats going on, this doesnt actually edit the map on the client end

Last edited by chasester (2015-10-13 22:12:13)

Offline

#3 2015-10-13 22:08:41

gaya
Member

Re: Still trying to make a weapon that modifies blocks

Yes, but how do i create a selinfo to pass into edittrigger? Ideally, i want to convert the hitscan final position (where the shot landed) into a selinfo struct. And then i can use the edittrigger.

Based on that code, i can have each weapon define a different behavior for edit trigger, or a different way to create selinfo. For example: extrude or intrude entire block, or just vertexes. A shovel affects blocks and a hammer affects vertexes.

Offline

#4 2015-10-13 22:14:22

chasester
Member

Re: Still trying to make a weapon that modifies blocks

honestly based on the video that seems like a very bulky way of editing, but ok

As i said above on the further review of the code that is just a message center to call the server, you still need to do the delete on your end, else you will have to do a get map to get the map back from the server because the map on the server is being modified but the local client is not being modified.

void mpdelcube(selinfo &sel, bool local)
{
    if(local) game::edittrigger(sel, EDIT_DELCUBE);
    loopselxyz(discardchildren(c, true); emptyfaces(c));
}

thats the function you need
it will do the triggering as well just do the same thing but go:

mpdelcube(sel, true) // true because you are the local client that is deleting the cube not being told by the server that this cube has been deleted
idb all the commands will use mp## commands

so i suggest setting up your own version of the edittrigger command inside of the octedit.cpp

void shootedit(selinto &sel,int type){
   switch(type)
   {
       ....
    }
}

use an extern inside of iengine.h and call it on the shoot, then just simiply have the switch just call the correct mp## function so all of it works correctly. NICE CLEAN WRAPPER CODE :)

chasester

Last edited by chasester (2015-10-13 22:21:42)

Offline

#5 2015-10-14 12:58:16

gaya
Member

Re: Still trying to make a weapon that modifies blocks

Yes, i understand the cube editing part. The problem is: the selinfo struct is in a different coordinate system than the picking done by the weapon. And there's no easy way to convert between one another. So i can't call that function from the fire weapon functions.

Offline

#6 2015-10-14 21:45:27

chasester
Member

Re: Still trying to make a weapon that modifies blocks

Ok from my understanding of this

struct selinfo
{
    int corner;
    int cx; //cube index of the x direction of the o equivalent
    int cxs;//cube index of the x direction of the s equivalent
    int cy; // cube index of the y direction of the o equivalent
    int cys;// cube index of the y direction of the s equivalent
//these for points map the for points of your cube selection
    ivec o; o is the start location (or the lowest value (xyz) selected (aka the closest point to (0,0,0)
    ivec s; //s is the farthest selected value from o;
    int grid; //grid is gridsize (this is automatically set) 
    int orient; //orientation is the side of the cube selected 0-7;

so from my understanding you need to set:
o to the point where the player hit
s to the point where the player hit

when deleting orient is unnecessary (its only used when pulling or pushing, copying and rotating)

//in octedit.cpp towards the bottom, below all the mp## functions
void shootedit(selinto &ssel,int type, int arg1, int arg2){
    ssel.cx = 0;
    ssel.cy = 0;
    ssel.cxs = sel.s[R[dimension(orient)]]*2;
    ssel.cys = sel.s[C[dimension(orient)]]*2;
    ssel.orient = orient;
   switch(type)
   {
            case EDIT_FLIP:
            case EDIT_COPY:
            case EDIT_PASTE:
            case EDIT_ROTATE:
            case EDIT_MAT:
            case EDIT_FACE:
            case EDIT_TEX:
            case EDIT_REPLACE:
            case EDIT_CALCLIGHT:
            case EDIT_REMIP:
            case EDIT_VSLOT:
            case EDIT_UNDO:
            case EDIT_REDO:
                 break; //not gonna worrie about this yet
            case EDIT_DELCUBE:
            {
                 mpdelcube(ssel, true);
                 break;
            }
    }
}

//in iengine
extern void shootedit(selinto &sel,int type, int arg1=0, int arg2=0);

//in weapon
look at the @edit

that should work as good base code for this, then just simply write the rest of the info for each of the case types :)

chasester



@ edit dont use hit,
HIT ONLY IS CALLED IF IT HITs A PLAYER OR PLAYER LIKE OBJECT (monster, movable, etc)

do it once in the shoot command

//weapons.cpp
shoot( ... ) {
...
 if(d==player1 || d->ai) // do it here if you want the ai to do it as well
        {
            addmsg(N_SHOOT, "rci2i6iv", d, lastmillis-maptime, atk,
                   (int)(from.x*DMF), (int)(from.y*DMF), (int)(from.z*DMF),
                   (int)(to.x*DMF), (int)(to.y*DMF), (int)(to.z*DMF),
                   hits.length(), hits.length()*sizeof(hitmsg)/sizeof(int), hits.getbuf());
// do it here if you want the ai to do it as well
        }
//or for only players do it here
   if(d==player1 && ATK_RAIL_SHOOT == atk){ //if its a rail gun
      selinfo *sel; 
      sel.o = at.o;
      sel.s = at.o;
      sel.grid = 4; //what ever selectsize you want to delete at "_"
      shootedit(sel, EDIT_DELCUBE);
   }
...
}
... 
updateprojectiles(...){
...
   if(exploded){
      selinfo *sel; 
      sel.o = at.o;
      sel.s = at.o;
      sel.grid = 3; //what ever selectsize you want to delete at "_"
      shootedit(sel, EDIT_DELCUBE);
...
   }
...
}

Last edited by chasester (2015-10-14 22:03:44)

Offline

#7 2015-10-15 02:01:24

gaya
Member

Re: Still trying to make a weapon that modifies blocks

By at, you mean atk? And inside updateprojectiles, p.atk?

Offline

#8 2015-10-15 02:27:14

gaya
Member

Re: Still trying to make a weapon that modifies blocks

selinfo needs an ivec

Offline

#9 2015-10-15 03:01:56

MajorLunaC
Member

Re: Still trying to make a weapon that modifies blocks

Side Note

Now that I really think about it, I can't remember too well, but there may have been a minecraft-type map/mod (with build weapons?). It's been so long, I can't remember anything for sure as I was searching through lots of minecraft remakes at the time. Now general searches don't help because there's a "Tesseract" Minecraft mod (perhaps thanks to Interstellar).

Don't put any hope in finding it. It's probably better to do it yourself, to have it work the way you want. Could be compatibility issues too.

Offline

#10 2015-12-23 10:31:16

chasester
Member

Re: Still trying to make a weapon that modifies blocks

@Gaya
sorrie i missed your comments sorrie

Atk is basically the gun id its 0 or 1 in tesseract idb

ivec(const vec &v);
an ivec can convert to a vec and visa versa, an ivec is a integer vector meaning x y z are ints not floats, just so that things line up better with the grid system. (also used when storing buffers).

@mine craft tesseract
Really dont understand the appeal there are a ton of mine craft mods and games that are almost mine craft, Probably a bad market to try to get into.

@My code above
Ive been messing around with the world.cpp file a lil more so i understand the way the selinfo works. It only updates in editmode, you can simply change this so it updates and renders all the time, just for debugging so you can see it. Its in Octedit.cpp ln 320 ish That's the renderer so tracing it back should lead you to the selinfo update.

chasester

Offline

#11 2015-12-23 13:03:06

gaya
Member

Re: Still trying to make a weapon that modifies blocks

Apparently, selinfo is a global that get's used everywhere by client functions.

Offline

#12 2015-12-24 07:15:39

chasester
Member

Re: Still trying to make a weapon that modifies blocks

ya the whole edit command is global, well most the engine is global, selinfo is a class, sel is the member but ya, you could just create your own selinfo to change your data.

Offline

#13 2015-12-28 20:23:52

gaya
Member

Re: Still trying to make a weapon that modifies blocks

But how? That's one of the biggest challenges i've been facing: how i can create my own selinfo based on the raycast hit, caused by a weapon projectile?

selinfo needs: ivec o, s and also int corner, cx, cxs, cy, cys. Variable names certainly are not helping here (in the whole source code, anyway).

Offline

#14 2015-12-28 21:00:49

chasester
Member

Re: Still trying to make a weapon that modifies blocks

its all in rendereditcursor this is where the update happens BUT here is a description of the member variables

struct selinfo
    int cx, cxs, cy, cys; 
//this is the cube distance between o, and s
    ivec o; 
//o is the origin of the selection (where the lil orange box renders)
    ivec s; 
//s is the origin of the farthest point of the selection (farthest side from the orange box
    int grid; 
//grid is the gridsize of the selection
    int orient; 
//orient is what side the selection is on (this works with the global define orient)
    int corner; 
//which of the four corners of the orient side are being selected, this is used for q + scroll calls

Offline

#15 2015-12-29 12:13:41

gaya
Member

Re: Still trying to make a weapon that modifies blocks

Yes, but i can't convert the at struct vectors into something usable by selinfo. At least, i'm not able to get the target vector and translate into an ivec for o and s.

Offline

#16 2015-12-30 07:25:54

chasester
Member

Re: Still trying to make a weapon that modifies blocks

Lol you are not a programer :)

so ivec is all ints meaning it can only hold whole numbers (1,2,3,4etc)
vec is all floats so it can hold all numbers including decimals(1.0f, 2.5f, 4.8583f, etc)

so to convert you can do this a couple of ways

Take the vec and do
selinfo.o(player->o);

They will convert it automatically for you.

You could also go:
selinfo.o = ivec(player->o);

etc,

IF you posted some code so i can see what you are doing I may be of more help.

In Rendereditcurser they do this passing in the vec of where the player is pointed (the intersecting vector).

chasester

Offline

#17 2015-12-30 12:50:07

gaya
Member

Re: Still trying to make a weapon that modifies blocks

Yep, i'm not. I'm an artist, with some modding experience (mostly UnrealScript and QuakeC). Thanks for the help and the patience. :D

Offline

#18 2015-12-31 03:35:09

chasester
Member

Re: Still trying to make a weapon that modifies blocks

Ya you are trying to tackles something that seems to be out side your league. If you need help let me know, but its not as easy as a little scripting its a lot of oo programing to get it to work the way you want :)

chasester

Offline

Board footer