shithub: choc

Download patch

ref: 0ac04776267a1a84724fcccfada12f769f4c315a
parent: bbb39c2906ab01b75e7959a0d07560a4a56c459a
author: James Haley <[email protected]>
date: Wed Sep 15 20:08:25 EDT 2010

Some reformatting, change of some strings to use DEH_String and
DEH_snprintf. Implemented proper logic for Shadowarmor that was missing
from P_GivePower, and added the code for making psprites translucent
and/or godmode-colormapped in R_DrawPSprite.

Subversion-branch: /branches/strife-branch
Subversion-revision: 2089

--- a/src/strife/p_inter.c
+++ b/src/strife/p_inter.c
@@ -71,41 +71,40 @@
 boolean P_GiveAmmo(player_t* player, ammotype_t ammo, int num)
 {
     int		oldammo;
-	
+
     if(ammo == am_noammo)
-	return false;
-		
+        return false;
+
     if(ammo > NUMAMMO)
-	I_Error ("P_GiveAmmo: bad type %i", ammo);
-		
+        I_Error ("P_GiveAmmo: bad type %i", ammo);
+
     if(player->ammo[ammo] == player->maxammo[ammo])
-	return false;
-		
+        return false;
+
     if(num)
-	num *= clipammo[ammo];
+        num *= clipammo[ammo];
     else
-	num = clipammo[ammo]/2;
-    
+        num = clipammo[ammo]/2;
+
     if(gameskill == sk_baby
-	|| gameskill == sk_nightmare)
+        || gameskill == sk_nightmare)
     {
-	// give double ammo in trainer mode,
-	// you'll need in nightmare
-	num <<= 1;
+        // give double ammo in trainer mode,
+        // you'll need in nightmare
+        num <<= 1;
     }
-    
-		
+
     oldammo = player->ammo[ammo];
     player->ammo[ammo] += num;
 
     if(player->ammo[ammo] > player->maxammo[ammo])
-	player->ammo[ammo] = player->maxammo[ammo];
+        player->ammo[ammo] = player->maxammo[ammo];
 
     // If non zero ammo, 
     // don't change up weapons,
     // player was lower on purpose.
     if(oldammo)
-	return true;	
+        return true;
 
     // We were down to zero,
     // so select a new weapon.
@@ -112,7 +111,7 @@
     // Preferences are not user selectable.
 
     // villsa [STRIFE] ammo update
-    // [STRIFE] TODO - where's the check for grenades?
+    // where's the check for grenades? - haleyjd: verified no switch to grenades
     switch(ammo && !player->readyweapon)
     {
     case am_bullets:
@@ -139,7 +138,7 @@
     default:
         break;
     }
-	
+
     return true;
 }
 
@@ -253,7 +252,7 @@
 
         player->health = health;
     }
-	
+
     return true;
 }
 
@@ -295,11 +294,11 @@
 boolean P_GiveCard(player_t* player, card_t card)
 {
     if (player->cards[card])
-	return false;
+        return false;
     
     // villsa [STRIFE] multiply by 2
     player->bonuscount = BONUSADD * 2;
-    player->cards[card] = 1;
+    player->cards[card] = true;
 
     return true;
 }
@@ -309,26 +308,46 @@
 // P_GivePower
 //
 boolean P_GivePower(player_t* player, powertype_t power)
