doom

a minimalistic implementation of doom
git clone git://ssnf.xyz/doom
Log | Files | Refs

p_telept.c (1618B)


      1 #include "doomdef.h"
      2 
      3 #include "s_sound.h"
      4 
      5 #include "p_local.h"
      6 
      7 
      8 
      9 #include "sounds.h"
     10 
     11 
     12 #include "r_state.h"
     13 
     14 
     15 
     16 
     17 
     18 
     19 int
     20 EV_Teleport
     21 ( line_t*	line,
     22   int		side,
     23   mobj_t*	thing )
     24 {
     25     int		i;
     26     int		tag;
     27     mobj_t*	m;
     28     mobj_t*	fog;
     29     unsigned	an;
     30     thinker_t*	thinker;
     31     sector_t*	sector;
     32     fixed_t	oldx;
     33     fixed_t	oldy;
     34     fixed_t	oldz;
     35 
     36     
     37     if (thing->flags & MF_MISSILE)
     38 	return 0;		
     39 
     40     
     41     
     42     if (side == 1)		
     43 	return 0;	
     44 
     45     
     46     tag = line->tag;
     47     for (i = 0; i < numsectors; i++)
     48     {
     49 	if (sectors[ i ].tag == tag )
     50 	{
     51 	    thinker = thinkercap.next;
     52 	    for (thinker = thinkercap.next;
     53 		 thinker != &thinkercap;
     54 		 thinker = thinker->next)
     55 	    {
     56 		
     57 		if (thinker->function.acp1 != (actionf_p1)P_MobjThinker)
     58 		    continue;	
     59 
     60 		m = (mobj_t *)thinker;
     61 		
     62 		
     63 		if (m->type != MT_TELEPORTMAN )
     64 		    continue;		
     65 
     66 		sector = m->subsector->sector;
     67 		
     68 		if (sector-sectors != i )
     69 		    continue;	
     70 
     71 		oldx = thing->x;
     72 		oldy = thing->y;
     73 		oldz = thing->z;
     74 				
     75 		if (!P_TeleportMove (thing, m->x, m->y))
     76 		    return 0;
     77 		
     78 		thing->z = thing->floorz;  
     79 		if (thing->player)
     80 		    thing->player->viewz = thing->z+thing->player->viewheight;
     81 				
     82 		
     83 		fog = P_SpawnMobj (oldx, oldy, oldz, MT_TFOG);
     84 		S_StartSound (fog, sfx_telept);
     85 		an = m->angle >> ANGLETOFINESHIFT;
     86 		fog = P_SpawnMobj (m->x+20*finecosine[an], m->y+20*finesine[an]
     87 				   , thing->z, MT_TFOG);
     88 
     89 		
     90 		S_StartSound (fog, sfx_telept);
     91 		
     92 		
     93 		if (thing->player)
     94 		    thing->reactiontime = 18;	
     95 
     96 		thing->angle = m->angle;
     97 		thing->momx = thing->momy = thing->momz = 0;
     98 		return 1;
     99 	    }	
    100 	}
    101     }
    102     return 0;
    103 }
    104