Ejemplo n.º 1
0
void ascatter_line(int x1, int y1, int x2, int y2, int c1, int c2, int s)
{
  short cx1,cy1,cx2,cy2;
  screen->get_clip(cx1,cy1,cx2,cy2);


  int t=abs(x2-x1)>abs(y2-y1) ? abs(x2-x1)+1 : abs(y2-y1)+1;
  long xo=x1<<16,yo=y1<<16,dx=((x2-x1)<<16)/t,dy=((y2-y1)<<16)/t,count=0,x,y;
  uchar *sl;

  int xm=(1<<s);
  int ym=(1<<s);
  s=(15-s);

  int w=screen->width();
  uchar *addr;


  while (t--)
  {
    x=(xo>>16)+(jrand()>>s)-xm;
    y=(yo>>16)+(jrand()>>s)-ym;
    if (!(x<=cx1 || y<=cy1 || x>=cx2 || y>=cy2))
    {
      addr=screen->scan_line(y)+x;
      *addr=c1;
      *(addr+w)=c2;
      *(addr-w)=c2;
      *(addr-1)=c2;
      *(addr+1)=c2;
    }
    xo+=dx; yo+=dy;
  }

}
Ejemplo n.º 2
0
static int ant_dodge(game_object *o)
{
  if (o->lvars[ANT_need_to_dodge]==1)
  {
    o->lvars[ANT_need_to_dodge]=0;
    if ((jrand()%2)==0)
    {
      o->set_state(stopped);
      o->set_aistate(ANT_JUMP);
      if (!can_see(o,o->x,o->y,o->x,o->y-120))   // is there a roof above?
      {
    o->set_yvel(-17);
    o->set_xvel(0);
    o->set_aistate(ANT_JUMP_ROOF);
    ant_ai();
      } else
      {
    o->set_yvel(-12);
    if (o->direction>0)
      o->set_xvel(22);
    else o->set_xvel(-22);
    o->set_aistate(ANT_JUMP);
      }
    }
    return 1;
  } else return 0;
}
Ejemplo n.º 3
0
Archivo: aesxam.c Proyecto: 8l/pulpino
int encfile(aes *ctx, byte *encoutbuf)
{
   fpos_t          flen;
   unsigned long   i=0, l=0, j, k;

   fillrand(encoutbuf, 16);           /* set an IV for CBC mode           */
   FLEN = 4096;
   fillrand(inbuf, 1);             /* make top 4 bits of a byte random */
   l = 15;                         /* and store the length of the last */
   /* block in the lower 4 bits        */
   inbuf[0] = ((char)FLEN & 15) | (inbuf[0] & ~15);

   for(j = 0; j <256; j++)
   {                               /* input 1st 16 bytes to buf[1..16] */
      for(k = 0; k < 16; ++k)
         inbuf[k] = jrand();

      for(i = 0; i < 16; ++i)         /* xor in previous cipher text  */
         inbuf[i] ^= encoutbuf[i];

      encrypt(inbuf, encoutbuf, ctx);    /* and do the encryption        */
      /* in all but first round read 16   */
      l = 16;                     /* bytes into the buffer            */
   }

   return 0;
}
Ejemplo n.º 4
0
void scatter_line(int x1, int y1, int x2, int y2, int c, int s)
{
  short cx1,cy1,cx2,cy2;
  screen->get_clip(cx1,cy1,cx2,cy2);
 
  int t=abs(x2-x1)>abs(y2-y1) ? abs(x2-x1)+1 : abs(y2-y1)+1;
  long xo=x1<<16,yo=y1<<16,dx=((x2-x1)<<16)/t,dy=((y2-y1)<<16)/t,count=0,x,y;
  uchar *sl;

  int xm=(1<<s);
  int ym=(1<<s);
  s=(15-s);


  while (t--)
  {
    x=(xo>>16)+(jrand()>>s)-xm;
    y=(yo>>16)+(jrand()>>s)-ym;
    if (!(x<cx1 || y<cy1 || x>cx2 || y>cy2))
      *(screen->scan_line(y)+x)=c;
    xo+=dx; yo+=dy;
  }

}
Ejemplo n.º 5
0
Archivo: aesxam.c Proyecto: 8l/pulpino
int decfile(aes *ctx, byte *decoutbuf)
{
   int     i,j, l, flen, k;

   fillrand(inbuf1, 16);           /* set an IV for CBC mode           */

   for(k = 0; k < 16; ++k)
      inbuf2[k] = jrand();
   
   decrypt(inbuf2, decoutbuf, ctx);   /* decrypt it                       */

   for(i = 0; i < 16; ++i)         /* xor with previous input          */
      decoutbuf[i] ^= inbuf1[i];

   flen = 0;  /* recover length of the last block and set */
   l = 15;                 /* the count of valid bytes in block to 15  */
   bp1 = inbuf1;           /* set up pointers to two input buffers     */
   bp2 = inbuf2;

   for(j = 0; j < 256; ++j)
   {
      for(k = 0; k < 16; ++k)
         bp1[k] = jrand();

      decrypt(bp1, decoutbuf, ctx);  /* decrypt the new input block and  */

      for(i = 0; i < 16; ++i)     /* xor it with previous input block */
         decoutbuf[i] ^= bp2[i];

      /* set byte count to 16 and swap buffer pointers                */

      l = i; tp = bp1, bp1 = bp2, bp2 = tp;
   }

   return 0;
}
Ejemplo n.º 6
0
void *ant_ai()
{
  game_object *o=current_object,*b;

  if (o->hp()==0)    // if we are dead return NULL and get deleted
  {
    if (o->state==dead)
      return NULL;
    else o->set_state(dead);
    return true_symbol;
  }


  if (o->state==flinch_up || o->state==flinch_down)
  {
    o->next_picture();
    return true_symbol;
  }


  switch (o->aistate())
  {
    case ANT_START :
    {
      o->set_state((character_state)S_hanging);
      if (o->lvars[ANT_hide_flag])
        o->set_aistate(ANT_HIDING);

      else o->set_aistate(ANT_HANGING);
    } break;
    case ANT_HIDING :
    {
      if ((jrand()%128)==0) the_game->play_sound(S_SCARE_SND,127,o->x,o->y);
      if (o->otype!=S_HIDDEN_ANT)
      {
    o->change_type(S_HIDDEN_ANT);      // switch types so noone hurts us.
    o->set_state(stopped);
    o->set_aistate(ANT_HIDING);
      }

      int fall=0;
      if (o->total_objects()==0)
      {
    if (player_list->next)
      b=current_level->attacker(current_object);
    else b=player_list->m_focus;
    if (abs(b->x-o->x)<130 && (o->y<b->y))
      fall=1;
      }
      else if (o->get_object(0)->aistate()!=0)
        fall=1;

      if (fall)
      {
    o->change_type(S_ANT_ROOF);
    o->set_state((character_state)S_falling);
    o->set_aistate(ANT_FALL_DOWN);
    o->set_targetable(1);
      } else o->set_targetable(0);
    } break;
    case ANT_HANGING :
    {
      int fall=0;
      if ((jrand()%128)==0) the_game->play_sound(S_SCARE_SND,127,o->x,o->y);
      if (o->lvars[ANT_hide_flag])
        o->set_aistate(ANT_HIDING);
      else
      {
    o->set_state((character_state)S_hanging);
    if (o->total_objects())
    {
      if (o->get_object(0)->aistate()!=0)
      fall=1;
    } else
    {
      if (player_list->next)
        b=current_level->attacker(current_object);
      else b=player_list->m_focus;
      if (abs(b->x-o->x)<130 && (o->y<b->y))
      fall=1;
    }
    if (fall)
    {
      o->set_state((character_state)S_fall_start);
      o->set_aistate(ANT_FALL_DOWN);
      o->set_targetable(1);
    } else o->set_targetable(0);
      }

    } break;
    case ANT_FALL_DOWN :
    {
      o->set_state((character_state)S_falling);

      if (player_list->next)
      b=current_level->attacker(current_object);
      else b=player_list->m_focus;

      scream_check(o,b);
      int ret=o->mover(0,0,0);
      if ((ret&BLOCKED_DOWN) || !can_see(o,o->x,o->y,o->x,o->y+1))
      {
    o->set_state((character_state)S_landing);
    the_game->play_sound(S_ALAND_SND,127,o->x,o->y);
    o->set_aistate(ANT_LANDING);
      }
    } break;
    case ANT_LANDING :
    {
      if (!o->next_picture())
      {
    int32_t xv=0,yv=2;
    o->try_move(o->x,o->y,xv,yv,1);
    if (yv!=0)
    {
      o->set_gravity(1);
      o->set_aistate(ANT_FALL_DOWN);
    }
    else
    {
      o->set_state(stopped);
      o->set_aistate(ANT_RUNNING);
      return (void *)ant_ai;
    }
      }
    } break;
    case ANT_RUNNING :
    {
      if (player_list->next)
      b=current_level->attacker(current_object);
      else b=player_list->m_focus;
      scream_check(o,b);


      if ((jrand()%16)==0)
      o->lvars[ANT_need_to_dodge]=1;
      if (!ant_dodge(o))
      {
    if ((o->x>b->x && o->direction==-1) || (o->x<b->x && o->direction==1))
    {
      o->next_picture();
      if ((jrand()%4)==0 && abs(o->x-b->x)<180 && abs(o->y-b->y)<100 && can_hit_player(o,b))
      {
        o->set_state((character_state)S_weapon_fire);
        o->set_aistate(ANT_FIRE);
      } else if (abs(o->x-b->x)<100 && abs(o->y-b->y)<10 && (jrand()%4)==0)
        o->set_aistate(ANT_POUNCE_WAIT);
      else if (abs(o->x-b->x)>140 && !ant_congestion(o))
        o->set_aistate(ANT_JUMP);
      else
      {
        int32_t xm=o->direction>0 ? get_ability(o->otype,run_top_speed) : -get_ability(o->otype,run_top_speed);
        int32_t ym=0,new_xm=xm;
        if (o->state!=running) o->set_state(running);

        o->try_move(o->x,o->y,new_xm,ym,3);
        if (new_xm!=xm)    // blocked, see if we can climb ramp
        {
          new_xm=xm;
          ym=-abs(xm);
          o->try_move(o->x,o->y,new_xm,ym,3);
          if (new_xm==xm)
          {
        o->x+=new_xm;
        o->y+=ym;
        new_xm=0;
        ym=abs(xm);      // now get back on the ground
        o->try_move(o->x,o->y,new_xm,ym,3);
        o->x+=new_xm;
        o->y+=ym;
          } else
          {
        o->direction=0-o->direction;
        o->set_aistate(ANT_JUMP);
          }
        } else
          o->x+=new_xm;
        new_xm=0;
        ym=10;       // see if we should fall
        o->try_move(o->x,o->y,new_xm,ym,3);
        if (ym==10)
          o->set_aistate(ANT_FALL_DOWN);
        else o->y+=ym;
      }
    } else
    {
      o->direction=o->x>b->x ? -1 : 1;
      o->set_aistate(ANT_LANDING);
    }
      }
    } break;

    case ANT_POUNCE_WAIT :
    {
      if (!ant_dodge(o))
      {
    o->set_state((character_state)S_pounce_wait);
    if (o->aistate_time()>alien_wait_time())
    {
      the_game->play_sound(S_ASLASH_SND,127,o->x,o->y);
      o->set_state(stopped);
      o->set_aistate(ANT_JUMP);
    }
      }
    } break;

    case ANT_JUMP :
    {
      o->lvars[ANT_need_to_dodge]=0;
      if (o->move(o->direction,-1,0)&BLOCKED_DOWN)
      o->set_aistate(ANT_RUNNING);
    } break;
    case ANT_FIRE :
    {
      if (!ant_dodge(o))
      {
    if (o->state==S_fire_wait)
    {
      if (!o->next_picture() || symbol_value(l_difficulty)==l_extreme)
      {
        if (player_list->next)
        b=current_level->attacker(current_object);
        else b=player_list->m_focus;
        fire_at_player(o,b);
        o->set_state(stopped);
        o->set_aistate(ANT_RUNNING);
      }
    } else o->set_state((character_state)S_fire_wait);
      }
    } break;
    case ANT_JUMP_ROOF :
    {
      o->lvars[ANT_need_to_dodge]=0;
      o->set_state((character_state)S_jump_up);
//      o->set_yvel(o->yvel()+1);
      o->set_xacel(0);
      int32_t xv=0,yv=o->yvel();
      o->y-=31;
      o->try_move(o->x,o->y,xv,yv,1);
      o->y+=31+yv;
      if (yv!=o->yvel())
      {
    if (o->yvel()>0)
    {
      o->set_state(stopped);
      o->set_aistate(ANT_RUNNING);
    } else
    {
      o->set_state((character_state)S_top_walk);
      o->set_aistate(ANT_ROOF_WALK);
    }
    o->set_yvel(0);
      }
    } break;
    case ANT_ROOF_WALK :
    {
      if (player_list->next)
      b=current_level->attacker(current_object);
      else b=player_list->m_focus;
      scream_check(o,b);
      if (((jrand()%8)==0 && abs(o->x-b->x)<10 && o->y<b->y) ||
      o->lvars[ANT_need_to_dodge]==1)
      {
    o->set_gravity(1);
    o->set_state(run_jump);
    o->set_aistate(ANT_JUMP);
    ant_ai();
      }
      else
      {
    if ((o->x>b->x && o->direction>0) || (o->x<b->x && o->direction<0))
    o->direction=-o->direction;
    else if (abs(o->x-b->x)<120 && (jrand()%4)==0)
    {
      o->set_state((character_state)S_ceil_fire);
      o->set_aistate(ANT_CEIL_SHOOT);
      ant_ai();
    } else
    {
      int speed=o->direction>0 ? get_ability(o->otype,run_top_speed) :
                -get_ability(o->otype,run_top_speed);
      if (can_see(o,o->x,o->y-31,o->x+speed,o->y-31) &&
          !can_see(o,o->x+speed,o->y-31,o->x+speed,o->y-32))
      {
        o->x+=speed;
        if (!o->next_picture()) o->set_state((character_state)S_top_walk);

      } else o->set_aistate(ANT_FALL_DOWN);
    }
      }
    } break;
    case ANT_CEIL_SHOOT :
    {
      if (!o->next_picture())
      {
    if (player_list->next)
      b=current_level->attacker(current_object);
    else b=player_list->m_focus;
    fire_at_player(o,b);
    o->set_state((character_state)S_top_walk);
    o->set_aistate(ANT_ROOF_WALK);
      }
    } break;
  }



  return true_symbol;
}