-{
+{    
+    
+    // haleyjd 09/14/10: [STRIFE] moved to top, exception for Shadow Armor
+    if(player->powers[power] && power != pw_invisibility)
+        return false;	// already got it
+
+    // if giving pw_invisibility and player already has MVIS, no can do.
+    if(power == pw_invisibility && (player->mo->flags & MF_MVIS))
+        return false;
+
     // villsa [STRIFE]
     if(power == pw_targeter)
     {
         player->powers[power] = TARGTICS;
         P_SetPsprite(player, ps_targcenter, S_TRGT_00); // 10
-        P_SetPsprite(player, ps_targleft, S_TRGT_01); // 11
-        P_SetPsprite(player, ps_targright, S_TRGT_02); // 12
+        P_SetPsprite(player, ps_targleft,   S_TRGT_01); // 11
+        P_SetPsprite(player, ps_targright,  S_TRGT_02); // 12
 
         player->psprites[ps_targcenter].sx  = (160*FRACUNIT);
-        player->psprites[ps_targleft].sy    = (100*FRACUNIT);
+        player->psprites[ps_targleft  ].sy  = (100*FRACUNIT);
         player->psprites[ps_targcenter].sy  = (100*FRACUNIT);
-        player->psprites[ps_targright].sy   = (100*FRACUNIT);
+        player->psprites[ps_targright ].sy  = (100*FRACUNIT);
         return true;
     }
 
     if(power == pw_invisibility)
     {
+        // if player already had this power...
+        if(player->powers[power])
+        {
+            // remove SHADOW, give MVIS.
+            player->mo->flags &= ~MF_SHADOW;
+            player->mo->flags |= MF_MVIS;
+        }
+        else // give SHADOW
+            player->mo->flags |= MF_SHADOW;
+
+        // set tics if giving shadow, or renew them if MVIS.
         player->powers[power] = INVISTICS;
-        player->mo->flags |= MF_SHADOW;
+
         return true;
     }
 
@@ -348,8 +367,9 @@
     // villsa [STRIFE]
     if(power == pw_allmap)
     {
+        // remember in mapstate
         if(gamemap < 40)
-            player->mapstate[gamemap] = 1;
+            player->mapstate[gamemap] = true;
 
         player->powers[power] = 1;
         return true;
@@ -362,11 +382,7 @@
         return true;
     }
 
-
-    if(player->powers[power])
-        return false;	// already got it
-
-
+    // default behavior:
     player->powers[power] = 1;
     return true;
 }
@@ -512,7 +528,7 @@
             player->backpack = true;
         }
         for(i = 0; i < NUMAMMO; i++)
-	    P_GiveAmmo(player, i, 1);
+            P_GiveAmmo(player, i, 1);
         break;
 
     case SPR_COIN:
@@ -577,14 +593,17 @@
     if(!pickupmsg[0])
     {
         if(special->info->name)
-            sprintf(pickupmsg, "You picked up the %s.", special->info->name);
+        {
+            DEH_snprintf(pickupmsg, sizeof(pickupmsg), 
+                         "You picked up the %s.", DEH_String(special->info->name));
+        }
         else
-            sprintf(pickupmsg, "You picked up the item.");
+            DEH_snprintf(pickupmsg, sizeof(pickupmsg), "You picked up the item.");
     }
     // use the first character to indicate that the player is full on items
     else if(pickupmsg[0] == '!')
     {
-        sprintf(pickupmsg, "You cannot hold any more.");
+        DEH_snprintf(pickupmsg, sizeof(pickupmsg), "You cannot hold any more.");
         player->message = pickupmsg;
         return;
     }
--- a/src/strife/p_local.h
+++ b/src/strife/p_local.h
@@ -92,6 +92,10 @@
 //
 // P_USER
 //
+
+// haleyjd 09/15/10: externalized
+#define INVERSECOLORMAP         32
+
 void    P_PlayerThink (player_t* player);
 // haleyjd 08/30/10: [STRIFE] Needed externally
 void    P_Thrust (player_t* player, angle_t angle, fixed_t move);
--- a/src/strife/p_user.c
+++ b/src/strife/p_user.c
@@ -39,7 +39,6 @@
 
 
 // Index of the special effects (INVUL inverse) map.
-#define INVERSECOLORMAP		32
 #define LOOKPITCHAMOUNT         6                       // villsa [STRIFE]
 #define CENTERVIEWAMOUNT        (LOOKPITCHAMOUNT + 2)   // villsa [STRIFE]
 #define LOOKUPMAX               90                      // villsa [STRIFE]
--- a/src/strife/r_things.c
+++ b/src/strife/r_things.c
@@ -43,8 +43,11 @@
 
 #include "doomstat.h"
 
+// haleyjd
+#include "p_local.h"
 
 
+
 #define MINZ				(FRACUNIT*4)
 #define BASEYCENTER			100
 
@@ -710,14 +713,14 @@
     // decide which patch to use
 #ifdef RANGECHECK
     if ( (unsigned)psp->state->sprite >= (unsigned int) numsprites)
