wzinputpatch2.patch:

1.Changed mouse key KEY_STATE enum from 0,1,2,3,4 ...
to 1,2,4,8,16 ...

2.Changed aMouseState[MAX_SCANS] from KEY_STATE to UBYTE

3.Changed the mouse 'key state' in inputProcessEvent to bitwise operation,prevously each 'key state' was exclusive,that's what makes 'double click' event so hard to implement in my opinion.

4.Added a static Uint64 CurrFrameNum to get frame number in InputProcessEvent function,'double click' event is triggered when there are 2 'KEY_DOWN' events within (1 + frameGetAverageRate()*0.25) frames.(thanks to Gerard for the '1+frameGetAverageRate()*0.25' idea)

projfix1.patch:

1.Fixed a bug,which enables you to destroy oil resource/artifact/pickup permanently.

Problems in previous patches by me:

1.Concerning the crash problems with uninitialized asWeaps[0].nStat,the uninitialized behavior is intended because non-weapon droid's asWeaps[DROID_MAXWEAPS] should never be ininitialized.

2.The uninitialzied numWeaps problem is a compability issue,in old template format in droid.c,'numWeaps' was commented-out,I re-enabled it recently when adding multi-turret,so the 2 trucks given to you in skirmish might have a corrupted or uninitialized numWeaps value under certain circumstances when copying 'non-exist' numWeaps values from old template format data.

3.I think the crashes have something to do with a bug in original code:

Droids with 0 weapons/numWeaps were never supposed to be checked in those functions,but the safety check 'if (psDroid->numWeaps > 0)' in various functions was commented-out by someone for unknown reason,instead,they use 'if (psDroid->asWeaps[0].nStat > 0)' hack to check whether a droid has a weapon or not,which can be bypassed by a '0xcd'/'0xdd' marked uninitialized value easily and results in a null pointer crash eventually.I just re-added/uncommented 'if (psDroid->numWeaps > 0)' and it cured the crashes.

4.Projectile target prediction vector z is not used for ground units is because the height difference between 2 ground units is usually negligible,I'll make all target prediction to take vector z into consideration if ground units have problems hitting each other on higher/lower terrain.

5.The connectors(hardpoints) position problem(2nd and 3rd turret 'stack') is due to the size problem of a .pie for a 'body',the body pie in wz are way too small/narrow for multiple weapons,not to mention the turrets are too big in wz,even light body with 1 ripplerocket looked rediculous.There is no cure for this unless someone with artistic skills remake the body pies with greater scale.

- Watermelon

_________________________________________________________________
Don't just search. Find. Check out the new MSN Search! http://search.msn.com/
Index: input.c
===================================================================
--- input.c     (revision 469)
+++ input.c     (working copy)
@@ -25,18 +25,18 @@
/* The possible states for keys */
typedef enum _key_state
{
-       KEY_UP,
-       KEY_PRESSED,
-       KEY_DOWN,
-       KEY_RELEASED,
-       KEY_PRESSRELEASE,       // When a key goes up and down in a frame
-       KEY_DOUBLECLICK,        // Only used by mouse keys
-       KEY_DRAG,                       // Only used by mouse keys
+       KEY_UP = 1,
+       KEY_PRESSED = 2,
+       KEY_DOWN = 4,
+       KEY_RELEASED = 8,
+       KEY_PRESSRELEASE = 16,  // When a key goes up and down in a frame
+       KEY_DOUBLECLICK = 32,   // Only used by mouse keys
+       KEY_DRAG = 64,                  // Only used by mouse keys
} KEY_STATE;


/* The current state of the keyboard */
-static KEY_STATE aKeyState[KEY_MAXSCAN];
+static UBYTE aKeyState[KEY_MAXSCAN];

/* The current location of the mouse */
static SDWORD           mouseXPos, mouseYPos;
@@ -51,7 +51,7 @@
static SDWORD                   dragX, dragY;

/* The current mouse button state */
-static KEY_STATE aMouseState[6];
+static UBYTE aMouseState[6];


/* The size of the input buffer */
@@ -65,6 +65,8 @@
static char     *pCharStartBuffer, *pCharEndBuffer;
static char     currentChar;

+//Watermelon:lastKeydown;
+static Uint64  lastKeydown;

