void World::Damage(const ushort x, const ushort y, const ushort z, const ushort dmg, const int dmg_kind) { Block * temp = GetBlock(x, y, z); if ( temp==Normal(temp->Sub()) && AIR!=temp->Sub() ) { SetBlock((temp=NewBlock(temp->Kind(), temp->Sub())), x, y, z); } if ( temp->Damage(dmg, dmg_kind) > 0 ) { temp->ReceiveSignal(SOUND_STRINGS[1]); // "Ouch!" if ( block_manager.MakeId(BLOCK, STONE)==temp->GetId() && temp->Durability()!=MAX_DURABILITY ) { // convert stone into ladder DeleteBlock(temp); SetBlock(NewBlock(LADDER, STONE), x, y, z); emit ReEnlighten(x, y, z); } else { SetBlock(ReplaceWithNormal(temp), x, y, z); } } }
void r_ShredInfo::BuildShred( r_WorldVertex* shred_vertices ) { model_list.Clear(); model_list.SetModelCount( model_count_to_draw ); model_list.AllocateMemory(); unsigned char x, y, z; Block* b; unsigned char x1= false , y1= false , z1= false; unsigned char current= false; //false видим //true невидим unsigned char normal_id; unsigned char light; unsigned char tex_id, tex_scale, tc_x, tc_y; char texture_basis[4]; unsigned int v13[2]; short X= latitude * 16, Y= longitude * 16; short relative_X, relative_Y; const World* world= shred->GetWorld(); relative_Y= (shred->Longitude() - world->Longitude() + world->NumShreds()/2 )*16; relative_X= (shred->Latitude() - world->Latitude() + world->NumShreds()/2 )*16; bool flat_lighting= relative_X == 0 || relative_Y == 0 || relative_X/16 >= ( world->NumShreds()-1)|| relative_Y/16 >= ( world->NumShreds()-1) ; /*Поскольку количество квадов с водой становится известно только на этапе построения меша, размещать их приходится от конца буффера с данными вершин, и заполнять в обратном направлении*/ water_vertices= shred_vertices + quad_count * 4 - 4; water_quad_count= 0; r_WorldVertex* tmp_vert_p; /*в конце алгоритма указатель как раз будет указывать на начало буффера с квадами воды*/ for( x= 0; x< R_SHRED_WIDTH - 1 ; x++ ) { for( y= 0; y< R_SHRED_WIDTH - 1; y++ ) { z1= visibly_information[ (x<<11) | (y<<7) | min_geometry_height ]; for( z= min_geometry_height; z<= max_geometry_height; z++ ) { current= z1; x1= visibly_information[ ((x+1)<<11) | (y<<7) | z ] &3; y1= visibly_information[ (x<<11) | ((y+1)<<7) | z ] &3; z1= visibly_information[ (x<<11) | (y<<7) | (z+1) ]; if( z1 & 4 ) { b= shred->GetBlock( x, y, z + 1 ); unsigned char s= b->Sub(), k= b->Kind(), d= b->GetDir(); model_list.AddModel( b->GetId(), d, r_TextureManager::GetBlockTexture( b->GetId(), 0, 0 ), shred->Lightmap( x, y, z + 1 ), x + X, y + Y, z ); } z1&= 3; if( current != x1 ) { normal_id= WORLD_NORMAL_X; if( current > x1 ) { v13[0]= 1; v13[1]= 3; normal_id++; b= shred->GetBlock( x + 1, y, z ); light= shred->Lightmap( x , y, z ); } else { v13[0]= 3; v13[1]= 1; b= shred->GetBlock( x, y, z ); light= shred->Lightmap( x + 1, y, z ); } BUILD_QUAD_X } if( current != y1 ) { normal_id= WORLD_NORMAL_Y; if( current > y1 ) { v13[0]= 1; v13[1]= 3; normal_id++; b= shred->GetBlock( x, y + 1, z ); light= shred->Lightmap( x, y, z ); } else { v13[0]= 3; v13[1]= 1; b= shred->GetBlock( x, y, z ); light= shred->Lightmap( x, y+1, z ); } BUILD_QUAD_Y } if( current != z1 ) { normal_id= WORLD_NORMAL_Z; if( current > z1 ) { v13[0]= 1; v13[1]= 3; normal_id++; b= shred->GetBlock( x, y, z + 1 ); light= shred->Lightmap( x , y, z ); } else { v13[0]= 3; v13[1]= 1; b= shred->GetBlock( x, y, z ); light= shred->Lightmap( x, y, z + 1 ); } BUILD_QUAD_Z } }