// File: /workspace/github_c_makefile_star2_O2/jonof[P]jftekwar/src/tekstat.c
// Function: enemyshootgun
void
enemyshootgun(short sprnum,int x,int y,int z,short daang,int dahoriz,
              short dasectnum,char guntype)
{
     short     hitsect,hitwall,hitsprite,daang2;
     int       j,daz2,hitx,hity,hitz,discrim;
     int       ext,target,pnum;

    #ifdef PLRSPRDEBUG
     if( isaplayersprite(sprnum) ) {
          crashgame("messing w plrsprite at 16");
     }
    #endif

     ext=sprptr[sprnum]->extra;
     if( !validext(ext) ) {
          crashgame("enemyshootgun: bad ext");
     }
     target=sprXTptr[sprnum]->target;
     if( !validplayer(target) ) {
          return;
     }

     // enemy gun fire sounds
     switch (guntype) {
     case 0:
          switch( sprXTptr[ext]->attackpic ) {
          case RATATTACKPIC:
               break;
          case 3910:
               playsound(S_WH_8,x,y,0,ST_NOUPDATE);
               break;
          default:
               playsound(S_MATRIX_ATTACK2,x,y,0,ST_NOUPDATE);
               break;
          }
          break;
     case 1:
     case 2:
     case 3:
     case 4:
          switch( sprXTptr[ext]->attackpic ) {
          case 3773:
          case 3800:
          case 3805:
          case 3810:
          case 3818:
               playsound(S_MATRIX_ATTACK,x,y,0,ST_NOUPDATE);
               break;
          case 3850:
          case 3860:
          case 3890:
          case 3909:
          case 3952:
          case 4001:
               playsound(S_MATRIX_ATTACK2,x,y,0,ST_NOUPDATE);
               break;
          case COPATTACKPIC:
               playsound(S_ENEMYGUN1,x,y,0,ST_NOUPDATE);
               break;
          case ANTATTACKPIC:
               playsound(S_ENEMYGUN2,x,y,0,ST_NOUPDATE);
               break;
          case MAATTACKPIC:
               playsound(S_ENEMYGUN3,x,y,0,ST_NOUPDATE);
               break;
          case SAMATTACKPIC:
               playsound(S_ENEMYGUN4,x,y,0,ST_NOUPDATE);
               break;
          default:
               playsound(S_ENEMYGUN1,x,y,0,ST_NOUPDATE);
               break;
          }
          break;
     case 5:
     case 6:
     case 7:
     case 8:
          switch( sprXTptr[ext]->attackpic ) {
          case 3773:
          case 3800:
          case 3805:
          case 3810:
          case 3818:
               playsound(S_MATRIX_ATTACK,x,y,0,ST_NOUPDATE);
               break;
          case 3850:
          case 3860:
          case 3890:
          case 3909:
          case 3952:
          case 4001:
               playsound(S_MATRIX_ATTACK2,x,y,0,ST_NOUPDATE);
               break;
          default:
               playsound(S_AUTOGUN,x,y,0,ST_NOUPDATE);
          }
          break;
     default:
          break;
     }

     // gun shot code
     switch (guntype) {
     case 0:
          if( (labs(x-posx[target])+labs(y-posy[target])) < 1024 ) {
               if( labs(z-posz[target]) < 12288 ) {
                    playerpainsound(target);
                    if( ((sprXTptr[ext]->fxmask)&FX_HOLOGRAM) != 0 ) {
                         playsound(S_MATRIX_ATTACK,x,y,0,ST_NOUPDATE);
                         enemywoundplayer(target,sprnum,0);
                    }
                    if( ((sprXTptr[ext]->fxmask)&FX_ANDROID) != 0 ) {
                         androidexplosion(sprnum);
                         enemywoundplayer(target,sprnum,6);
                         //changespritestat(sprnum, VANISH);
                         jsdeletesprite(sprnum);
                    }
                    else {
                         enemywoundplayer(target,sprnum,0);
                    }
               }
          }
          return;
     case GUN3FLAG:
     case GUN4FLAG:
     case GUN5FLAG:
          daang2=daang;
          daz2=((100-dahoriz)<<11);
          z=posz[target];     // instead of calculating a dot product angle
          hitscan(x,y,z,dasectnum,sintable[(daang2+2560)&2047],
               sintable[(daang2+2048)&2047],daz2,
               &hitsect,&hitwall,&hitsprite,&hitx,&hity,&hitz,CLIPMASK1);
          if( hitsprite > 0 ) {
               if( playerhit(hitsprite, &pnum) ) {
                    playerpainsound(pnum);
                    enemywoundplayer(pnum,sprnum,3);
               }
               else {
                    damagesprite(hitsprite,tekgundamage(guntype,x,y,z,hitsprite));
               }
          }
          else {
               j=jsinsertsprite(hitsect, 3);
               if( j != -1 ) {
                    fillsprite(j,hitx,hity,hitz+(8<<8),2,-4,0,32,16,16,0,0,
                               EXPLOSION,daang,0,0,0,sprnum+MAXSPRITES,hitsect,3,63,0,0);
               }
          }
          break;
     case GUN6FLAG:
	     j = jsinsertsprite(sprptr[sprnum]->sectnum, PROJECTILE);
          if ( j ==  -1 ) {
               break;
          }
	     sprptr[j]->x=sprptr[sprnum]->x;
	     sprptr[j]->y=sprptr[sprnum]->y;
          switch( sprXTptr[ext]->basestat ) {
          case FLY:
	          sprptr[j]->z=sprptr[sprnum]->z;
               break;
          default:
	          sprptr[j]->z=sectptr[sprptr[sprnum]->sectnum]->floorz-8192;
               break;
          }
	     sprptr[j]->cstat=0x01;
	     sprptr[j]->picnum=PULSARPIC;
	     sprptr[j]->shade=-32;
	     sprptr[j]->xrepeat=32;
	     sprptr[j]->yrepeat=32;
	     sprptr[j]->ang=sprptr[sprnum]->ang;
	     sprptr[j]->xvel=(sintable[(sprptr[j]->ang+2560)&2047]>>4);
	     sprptr[j]->yvel=(sintable[(sprptr[j]->ang+2048)&2047]>>4);
          discrim=ksqrt((posx[target]-sprptr[j]->x)*(posx[target]-sprptr[j]->x) +
				    (posy[target]-sprptr[j]->y)*(posy[target]-sprptr[j]->y));
          if ( discrim == 0 ) {
               discrim=1;
          }
	     sprptr[j]->zvel=((posz[target]+(8<<8)-sprptr[j]->z)<<9)/discrim;
          sprptr[j]->owner=sprnum;
	     sprptr[j]->clipdist=16L;
	     sprptr[j]->lotag=0;
	     sprptr[j]->hitag=0;
          break;
     default:
          break;
     }

     if( guntype != 0 ) {
          enemygunshot(sprnum);
     }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, 0x20(%rsp)
movl %r8d, %r14d
movl %ecx, %ebp
movl %edx, (%rsp)
movl %esi, 0x4(%rsp)
movl %edi, %ebx
movb 0x78(%rsp), %r13b
movzwl 0x70(%rsp), %eax
movw %ax, 0xa(%rsp)
callq 0x1cfc4
testl %eax, %eax
je 0x205db
leaq 0x6219f(%rip), %rdi     # 0x82773
xorl %eax, %eax
callq 0x2acb8
movq %rbx, 0x10(%rsp)
movswq %bx, %rbx
leaq 0x106c45(%rip), %rax    # 0x127230
movq (%rax,%rbx,8), %rax
movswq 0x2a(%rax), %r12
cmpq $0x4000, %r12           # imm = 0x4000
jb 0x2060b
leaq 0x62189(%rip), %rdi     # 0x8278d
xorl %eax, %eax
callq 0x2acb8
leaq 0x1aec1e(%rip), %rax    # 0x1cf230
movq (%rax,%rbx,8), %rax
movzwl 0x2(%rax), %r15d
movl %r15d, %edi
callq 0xe2e0
testl %eax, %eax
je 0x20be7
movsbl %r13b, %r13d
leal -0x1(%r13), %eax
cmpl $0x4, %eax
jb 0x206a8
leal -0x5(%r13), %eax
cmpl $0x4, %eax
jae 0x20723
movl %r14d, 0x1c(%rsp)
leaq 0x1aebdf(%rip), %rax    # 0x1cf230
movq (%rax,%r12,8), %rax
movzwl 0x12(%rax), %eax
leal -0xebd(%rax), %ecx
cmpl $0x2d, %ecx
movl (%rsp), %r14d
jbe 0x20755
leal -0xf0a(%rax), %ecx
cmpl $0x3b, %ecx
ja 0x2068b
movabsq $0x800010000000401, %rdx # imm = 0x800010000000401
btq %rcx, %rdx
jb 0x207a5
cmpl $0xfa1, %eax            # imm = 0xFA1
je 0x207a5
cmpl $0xf70, %eax            # imm = 0xF70
je 0x207a5
pushq $0x69
jmp 0x2089b
movl %r14d, 0x1c(%rsp)
leaq 0x1aeb7c(%rip), %rax    # 0x1cf230
movq (%rax,%r12,8), %rax
movzwl 0x12(%rax), %eax
leal -0xebd(%rax), %ecx
cmpl $0x2d, %ecx
movl (%rsp), %r14d
jbe 0x20773
leal -0xf0a(%rax), %ecx
cmpl $0x3b, %ecx
jbe 0x20791
cmpl $0x490, %eax            # imm = 0x490
je 0x2071c
cmpl $0x6eb, %eax            # imm = 0x6EB
je 0x20899
cmpl $0x73e, %eax            # imm = 0x73E
je 0x20891
cmpl $0x7e7, %eax            # imm = 0x7E7
je 0x20895
cmpl $0xfa1, %eax            # imm = 0xFA1
je 0x207a5
cmpl $0xf70, %eax            # imm = 0xF70
je 0x207a5
pushq $0x5f
jmp 0x2089b
testl %r13d, %r13d
jne 0x20bdd
movq %r12, %r14
leaq 0x1aeafa(%rip), %rax    # 0x1cf230
movq (%rax,%r12,8), %rax
movzwl 0x12(%rax), %eax
cmpl $0x118, %eax            # imm = 0x118
movl 0x4(%rsp), %ebx
je 0x207c4
cmpl $0xf46, %eax            # imm = 0xF46
jne 0x207af
pushq $0x1f
popq %rdi
jmp 0x207b4
movl $0x92, %edi
movabsq $0x202108000001, %rdx   # imm = 0x202108000001
btq %rcx, %rdx
jb 0x2089c
jmp 0x2066c
movl $0x92, %edi
movabsq $0x202108000001, %rdx   # imm = 0x202108000001
btq %rcx, %rdx
jb 0x2089c
jmp 0x206cf
movabsq $0x800010000000401, %rdx # imm = 0x800010000000401
btq %rcx, %rdx
jae 0x206de
movl $0x93, %edi
jmp 0x2089c
movl $0x93, %edi
pushq $0x4
popq %r8
movl %ebx, %esi
movl (%rsp), %edx
xorl %ecx, %ecx
callq 0x1ab2a
leal (,%r15,4), %eax
leaq 0xb9cfd(%rip), %rcx     # 0xda4d0
subl (%rcx,%rax), %ebx
movl %ebx, %ecx
negl %ecx
cmovsl %ebx, %ecx
leaq 0xb9d2c(%rip), %rdx     # 0xda510
movl (%rsp), %esi
subl (%rdx,%rax), %esi
movl %esi, %eax
negl %eax
cmovsl %esi, %eax
addq %rcx, %rax
cmpq $0x3ff, %rax            # imm = 0x3FF
ja 0x20be7
movl %r15d, %eax
leaq 0xb9d46(%rip), %rcx     # 0xda550
subl (%rcx,%rax,4), %ebp
movl %ebp, %eax
negl %eax
cmovsl %ebp, %eax
cmpl $0x2fff, %eax           # imm = 0x2FFF
ja 0x20be7
movl %r15d, %edi
callq 0xe5f6
leaq 0x1aea02(%rip), %r12    # 0x1cf230
movq (%r12,%r14,8), %rax
movzwl 0x4(%rax), %eax
movq 0x10(%rsp), %rbx
movswl %bx, %ebp
testb $0x8, %al
je 0x2086e
pushq $0x4
popq %r8
movl $0x92, %edi
movl 0x4(%rsp), %esi
movl (%rsp), %edx
xorl %ecx, %ecx
callq 0x1ab2a
movswl %r15w, %edi
movl %ebp, %esi
xorl %edx, %edx
callq 0x20509
movq (%r12,%r14,8), %rax
movzwl 0x4(%rax), %eax
testb $0x4, %al
jne 0x20bf6
movswl %r15w, %edi
movl %ebp, %esi
xorl %edx, %edx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x20509
pushq $0x61
jmp 0x2089b
pushq $0x62
jmp 0x2089b
pushq $0x60
popq %rdi
movq %r12, %rbp
pushq $0x4
popq %r8
movl 0x4(%rsp), %r12d
movl %r12d, %esi
movl %r14d, %edx
xorl %ecx, %ecx
callq 0x1ab2a
leal -0x3(%r13), %eax
cmpl $0x3, %eax
jae 0x20989
movl 0x20(%rsp), %ecx
shll $0xb, %ecx
movl $0x32000, %eax          # imm = 0x32000
subl %ecx, %eax
leaq 0xb9c79(%rip), %rcx     # 0xda550
movl %r14d, %ebp
movl (%rcx,%r15,4), %r15d
movl 0x1c(%rsp), %ebx
movzwl %bx, %ecx
leal 0x200(%rcx), %edx
movl $0x7ff, %esi            # imm = 0x7FF
andl %esi, %edx
leaq 0x5552d7(%rip), %rdi    # 0x575bd0
movswl (%rdi,%rdx,2), %r8d
andl %esi, %ecx
movswl (%rdi,%rcx,2), %r9d
leaq 0x28(%rsp), %r10
leaq 0x2c(%rsp), %r11
leaq 0xc(%rsp), %r14
movswl 0xa(%rsp), %ecx
movl %r12d, %edi
movl %ebp, %esi
movl %r15d, %edx
pushq $0x1000040              # imm = 0x1000040
pushq %r10
pushq %r11
leaq 0x48(%rsp), %r10
pushq %r10
pushq %r14
leaq 0x5e(%rsp), %r10
pushq %r10
leaq 0x3e(%rsp), %r10
pushq %r10
pushq %rax
callq 0x447c6
addq $0x40, %rsp
movswl (%r14), %edi
testl %edi, %edi
jle 0x209f7
leaq 0x24(%rsp), %rsi
callq 0x20d25
testl %eax, %eax
je 0x20a9d
movl 0x24(%rsp), %ebp
movl %ebp, %edi
callq 0xe5f6
movswl 0x10(%rsp), %esi
movswl %bp, %edi
pushq $0x3
popq %rdx
callq 0x20509
jmp 0x20bdd
cmpl $0x6, %r13d
leaq 0x10689c(%rip), %r14    # 0x127230
jne 0x20bdd
movq (%r14,%rbx,8), %rax
movswl 0x18(%rax), %edi
movl $0x191, %esi            # imm = 0x191
callq 0x1cf0c
cmpw $-0x1, %ax
je 0x20bdd
movq (%r14,%rbx,8), %rcx
movl (%rcx), %ecx
movswq %ax, %r12
movq (%r14,%r12,8), %rax
movl %ecx, (%rax)
movq (%r14,%rbx,8), %rax
movl 0x4(%rax), %eax
movq (%r14,%r12,8), %rcx
movl %eax, 0x4(%rcx)
leaq 0x1ae855(%rip), %rax    # 0x1cf230
movq (%rax,%rbp,8), %rax
cmpw $0x1f4, 0x8(%rax)       # imm = 0x1F4
movq (%r14,%rbx,8), %rax
jne 0x20ac7
movl 0x8(%rax), %eax
jmp 0x20adf
movswl 0xe(%rsp), %edi
pushq $0x3
popq %rsi
callq 0x1cf0c
cmpw $-0x1, %ax
je 0x20bdd
movswq %ax, %rax
imulq $0x2c, %rax, %rcx
leaq 0x403113(%rip), %rdx    # 0x423b30
leaq (%rdx,%rcx), %rdi
movl 0x30(%rsp), %esi
movl %esi, (%rdx,%rcx)
movl 0x2c(%rsp), %esi
movl %esi, 0x4(%rdx,%rcx)
movl $0x800, %esi            # imm = 0x800
addl 0x28(%rsp), %esi
movl %esi, 0x8(%rdx,%rcx)
movl $0x1ab0002, 0xc(%rdx,%rcx) # imm = 0x1AB0002
movw $0xfc, 0x10(%rdx,%rcx)
movb $0x20, 0x12(%rdx,%rcx)
movl $0x1010, 0x14(%rdx,%rcx) # imm = 0x1010
movw %bx, 0x1c(%rdx,%rcx)
movq 0x10(%rsp), %rsi
addl $0x4000, %esi           # imm = 0x4000
movw %si, 0x1e(%rdx,%rcx)
movabsq $0x3f000000000000, %rsi # imm = 0x3F000000000000
movq %rsi, 0x20(%rdx,%rcx)
movl $0xffff0000, 0x28(%rdx,%rcx) # imm = 0xFFFF0000
imulq $0xc, %rax, %rsi
addq 0xa6528(%rip), %rsi     # 0xc6fb8
pushq $0x3
popq %rdx
callq 0x56a36
jmp 0x20bdd
movswl 0xc(%rsp), %r14d
movl %r13d, %edi
movl 0x4(%rsp), %esi
movl (%rsp), %edx
movl %r15d, %ecx
movl %r14d, %r8d
callq 0xe387
movl %r14d, %edi
movl %eax, %esi
callq 0x1fc8e
jmp 0x20bdd
movswq 0x18(%rax), %rax
leaq 0x1ce75d(%rip), %rcx    # 0x1ef230
movq (%rcx,%rax,8), %rcx
movl $0xffffe000, %eax       # imm = 0xFFFFE000
addl 0x8(%rcx), %eax
movq (%r14,%r12,8), %rcx
movl %eax, 0x8(%rcx)
movq (%r14,%r12,8), %rax
movw $0x1, 0xc(%rax)
movq (%r14,%r12,8), %rax
movw $0x138, 0xe(%rax)       # imm = 0x138
movq (%r14,%r12,8), %rax
movb $-0x20, 0x10(%rax)
movq (%r14,%r12,8), %rax
movb $0x20, %cl
movb %cl, 0x14(%rax)
movq (%r14,%r12,8), %rax
movb %cl, 0x15(%rax)
movq (%r14,%rbx,8), %rax
movzwl 0x1c(%rax), %eax
movq (%r14,%r12,8), %rcx
movw %ax, 0x1c(%rcx)
movq (%r14,%r12,8), %rax
movl $0x200, %ecx            # imm = 0x200
addl 0x1c(%rax), %ecx
movl $0x7ff, %edx            # imm = 0x7FF
andl %edx, %ecx
leaq 0x555094(%rip), %rsi    # 0x575bd0
movswl (%rsi,%rcx,2), %ecx
shrl $0x4, %ecx
movw %cx, 0x20(%rax)
movq (%r14,%r12,8), %rax
movzwl 0x1c(%rax), %ecx
andl %edx, %ecx
movswl (%rsi,%rcx,2), %ecx
shrl $0x4, %ecx
movw %cx, 0x22(%rax)
leal (,%r15,4), %ebx
leaq 0xb9965(%rip), %rax     # 0xda4d0
movl (%rax,%rbx), %eax
movq (%r14,%r12,8), %rcx
subl (%rcx), %eax
imull %eax, %eax
leaq 0xb9992(%rip), %rdx     # 0xda510
movl (%rdx,%rbx), %edi
subl 0x4(%rcx), %edi
imull %edi, %edi
addl %eax, %edi
callq 0x43f6c
movl %eax, %ecx
cmpl $0x1, %eax
adcl $0x0, %ecx
leaq 0xb99b3(%rip), %rax     # 0xda550
movl (%rax,%rbx), %eax
movq (%r14,%r12,8), %rsi
subl 0x8(%rsi), %eax
shll $0x9, %eax
addl $0x100000, %eax         # imm = 0x100000
cltd
idivl %ecx
movw %ax, 0x24(%rsi)
movq (%r14,%r12,8), %rax
movq 0x10(%rsp), %rcx
movw %cx, 0x1e(%rax)
movq (%r14,%r12,8), %rax
movb $0x10, 0x12(%rax)
movq (%r14,%r12,8), %rax
andw $0x0, 0x26(%rax)
movq (%r14,%r12,8), %rax
andw $0x0, 0x28(%rax)
movq 0x10(%rsp), %rdi
callq 0x201bd
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ebx, %edi
callq 0x20c20
movswl %r15w, %edi
pushq $0x6
popq %rdx
movl %ebp, %esi
callq 0x20509
movl %ebp, %edi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1cf5e