static KEY_CODE sdlKeyToKeyCode(SDLKey key)
{
@@ -101,12 +103,12 @@

        for(i=0; i<KEY_MAXSCAN; i++)
        {
-               aKeyState[i] = KEY_UP;
+               aKeyState[i] += KEY_UP;
        }

        for (i = 0; i < 6; i++)
        {
-               aMouseState[i] = KEY_UP;
+               aMouseState[i] += KEY_UP;
        }

        pStartBuffer = pInputBuffer;
@@ -209,6 +211,10 @@
        UDWORD  code,i, vk;
//      FRACT   divX,divY;
//      UDWORD  scrX,scrY;
+       //Watermelon CurrFrameNum
+       Uint64 CurrFrameNum;
+
+       CurrFrameNum = frameGetFrameNumber();

        switch(event->type)
        {
@@ -267,22 +273,36 @@
                        }

                        code = sdlKeyToKeyCode(event->key.keysym.sym);
-                       if ((aKeyState[code] == KEY_UP) ||
-                               (aKeyState[code] == KEY_RELEASED) ||
-                               (aKeyState[code] == KEY_PRESSRELEASE))
+                       if ((aKeyState[code] & KEY_UP) ||
+                               (aKeyState[code] & KEY_RELEASED) ||
+                               (aKeyState[code] & KEY_PRESSRELEASE))
                        {
-                               aKeyState[code] = KEY_PRESSED;
+                               if (aKeyState[code] & KEY_UP)
+                               {
+                                       aKeyState[code] &= ~KEY_UP;
+                               }
+                               if (aKeyState[code] & KEY_RELEASED)
+                               {
+                                       aKeyState[code] &= ~KEY_RELEASED;
+                               }
+                               if (aKeyState[code] & KEY_RELEASED)
+                               {
+                                       aKeyState[code] &= ~KEY_RELEASED;
+                               }
+                               aKeyState[code] |= KEY_PRESSED;
                        }
                        break;
                case SDL_KEYUP:
                        code = sdlKeyToKeyCode(event->key.keysym.sym);
-                       if (aKeyState[code] == KEY_PRESSED)
+                       if (aKeyState[code] & KEY_PRESSED)
                        {
-                               aKeyState[code] = KEY_PRESSRELEASE;
+                               aKeyState[code] &= ~KEY_PRESSED;
+                               aKeyState[code] |= KEY_PRESSRELEASE;
                        }
-                       else if (aKeyState[code] == KEY_DOWN)
+                       else if (aKeyState[code] & KEY_DOWN)
                        {
-                               aKeyState[code] = KEY_RELEASED;
+                               aKeyState[code] &= ~KEY_DOWN;
+                               aKeyState[code] |= KEY_RELEASED;
                        }
                        break;
                /* Deal with mouse messages */
@@ -304,33 +324,92 @@
                                */

                                /* now see if a drag has started */
-                               if ((aMouseState[dragKey] == KEY_PRESSED ||
-                                        aMouseState[dragKey] == KEY_DOWN) &&
+                               if ((aMouseState[dragKey] & KEY_PRESSED ||
+                                        aMouseState[dragKey] & KEY_DOWN) &&
                                        (ABSDIF(dragX,mouseXPos) > 
DRAG_THRESHOLD ||
                                         ABSDIF(dragY,mouseYPos) > 
DRAG_THRESHOLD))
                                {
                //              DBPRINTF(("dragging\n"));
-                                       aMouseState[dragKey] = KEY_DRAG;
+                                       if (aMouseState[dragKey] & KEY_PRESSED)
+                                       {
+                                               aMouseState[dragKey] &= 
~KEY_PRESSED;
+                                       }
+                                       if (aMouseState[dragKey] & KEY_DOWN)
+                                       {
+                                               aMouseState[dragKey] &= 
~KEY_DOWN;
+                                       }
+                                       aMouseState[dragKey] |= KEY_DRAG;
                                }
                        }
                        break;
                case SDL_MOUSEBUTTONUP:
-                       if (aMouseState[event->button.button] == KEY_PRESSED)
+                       //Watermelon:double click?
+                       if (aMouseState[event->button.button] & KEY_PRESSED)
+                       {
+                               aMouseState[event->button.button] &= 
~KEY_PRESSED;
+                               aMouseState[event->button.button] |= 
KEY_PRESSRELEASE;
+                       }
+                       else if (aMouseState[event->button.button] & KEY_DOWN
+                                       || aMouseState[event->button.button] & 
KEY_DRAG)
+                       {
+                               if (aMouseState[event->button.button] & 
KEY_DOWN)
                                {
-                               aMouseState[event->button.button] = 
KEY_PRESSRELEASE;
+ if (lastKeydown != CurrFrameNum && lastKeydown < (CurrFrameNum - 1 - frameGetAverageRate()*0.25 ))
+                                       {
+                                               if 
(aMouseState[event->button.button] & KEY_DOUBLECLICK)
+                                               {
+                                                       
aMouseState[event->button.button] &= ~KEY_DOUBLECLICK;
+                                               }
+                                       }
+                                       aMouseState[event->button.button] &= 
~KEY_DOWN;
                                }
-                       else if (aMouseState[event->button.button] == KEY_DOWN
-                                       || aMouseState[event->button.button] == 
KEY_DRAG)
+                               if (aMouseState[event->button.button] & 
KEY_DRAG)
                                {
-                               aMouseState[event->button.button] = 
KEY_RELEASED;
+                                       aMouseState[event->button.button] &= 
~KEY_DRAG;
+                               }
+                               aMouseState[event->button.button] |= 
KEY_RELEASED;
                        }
                        break;
                case SDL_MOUSEBUTTONDOWN:
-                       if (aMouseState[event->button.button] == KEY_UP
-                                       || aMouseState[event->button.button] == 
KEY_RELEASED
-                                       || aMouseState[event->button.button] == 
KEY_PRESSRELEASE)
+                       //Watermelon:double click?
+                       if (!lastKeydown)
                        {
-                               aMouseState[event->button.button] = KEY_PRESSED;
+                               lastKeydown = frameGetFrameNumber();
+                       }
+
+                       if (aMouseState[event->button.button] & KEY_DOUBLECLICK)
+                       {
+                               aMouseState[event->button.button] &= 
~KEY_DOUBLECLICK;
+                       }
+
+ if (lastKeydown != CurrFrameNum && lastKeydown < (CurrFrameNum - 1 - frameGetAverageRate()*0.25 ))
+                       {
+                               lastKeydown = frameGetFrameNumber();
+                       }
+
+ if (lastKeydown != CurrFrameNum && lastKeydown >= (CurrFrameNum - 1 - frameGetAverageRate()*0.25 ))
+                       {
+                               aMouseState[event->button.button] |= 
KEY_DOUBLECLICK;
+                               break;
+                       }
+
+                       if (aMouseState[event->button.button] & KEY_UP
+                                       || aMouseState[event->button.button] & 
KEY_RELEASED
+                                       || aMouseState[event->button.button] & 
KEY_PRESSRELEASE)
+                       {
+                               if (aMouseState[event->button.button] & KEY_UP)
+                               {
+                                       aMouseState[event->button.button] &= 
~KEY_UP;
+                               }
+                               if (aMouseState[event->button.button] & 
KEY_RELEASED)
+                               {
+                                       aMouseState[event->button.button] &= 
~KEY_RELEASED;
+                               }
+                               if (aMouseState[event->button.button] & 
KEY_PRESSRELEASE)
+                               {
+                                       aMouseState[event->button.button] &= 
~KEY_PRESSRELEASE;
+                               }
+                               aMouseState[event->button.button] |= 
KEY_PRESSED;
                                if (event->button.button < 4)
                                {
                                        dragKey = 
(MOUSE_KEY_CODE)event->button.button;
@@ -344,19 +423,39 @@
                        /* Lost the window focus, have to take this as a global 
key up */
                        for(i=0; i<KEY_MAXSCAN; i++)
                        {
-                               if ((aKeyState[i] == KEY_PRESSED) ||
-                                       (aKeyState[i] == KEY_DOWN))
+                               if ((aKeyState[i] & KEY_PRESSED) ||
+                                       (aKeyState[i] & KEY_DOWN))
                                {
-                                       aKeyState[i] = KEY_RELEASED;
+                                       if (aKeyState[i] & KEY_PRESSED)
+                                       {
+                                               aKeyState[i] &= ~KEY_PRESSED;
+                                       }
+                                       if (aKeyState[i] & KEY_DOWN)
+                                       {
+                                               aKeyState[i] &= ~KEY_DOWN;
+                                       }
+                                       aKeyState[i] |= KEY_RELEASED;
                                }
                        }
                        for (i = 0; i < 6; i++)
                        {
-                               if ((aMouseState[i] == KEY_PRESSED) ||
-                                       (aMouseState[i] == KEY_DOWN) ||
-                                       (aMouseState[i] == KEY_DRAG))
+                               if ((aMouseState[i] & KEY_PRESSED) ||
+                                       (aMouseState[i] & KEY_DOWN) ||
+                                       (aMouseState[i] & KEY_DRAG))
                                {
-                                       aMouseState[i] = KEY_RELEASED;
+                                       if (aMouseState[i] & KEY_PRESSED)
+                                       {
+                                               aMouseState[i] &= ~KEY_PRESSED;
+                                       }
+                                       if (aMouseState[i] & KEY_DOWN)
+                                       {
+                                               aMouseState[i] &= ~KEY_DOWN;
+                                       }
+                                       if (aMouseState[i] & KEY_DRAG)
+                                       {
+                                               aMouseState[i] &= ~KEY_DRAG;
+                                       }
+                                       aMouseState[i] |= KEY_RELEASED;
                                }
                        }
                        break;
@@ -374,48 +473,74 @@
        /* Do the keyboard */
        for (i=0; i< KEY_MAXSCAN; i++)
        {
-               if (aKeyState[i] == KEY_PRESSED)
+               if (aKeyState[i] & KEY_PRESSED)
                {
-                       aKeyState[i] = KEY_DOWN;
+                       aKeyState[i] &= ~KEY_PRESSED;
+                       aKeyState[i] |= KEY_DOWN;
                }
-               else if ((aKeyState[i] == KEY_RELEASED) ||
-                                (aKeyState[i] == KEY_PRESSRELEASE))
+               else if ((aKeyState[i] & KEY_RELEASED) ||
+                                (aKeyState[i] & KEY_PRESSRELEASE))
                {
-                       aKeyState[i] = KEY_UP;
+                       if (aKeyState[i] & KEY_RELEASED)
+                       {
+                               aKeyState[i] &= ~KEY_RELEASED;
+                       }
+                       if (aKeyState[i] & KEY_PRESSRELEASE)
+                       {
+                               aKeyState[i] &= ~KEY_PRESSRELEASE;
+                       }
+                       aKeyState[i] |= KEY_UP;
                }
        }


        /* Do the mouse */
        for (i = 0; i < 6; i++) {
-               if (aMouseState[i] == KEY_PRESSED)
-                       aMouseState[i] = KEY_DOWN;
-               else if ((aMouseState[i] == KEY_RELEASED)
-                               || (aMouseState[i] == KEY_DOUBLECLICK)
-                               || (aMouseState[i] == KEY_PRESSRELEASE))
-                       aMouseState[i] = KEY_UP;
+               if (aMouseState[i] & KEY_PRESSED)
+               {
+                       aMouseState[i] &= ~KEY_PRESSED;
+                       aMouseState[i] |= KEY_DOWN;
                }
+               else if ((aMouseState[i] & KEY_RELEASED)
+                               || (aMouseState[i] & KEY_DOUBLECLICK)
+                               || (aMouseState[i] & KEY_PRESSRELEASE))
+               {
+                       if (aMouseState[i] & KEY_RELEASED)
+                       {
+                               aMouseState[i] &= ~KEY_RELEASED;
+                       }
+                       if (aMouseState[i] & KEY_DOUBLECLICK)
+                       {
+                               aMouseState[i] &= ~KEY_DOUBLECLICK;
+                       }
+                       if (aMouseState[i] & KEY_PRESSRELEASE)
+                       {
+                               aMouseState[i] &= ~KEY_PRESSRELEASE;
+                       }
+                       aMouseState[i] |= KEY_UP;
+               }
+               }
}

/* This returns true if the key is currently depressed */
BOOL keyDown(KEY_CODE code)
{
ASSERT( (code >= 0) && (keyCodeToSDLKey(code) < KEY_MAXSCAN), "Invalid key code: %d", code );
-       return (aKeyState[code] != KEY_UP);
+       return (!(aKeyState[code] & KEY_UP));
}

/* This returns true if the key went from being up to being down this frame */
BOOL keyPressed(KEY_CODE code)
{
ASSERT( (code >= 0) && (keyCodeToSDLKey(code) < KEY_MAXSCAN), "Invalid key code: %d", code ); - return ((aKeyState[code] == KEY_PRESSED) || (aKeyState[code] == KEY_PRESSRELEASE)); + return ((aKeyState[code] & KEY_PRESSED) || (aKeyState[code] & KEY_PRESSRELEASE));
}

/* This returns true if the key went from being down to being up this frame */
BOOL keyReleased(KEY_CODE code)
{
ASSERT( (code >= 0) && (keyCodeToSDLKey(code) < KEY_MAXSCAN), "Invalid key code: %d", code ); - return ((aKeyState[code] == KEY_RELEASED) || (aKeyState[code] == KEY_PRESSRELEASE)); + return ((aKeyState[code] & KEY_RELEASED) || (aKeyState[code] & KEY_PRESSRELEASE));
}

/* Return the X coordinate of the mouse */
@@ -434,38 +559,38 @@
BOOL mouseDown(MOUSE_KEY_CODE code)
{
        ASSERT( (code >= 0), "Invalid mouse key code: %d", code );
-       return (aMouseState[code] != KEY_UP);
+       return (!(aMouseState[code] & KEY_UP));
}

/* This returns true if the mouse key was double clicked */
BOOL mouseDClicked(MOUSE_KEY_CODE code)
{
        ASSERT( code >= 0, "Invalid mouse key code: %d", code );
-       return (aMouseState[code] == KEY_DOUBLECLICK);
+       return (aMouseState[code] & KEY_DOUBLECLICK);
}

/* This returns true if the mouse key went from being up to being down this frame */
BOOL mousePressed(MOUSE_KEY_CODE code)
{
        ASSERT( (code >= 0), "Invalid mouse key code: %d", code );
-       return ((aMouseState[code] == KEY_PRESSED) ||
-                       (aMouseState[code] == KEY_PRESSRELEASE));
+       return ((aMouseState[code] & KEY_PRESSED) ||
+                       (aMouseState[code] & KEY_PRESSRELEASE));
}

/* This returns true if the mouse key went from being down to being up this frame */
BOOL mouseReleased(MOUSE_KEY_CODE code)
{
        ASSERT( (code >= 0), "Invalid mouse key code: %d", code );
-       return ((aMouseState[code] == KEY_RELEASED) ||
-                       (aMouseState[code] == KEY_DOUBLECLICK) ||
-                       (aMouseState[code] == KEY_PRESSRELEASE));
+       return ((aMouseState[code] & KEY_RELEASED) ||
+                       (aMouseState[code] & KEY_DOUBLECLICK) ||
+                       (aMouseState[code] & KEY_PRESSRELEASE));
}

/* Check for a mouse drag, return the drag start coords if dragging */
BOOL mouseDrag(MOUSE_KEY_CODE code, UDWORD *px, UDWORD *py)
{
        ASSERT( (code >= 0), "Invalid mouse key code: %d", code );
-       if (aMouseState[code] == KEY_DRAG)
+       if (aMouseState[code] & KEY_DRAG)
        {
                *px = dragX;
                *py = dragY;

Index: projectile.c
===================================================================
--- projectile.c        (revision 474)
+++ projectile.c        (working copy)
@@ -856,6 +856,14 @@
                        //Watermelon:dont apply the 'hitbox' bonus if the 
target is a building
                        if ( psTempObj->type == OBJ_STRUCTURE || 
psTempObj->type == OBJ_FEATURE)
                        {
+                               //Watermelon:ignore oil resource and pickup
+                               if ( psTempObj->type == OBJ_FEATURE )
+                               {
+                                       if ( ((FEATURE 
*)psTempObj)->psStats->damageable == 0)
+                                       {
+                                               continue;
+                                       }
+                               }
                                wpRadius = 1;
                                //Watermelon:AA weapon shouldnt hit buildings
                                if ( psObj->psWStats->surfaceToAir == 
SHOOT_IN_AIR )
@@ -1103,8 +1111,16 @@
                        zdiff = (SDWORD)psObj->z - (SDWORD)psTempObj->z;

                        //Watermelon:dont apply the 'hitbox' bonus if the 
target is a building
-                       if ( psTempObj->type == OBJ_STRUCTURE )
+ if ( psTempObj->type == OBJ_STRUCTURE || psTempObj->type == OBJ_FEATURE )
                        {
+                               //Watermelon:ignore oil resource and pickup
+                               if ( psTempObj->type == OBJ_FEATURE )
+                               {
+                                       if ( ((FEATURE 
*)psTempObj)->psStats->damageable == 0)
+                                       {
+                                               continue;
+                                       }
+                               }
                                wpRadius = 1;
                        }


_______________________________________________
Warzone-dev mailing list
Warzone-dev@gna.org
https://mail.gna.org/listinfo/warzone-dev

Reply via email to