Exemple #1
0
void CBasicMapDamage::Update()
{
	SCOPED_TIMER("BasicMapDamage::Update");

	std::deque<Explo*>::iterator ei;

	for (ei = explosions.begin(); ei != explosions.end(); ++ei) {
		Explo* e = *ei;
		if (e->ttl <= 0) {
			continue;
		}
		--e->ttl;

		const int x1 = e->x1;
		const int x2 = e->x2;
		const int y1 = e->y1;
		const int y2 = e->y2;
		std::vector<float>::const_iterator si = e->squares.begin();

		for (int y = y1; y <= y2; ++y) {
			for (int x = x1; x<= x2; ++x) {
				const float dif = *(si++);
				readMap->AddHeight(y * gs->mapxp1 + x, dif);
			}
		}
		std::vector<ExploBuilding>::const_iterator bi;
		for (bi = e->buildings.begin(); bi != e->buildings.end(); ++bi) {
			const float dif = bi->dif;
			const int tx1 = bi->tx1;
			const int tx2 = bi->tx2;
			const int tz1 = bi->tz1;
			const int tz2 = bi->tz2;

			for (int z = tz1; z < tz2; z++) {
				for (int x = tx1; x < tx2; x++) {
					readMap->AddHeight(z * gs->mapxp1 + x, dif);
				}
			}

			CUnit* unit = unitHandler->GetUnit(bi->id);

			if (unit != NULL) {
				unit->Move(UpVector * dif, true);
			}
		}
		if (e->ttl == 0) {
			RecalcArea(x1 - 2, x2 + 2, y1 - 2, y2 + 2);
		}
	}

	while (!explosions.empty() && explosions.front()->ttl == 0) {
		delete explosions.front();
		explosions.pop_front();
	}

	UpdateLos();
}
void CBasicMapDamage::Update()
{
	SCOPED_TIMER("BasicMapDamage::Update");

	for (Explo* e: explosions) {
		if (e->ttl <= 0) {
			continue;
		}
		--e->ttl;

		std::vector<float>::const_iterator si = e->squares.begin();
		for (int y = e->y1; y <= e->y2; ++y) {
			for (int x = e->x1; x <= e->x2; ++x) {
				const float dif = *(si++);
				readMap->AddHeight(y * mapDims.mapxp1 + x, dif);
			}
		}

		for (ExploBuilding& b: e->buildings) {
			for (int z = b.tz1; z < b.tz2; z++) {
				for (int x = b.tx1; x < b.tx2; x++) {
					readMap->AddHeight(z * mapDims.mapxp1 + x, b.dif);
				}
			}

			CUnit* unit = unitHandler->GetUnit(b.id);
			if (unit != NULL) {
				unit->Move(UpVector * b.dif, true);
			}
		}

		if (e->ttl == 0) {
			RecalcArea(e->x1 - 1, e->x2 + 1, e->y1 - 1, e->y2 + 1);
		}
	}

	while (!explosions.empty() && explosions.front()->ttl == 0) {
		delete explosions.front();
		explosions.pop_front();
	}

	UpdateLos();
}
void CMapDamage::Update(void)
{
START_TIME_PROFILE;

	std::deque<Explo*>::iterator ei;

	for(ei=explosions.begin();ei!=explosions.end();++ei){
		Explo* e=*ei;
		--e->ttl;

		int x1=e->x1;
		int x2=e->x2;
		int y1=e->y1;
		int y2=e->y2;
		std::vector<float>::iterator si=e->squares.begin();
		for(int y=y1;y<=y2;++y){
			for(int x=x1;x<=x2;++x){
				float dif=*(si++);
				readmap->heightmap[y*(gs->mapx+1)+x]+=dif;
			}
		}
		for(std::vector<ExploBuilding>::iterator bi=e->buildings.begin();bi!=e->buildings.end();++bi){
			float dif=bi->dif;
			int tx1 = bi->tx1;
			int tx2 = bi->tx2;
			int tz1 = bi->tz1;
			int tz2 = bi->tz2;

			for(int z=tz1; z<tz2; z++){
				for(int x=tx1; x<tx2; x++){
					readmap->heightmap[z*(gs->mapx+1)+x]+=dif;
				}
			}
			CUnit* unit=uh->units[bi->id];
			if(unit){
				unit->pos.y+=dif;
				unit->midPos.y+=dif;
			}
		}
		readmap->ExplosionUpdate(e->x1,e->x2,e->y1,e->y2);
		if(e->ttl==0){
			float3 pos=e->pos;
			float strength=e->strength;
			float ds=2.5*sqrt(strength);
			float dd=strength/ds*8;
			RecalcArea(x1-2,x2+2,y1-2,y2+2);
	/*		for(int y=y1>>3;y<=y2>>3;++y){
				for(int x=x1>>3;x<=x2>>3;++x){
					if(!inRejuvQue[y][x]){
						RejuvSquare rs;
						rs.x=x;
						rs.y=y;
						rejuvQue.push_back(rs);
						inRejuvQue[y][x]=true;
					}
				}
			}*/
		}
	}
	while(!explosions.empty() && explosions.front()->ttl==0){
		delete explosions.front();
		explosions.pop_front();
	}
/*
	nextRejuv+=rejuvQue.size()/300.0;
	while(nextRejuv>0){
		nextRejuv-=1;
		int bx=rejuvQue.front().x;
		int by=rejuvQue.front().y;
		bool damaged=false;

		for(int y=by*16;y<by*16+16;++y){
			for(int x=bx*16;x<bx*16+16;++x){
				if(readmap->damagemap[y*1024+x]!=0){
					damaged=true;
					if(readmap->damagemap[y*1024+x]>5){
						int hsquare=((y+1)/2)*(gs->mapx+1)+(x+1)/2;
						readmap->heightmap[hsquare]-=(readmap->heightmap[hsquare]-readmap->orgheightmap[hsquare])*0.003;
						readmap->damagemap[y*1024+x]-=4;
					} else {
						readmap->damagemap[y*1024+x]=0;
						if(readmap->typemap[(y/2)*512+x/2]&128){
							readmap->typemap[(y/2)*512+x/2]&=127;
							treeDrawer->ResetPos(float3(x*4,0,y*4));
						}
					}
				}
			}
		}
		if(damaged){
			rejuvQue.push_back(rejuvQue.front());
			RecalcArea(bx*8,bx*8+8,by*8,by*8+8);
			readmap->RecalcTexture(bx*8,bx*8+8,by*8,by*8+8);
		} else {
			inRejuvQue[by][bx]=false;
		}
		rejuvQue.pop_front();
	}*/
	UpdateLos();
END_TIME_PROFILE("Map damage");
}