Advertisement
Guest User

Untitled

a guest
Feb 28th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.19 KB | None | 0 0
  1. // #define DEBUGSD
  2. int WP_SaberCanBlock(gentity_t *self, vec3_t point, int dflags, int mod, qboolean projectile, int attackStr)
  3. {
  4.     qboolean thrownSaber = qfalse;
  5.     float blockFactor = 0;
  6.  
  7.     if (!self || !self->client || !point)
  8.     {
  9.         return 0;
  10.     }
  11.  
  12.     #ifdef DEBUGSD
  13.     CV_SendClientPrint(self - g_entities, "WP_SaberCanBlock attackStr=%d... ", attackStr);
  14.     #endif
  15.  
  16.     if (attackStr == 8)
  17.     {
  18.         attackStr = 0;
  19.         thrownSaber = qtrue;
  20.     }
  21.  
  22.     if (BG_SaberInAttack(self->client->ps.saberMove))
  23.     {
  24.         #ifdef DEBUGSD
  25.         CV_SendClientPrint(self - g_entities, "no, saber in attack\n");
  26.         #endif
  27.         return 0;
  28.     }
  29.  
  30.     if (PM_InSaberAnim(self->client->ps.torsoAnim) && !self->client->ps.saberBlocked &&
  31.         self->client->ps.saberMove != LS_READY && self->client->ps.saberMove != LS_NONE)
  32.     {
  33.         if ( self->client->ps.saberMove < LS_PARRY_UP || self->client->ps.saberMove > LS_REFLECT_LL )
  34.         {
  35.             #ifdef DEBUGSD
  36.             CV_SendClientPrint(self - g_entities, "no, saber is in some animation\n");
  37.             #endif
  38.             return 0;
  39.         }
  40.     }
  41.  
  42.     if (self->client->ps.saberHolstered)
  43.     {
  44.         #ifdef DEBUGSD
  45.         CV_SendClientPrint(self - g_entities, "no, saber holstered\n");
  46.         #endif
  47.         return 0;
  48.     }
  49.  
  50.     if (self->client->ps.usingATST)
  51.     {
  52.         return 0;
  53.     }
  54.  
  55.     if (self->client->ps.weapon != WP_SABER)
  56.     {
  57.         #ifdef DEBUGSD
  58.         CV_SendClientPrint(self - g_entities, "no, not using saber\n");
  59.         #endif
  60.         return 0;
  61.     }
  62.  
  63.     if (self->client->ps.weaponstate == WEAPON_RAISING)
  64.     {
  65.         #ifdef DEBUGSD
  66.         CV_SendClientPrint(self - g_entities, "no, saber is raising\n");
  67.         #endif
  68.         return 0;
  69.     }
  70.  
  71.     if (self->client->ps.saberInFlight)
  72.     {
  73.         #ifdef DEBUGSD
  74.         CV_SendClientPrint(self - g_entities, "no, saber in flight\n");
  75.         #endif
  76.         return 0;
  77.     }
  78.  
  79.     if ((self->client->pers.cmd.buttons & BUTTON_ATTACK)/* &&
  80.         (projectile || attackStr == FORCE_LEVEL_3)*/)
  81.     { //don't block when the player is trying to slash, if it's a projectile or he's doing a very strong attack
  82.         #ifdef DEBUGSD
  83.         CV_SendClientPrint(self - g_entities, "no, i am holding attack button\n");
  84.         #endif
  85.         return 0;
  86.     }
  87.  
  88.     if (attackStr == FORCE_LEVEL_3)
  89.     {
  90.         if (self->client->ps.fd.forcePowerLevel[FP_SABERDEFEND] >= FORCE_LEVEL_3)
  91.         {
  92.             if (Q_irand(1, 10) < 3)
  93.             {
  94.                 #ifdef DEBUGSD
  95.                 CV_SendClientPrint(self - g_entities, "no, he is using strong attack and RNG decides that this shall not be blocked (i picked a number between 1 and 10, and it was below 3\n");
  96.                 #endif
  97.                 return 0;
  98.             }
  99.         }
  100.         else
  101.         {
  102.             return 0;
  103.         }
  104.     }
  105.  
  106.     if (attackStr == FORCE_LEVEL_2 && Q_irand(1, 10) < 3)
  107.     {
  108.         if (self->client->ps.fd.forcePowerLevel[FP_SABERDEFEND] >= FORCE_LEVEL_3)
  109.         {
  110.             //do nothing for now
  111.         }
  112.         else if (self->client->ps.fd.forcePowerLevel[FP_SABERDEFEND] >= FORCE_LEVEL_2)
  113.         {
  114.             if (Q_irand(1, 10) < 5)
  115.             {
  116.                 #ifdef DEBUGSD
  117.                 CV_SendClientPrint(self - g_entities, "no, he is using medium attack and RNG decides that this shall not be blocked (i picked a number between 1 and 10, and it was below 5\n");
  118.                 #endif
  119.                 return 0;
  120.             }
  121.         }
  122.         else
  123.         {
  124.             return 0;
  125.         }
  126.     }
  127.  
  128.     if (attackStr == FORCE_LEVEL_1 && !self->client->ps.fd.forcePowerLevel[FP_SABERDEFEND] &&
  129.         Q_irand(1, 40) < 3)
  130.     { //if I have no defense level at all then I might be unable to block a level 1 attack (but very rarely)
  131.         #ifdef DEBUGSD
  132.         CV_SendClientPrint(self - g_entities, "no, he is using fast attack and RNG decides that this shall not be blocked (i picked a number between 1 and 40, and it was below 3\n");
  133.         #endif
  134.         return 0;
  135.     }
  136.  
  137.     if (SaberAttacking(self))
  138.     { //attacking, can't block now
  139.  
  140.         #ifdef DEBUGSD
  141.         CV_SendClientPrint(self - g_entities, "no, SaberAttacking(self)\n");
  142.         #endif
  143.  
  144.         //FIXME: Do a "saber box" check here to see if the enemy saber hit this guy's saber
  145.         return 0;
  146.     }
  147.  
  148.     if (self->client->ps.saberMove != LS_READY &&
  149.         !self->client->ps.saberBlocking)
  150.     {
  151.         #ifdef DEBUGSD
  152.         CV_SendClientPrint(self - g_entities, "no, saberMove != LS_READY && !self->client->ps.saberBlocking\n");
  153.         #endif
  154.         return 0;
  155.     }
  156.  
  157.     if (self->client->ps.saberBlockTime >= level.time)
  158.     {
  159.         #ifdef DEBUGSD
  160.         CV_SendClientPrint(self - g_entities, "no, self->client->ps.saberBlockTime >= level.time\n");
  161.         #endif
  162.         return 0;
  163.     }
  164.  
  165.     if (self->client->ps.forceHandExtend != HANDEXTEND_NONE)
  166.     {
  167.         #ifdef DEBUGSD
  168.         CV_SendClientPrint(self - g_entities, "no, forceHandExtend != HANDEXTEND_NONE\n");
  169.         #endif
  170.         return 0;
  171.     }
  172.  
  173.     if (self->client->ps.fd.forcePowerLevel[FP_SABERDEFEND] == FORCE_LEVEL_3)
  174.     {
  175.         blockFactor = 0.05f;
  176.     }
  177.     else if (self->client->ps.fd.forcePowerLevel[FP_SABERDEFEND] == FORCE_LEVEL_2)
  178.     {
  179.         blockFactor = 0.6f;
  180.     }
  181.     else if (self->client->ps.fd.forcePowerLevel[FP_SABERDEFEND] == FORCE_LEVEL_1)
  182.     {
  183.         blockFactor = 0.9f;
  184.     }
  185.     else
  186.     { //for now we just don't get to autoblock with no def
  187.         return 0;
  188.     }
  189.  
  190.  
  191.     if (thrownSaber)
  192.     {
  193.         blockFactor -= 0.25f;
  194.     }
  195.  
  196.     if (!InFront( point, self->client->ps.origin, self->client->ps.viewangles, blockFactor )) //orig 0.2f
  197.     {
  198.         #ifdef DEBUGSD
  199.         CV_SendClientPrint(self - g_entities, "no, !InFront (blockFactor=%.2f)\n", blockFactor);
  200.         #endif
  201.         return 0;
  202.     }
  203.  
  204.     WP_SaberBlockNonRandom(self, point, projectile);
  205.  
  206.     #ifdef DEBUGSD
  207.     CV_SendClientPrint(self - g_entities, "yes, blocking it!\n");
  208.     #endif
  209.     return 1;
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement