Пример #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();
}
Пример #2
0
//------------------------------------------------------------------------
// 
// [2011/1/14 jjuiddong]
//------------------------------------------------------------------------
void CEvosGame::MouseEvent( int windowEvent, POINT pos)
{
	switch (windowEvent)
	{
	case WM_RBUTTONDOWN:
		{
			CUnit *punit = m_pUnitControl->GetUnit(0);
			if (punit)
			{
				punit->Move(Vector2D(pos.x, pos.y));
			}
		}
		break;
	}

}
Пример #3
0
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();
}
Пример #4
0
bool CHoverAirMoveType::HandleCollisions(bool checkCollisions)
{
	const float3& pos = owner->pos;

	if (pos != oldPos) {
		oldPos = pos;

		bool hitBuilding = false;

		// check for collisions if not on a pad, not being built, or not taking off
		// includes an extra condition for transports, which are exempt while loading
		if (!forceHeading && checkCollisions) {
			const vector<CUnit*>& nearUnits = quadField->GetUnitsExact(pos, owner->radius + 6);

			for (vector<CUnit*>::const_iterator ui = nearUnits.begin(); ui != nearUnits.end(); ++ui) {
				CUnit* unit = *ui;

				if (unit->transporter != NULL)
					continue;

				const float sqDist = (pos - unit->pos).SqLength();
				const float totRad = owner->radius + unit->radius;

				if (sqDist <= 0.1f || sqDist >= (totRad * totRad))
					continue;

				const float dist = math::sqrt(sqDist);
				const float3 dif = (pos - unit->pos).Normalize();

				if (unit->mass >= CSolidObject::DEFAULT_MASS || unit->immobile) {
					owner->Move(-dif * (dist - totRad), true);
					owner->SetVelocity(owner->speed * 0.99f);

					hitBuilding = true;
				} else {
					const float part = owner->mass / (owner->mass + unit->mass);
					const float colSpeed = -owner->speed.dot(dif) + unit->speed.dot(dif);

					owner->Move(-dif * (dist - totRad) * (1.0f - part), true);
					owner->SetVelocity(owner->speed + (dif * colSpeed * (1.0f - part)));

					if (!unit->UsingScriptMoveType()) {
						unit->SetVelocityAndSpeed(unit->speed - (dif * colSpeed * (part)));
						unit->Move(dif * (dist - totRad) * (part), true);
					}
				}
			}

			// update speed.w
			owner->SetSpeed(owner->speed);
		}

		if (hitBuilding && owner->IsCrashing()) {
			owner->KillUnit(NULL, true, false);
			return true;
		}

		if (pos.x < 0.0f) {
			owner->Move( RgtVector * 0.6f, true);
		} else if (pos.x > float3::maxxpos) {
			owner->Move(-RgtVector * 0.6f, true);
		}

		if (pos.z < 0.0f) {
			owner->Move( FwdVector * 0.6f, true);
		} else if (pos.z > float3::maxzpos) {
			owner->Move(-FwdVector * 0.6f, true);
		}

		return true;
	}

	return false;
}