-	I_Error ("R_ProjectSprite: invalid sprite number %i ",
-		 psp->state->sprite);
+        I_Error ("R_ProjectSprite: invalid sprite number %i ",
+                 psp->state->sprite);
 #endif
     sprdef = &sprites[psp->state->sprite];
 #ifdef RANGECHECK
     if ( (psp->state->frame & FF_FRAMEMASK)  >= sprdef->numframes)
-	I_Error ("R_ProjectSprite: invalid sprite frame %i : %i ",
-		 psp->state->sprite, psp->state->frame);
+        I_Error ("R_ProjectSprite: invalid sprite frame %i : %i ",
+                 psp->state->sprite, psp->state->frame);
 #endif
     sprframe = &sprdef->spriteframes[ psp->state->frame & FF_FRAMEMASK ];
 
@@ -726,13 +729,13 @@
     
     // calculate edges of the shape
     tx = psp->sx-160*FRACUNIT;
-	
+
     tx -= spriteoffset[lump];	
     x1 = (centerxfrac + FixedMul (tx,pspritescale) ) >>FRACBITS;
 
     // off the right side
     if (x1 > viewwidth)
-	return;		
+        return;
 
     tx +=  spritewidth[lump];
     x2 = ((centerxfrac + FixedMul (tx, pspritescale) ) >>FRACBITS) - 1;
@@ -739,7 +742,7 @@
 
     // off the left side
     if (x2 < 0)
-	return;
+        return;
     
     // store information in a vissprite
     vis = &avis;
@@ -750,46 +753,61 @@
     
     if (flip)
     {
-	vis->xiscale = -pspriteiscale;
-	vis->startfrac = spritewidth[lump]-1;
+        vis->xiscale = -pspriteiscale;
+        vis->startfrac = spritewidth[lump]-1;
     }
     else
     {
-	vis->xiscale = pspriteiscale;
-	vis->startfrac = 0;
+        vis->xiscale = pspriteiscale;
+        vis->startfrac = 0;
     }
 
     // villsa [STRIFE] calculate y offset with view pitch
     vis->texturemid = ((BASEYCENTER<<FRACBITS)+FRACUNIT/2)-(psp->sy-spritetopoffset[lump])
         + FixedMul(vis->xiscale, (centery-viewheight/2)<<FRACBITS);
-    
+
     if (vis->x1 > x1)
-	vis->startfrac += vis->xiscale*(vis->x1-x1);
+        vis->startfrac += vis->xiscale*(vis->x1-x1);
 
     vis->patch = lump;
 
     if (viewplayer->powers[pw_invisibility] > 4*32
-	|| viewplayer->powers[pw_invisibility] & 8)
+        || viewplayer->powers[pw_invisibility] & 8)
     {
-	// shadow draw
-	vis->colormap = NULL;
+        // shadow draw
+        vis->colormap   = spritelights[MAXLIGHTSCALE-1];
+        vis->mobjflags |= MF_SHADOW;
     }
-    else if (fixedcolormap)
+    else if(viewplayer->powers[pw_invisibility] & 4)
     {
-	// fixed color
-	vis->colormap = fixedcolormap;
+        vis->mobjflags |= (MF_SHADOW|MF_MVIS);
     }
-    else if (psp->state->frame & FF_FULLBRIGHT)
+
+    // When not MVIS, or if SHADOW, behave normally:
+    if(!(viewplayer->mo->flags & MF_MVIS) || (viewplayer->mo->flags & MF_SHADOW))
     {
-	// full bright
-	vis->colormap = colormaps;
+        if (fixedcolormap)
+        {
+            // fixed color
+            vis->colormap = fixedcolormap;
+        }
+        else if (psp->state->frame & FF_FULLBRIGHT)
+        {
+            // full bright
+            vis->colormap = colormaps;
+        }
+        else
+        {
+            // local light
+            vis->colormap = spritelights[MAXLIGHTSCALE-1];
+        }
     }
     else
     {
-	// local light
-	vis->colormap = spritelights[MAXLIGHTSCALE-1];
+        // When MVIS, use invulnerability colormap
+        vis->colormap = colormaps + INVERSECOLORMAP * 256 * sizeof(lighttable_t);
     }
-	
+
     R_DrawVisSprite (vis, vis->x1, vis->x2);
 }