Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.69 KB | None | 0 0
  1.  
  2. int damageBlock(WorldContext& context, float x, float y, int damages, bool remote, bool back)
  3. {
  4.     World& world = *context.world;
  5.     int i=x/16, j=y/16;
  6.     //damages = 255;
  7.    
  8.     Tile & t = world.at(i, j);    
  9.     //printf("life:%d\n", t.life);
  10.    
  11.     if(t.front < Tile::FirstBlockIndex) // classes spéciales
  12.     {
  13.         if(t.back == Tile::Void)
  14.             return t.front;
  15.        
  16.         // @todo faire des backwalls breakable
  17.         // on regarde si au moins un block est 'vide'
  18.         bool bounds = back? true: (
  19.             world.at(i-1, j).back < Tile::FirstBlockIndex ||
  20.             world.at(i+1, j).back < Tile::FirstBlockIndex ||
  21.             world.at(i, j-1).back < Tile::FirstBlockIndex ||
  22.             world.at(i, j+1).back < Tile::FirstBlockIndex );
  23.        
  24.         if(!bounds)
  25.             return t.front;
  26.        
  27.         if(t.life != Tile::LifeMax && !t.indestructible())
  28.         {
  29.             if(!remote)
  30.                 networkSendDamageBlock(i, j, damages);
  31.            
  32.             if(t.life <= damages)
  33.             {
  34.                 int ret = t.back;
  35.                
  36.                 if(getCurrentAdminGameMode() != GameMode::Building)
  37.                     spawnDrops(context, od::Pos(i*16+2, j*16+2), BlockInfo::get(t.back).drops());
  38.                
  39.                 t.slopeBack = 38;
  40.                 t.back = Tile::Void;
  41.                 t.life = 0;
  42.                 return ret;
  43.             }
  44.             t.life -= damages;
  45.         }
  46.         return t.back;
  47.     }
  48.    
  49.     // check ore    
  50.     Ore & ore = world.findOre(i, j);
  51.     if(ore.valid())
  52.     {
  53.         if(!remote)
  54.             networkSendDamageBlock(i, j, damages);
  55.        
  56.         if(ore.life > damages)
  57.             ore.life -= damages;
  58.         else
  59.         {
  60.             OreInfo & info = OreInfo::get(ore.ind);
  61.             if(getCurrentAdminGameMode() != GameMode::Building)
  62.                 spawnDrops(context, od::Pos(i*16+2, j*16+2), info.drops());
  63.            
  64.             world.removeOre(i, j);
  65.         }
  66.     }
  67.     else if(world.at(i, j-1).front == Tile::LockDown)
  68.     {
  69.         return t.front;
  70.     }
  71.     else
  72.     {
  73.         if(!remote)
  74.             networkSendDamageBlock(i, j, damages); /// opti possible
  75.        
  76.         Ground & ground = world.findGround(i, j);
  77.         if(ground.valid())
  78.         {
  79.             world.removeGround(i, j);
  80.         }
  81.        
  82.         if(t.life != Tile::LifeMax && !t.indestructible())
  83.         {
  84.             if(t.life <= damages)
  85.             {
  86.                 int ret = t.front;
  87.                 removeBlock(context, x, y);
  88.                 return ret;
  89.             }
  90.  
  91.             t.life -= damages;
  92.         }
  93.     }
  94.     return t.front;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement