p_change.c (3820B)
1 /* p_change.c */ 2 3 #include "doomdef.h" 4 #include "p_local.h" 5 #include "st_main.h" 6 7 //completo y revisado 8 9 /* 10 ============================================================================== 11 12 SECTOR HEIGHT CHANGING 13 14 = After modifying a sectors floor or ceiling height, call this 15 = routine to adjust the positions of all things that touch the 16 = sector. 17 = 18 = If anything doesn't fit anymore, true will be returned. 19 = If crunch is true, they will take damage as they are being crushed 20 = If Crunch is false, you should set the sector height back the way it 21 = was and call P_ChangeSector again to undo the changes 22 ============================================================================== 23 */ 24 25 static boolean crushchange;// 800A5690 26 static boolean nofit; // 800A5694 27 28 /* 29 ================== 30 = 31 = P_ThingHeightClip 32 = 33 = Takes a valid thing and adjusts the thing->floorz, thing->ceilingz, 34 = anf possibly thing->z 35 = 36 = This is called for all nearby monsters whenever a sector changes height 37 = 38 = If the thing doesn't fit, the z will be set to the lowest value and 39 = false will be returned 40 ================== 41 */ 42 43 boolean P_ThingHeightClip (mobj_t *thing) // 80010180 44 { 45 boolean onfloor; 46 47 onfloor = (thing->z == thing->floorz); 48 49 P_CheckPosition (thing, thing->x, thing->y); 50 /* what about stranding a monster partially off an edge? */ 51 52 thing->floorz = tmfloorz; 53 thing->ceilingz = tmceilingz; 54 55 if (onfloor) 56 /* walking monsters rise and fall with the floor */ 57 thing->z = thing->floorz; 58 else 59 { /* don't adjust a floating monster unless forced to */ 60 if (thing->z+thing->height > thing->ceilingz) 61 thing->z = thing->ceilingz - thing->height; 62 } 63 64 if (thing->ceilingz - thing->floorz < thing->height) 65 return false; 66 67 return true; 68 } 69 70 71 /* 72 =============== 73 = 74 = PIT_ChangeSector 75 = 76 =============== 77 */ 78 79 boolean PIT_ChangeSector (mobj_t *thing) // 80010234 80 { 81 mobj_t *mo; 82 83 if (P_ThingHeightClip (thing)) 84 return true; /* keep checking */ 85 86 /* crunch bodies to giblets */ 87 if (thing->health <= 0 && thing->tics == -1) 88 { 89 if(thing->state != &states[S_498]) 90 { 91 P_SetMobjState(thing, S_498);//S_GIBS 92 S_StartSound(thing, sfx_slop); 93 thing->height = 0; 94 thing->radius = 0; 95 } 96 97 return true; /* keep checking */ 98 } 99 100 /* crunch dropped items */ 101 if (thing->flags & MF_DROPPED) 102 { 103 P_RemoveMobj (thing); 104 return true; /* keep checking */ 105 } 106 107 if (!(thing->flags & MF_SHOOTABLE) ) 108 return true; /* assume it is bloody gibs or something */ 109 110 nofit = true; 111 112 // 113 // [d64] insta-kill thing if sector type is 666 114 // 115 if(crushchange == 2) 116 { 117 P_DamageMobj(thing, NULL, NULL, MAXINT); 118 return true; 119 } 120 else 121 { 122 if (crushchange && !(gametic&3) ) 123 { 124 P_DamageMobj(thing,NULL,NULL,10); 125 /* spray blood in a random direction */ 126 mo = P_SpawnMobj (thing->x, thing->y, thing->z + thing->height/2, MT_BLOOD); 127 mo->momx = (P_Random() - P_Random())<<12; 128 mo->momy = (P_Random() - P_Random())<<12; 129 } 130 } 131 132 return true; /* keep checking (crush other things) */ 133 } 134 135 /* 136 =============== 137 = 138 = P_ChangeSector 139 = 140 =============== 141 */ 142 143 boolean P_ChangeSector (sector_t *sector, boolean crunch) // 800103BC 144 { 145 int x,y; 146 int i; 147 148 /* force next sound to reflood */ 149 players[0].lastsoundsector = NULL; 150 151 nofit = false; 152 crushchange = crunch; 153 154 // [d64] handle special case if sector's special is 666 155 if(sector->special == 666) 156 crushchange = 2; 157 158 /* recheck heights for all things near the moving sector */ 159 for (x = sector->blockbox[BOXLEFT]; x <= sector->blockbox[BOXRIGHT]; x++) 160 { 161 for (y = sector->blockbox[BOXBOTTOM]; y <= sector->blockbox[BOXTOP]; y++) 162 { 163 P_BlockThingsIterator(x, y, PIT_ChangeSector); 164 } 165 } 166 167 return nofit; 168 } 169 170