示例#1
0
P2 S2weaveCell::GetBoundPoint(int ibl)  
{
	bool binV = ((boundlist[ibl].first & 1) == 0); 
	double wb = boundlist[ibl].second->w; 
	double wp = GetSide(boundlist[ibl].first)->wp; 
	return (binV ? P2(wp, wb) : P2(wb, wp)); 
}
示例#2
0
Shmem::SharedMemory*
IToplevelProtocol::CreateSharedMemory(size_t aSize,
                                      Shmem::SharedMemory::SharedMemoryType aType,
                                      bool aUnsafe,
                                      Shmem::id_t* aId)
{
  RefPtr<Shmem::SharedMemory> segment(
    Shmem::Alloc(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), aSize, aType, aUnsafe));
  if (!segment) {
    return nullptr;
  }
  int32_t id = GetSide() == ParentSide ? ++mLastShmemId : --mLastShmemId;
  Shmem shmem(
    Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(),
    segment.get(),
    id);
  Message* descriptor = shmem.ShareTo(
    Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead(), OtherPid(), MSG_ROUTING_CONTROL);
  if (!descriptor) {
    return nullptr;
  }
  Unused << GetIPCChannel()->Send(descriptor);

  *aId = shmem.Id(Shmem::IHadBetterBeIPDLCodeCallingThis_OtherwiseIAmADoodyhead());
  Shmem::SharedMemory* rawSegment = segment.get();
  mShmemMap.AddWithID(segment.forget().take(), *aId);
  return rawSegment;
}
void    CprojectileIGC::Update(Time now)
{
    if (GetMyLastUpdate() >= m_timeExpire)
        Terminate();
    else
    {
        if (now >= m_timeExpire)
        {
            float   p = m_projectileType->GetBlastPower();
            if (p != 0.0f)
            {
                m_pExplosionData = GetCluster()->CreateExplosion(m_projectileType->GetDamageType(),
                                                                 p * GetSide()->GetGlobalAttributeSet().GetAttribute(c_gaDamageGuns),
                                                                 m_projectileType->GetBlastRadius(),
                                                                 c_etProjectile,
                                                                 m_timeExpire,
                                                                 GetPosition() +
                                                                 GetVelocity() * (m_timeExpire - GetMyLastUpdate()),
                                                                 m_launcher);
            }
        }

        TmodelIGC<IprojectileIGC>::Update(now);
    }
}
示例#4
0
int                 CmineIGC::Export(void*    data) const
{
    int size = sizeof(DataMineExport);

    if (data)
    {
        DataMineExport* pdme = (DataMineExport*)data;

        pdme->p0 = GetPosition();
        pdme->time0 = m_time0;

        pdme->mineID = GetObjectID();
        pdme->exportF = true;

        pdme->clusterID = GetCluster()->GetObjectID();
        pdme->minetypeID = m_mineType->GetObjectID();

        pdme->launcherID = m_launcher ? m_launcher->GetObjectID() : NA;

        pdme->sideID = GetSide()->GetObjectID();

        pdme->fraction = m_fraction;

        pdme->createNow = m_bCreateNow;
    }

    return size;
}
示例#5
0
/*
============
idMapBrush::Write
============
*/
bool idMapBrush::Write( idFile *fp, int primitiveNum, const idVec3 &origin ) const {
	int i;
	idMapBrushSide *side;

	fp->WriteFloatString( "// primitive %d\n{\n brushDef3\n {\n", primitiveNum );

	// write brush epairs
	for ( i = 0; i < epairs.GetNumKeyVals(); i++) {
		fp->WriteFloatString( "  \"%s\" \"%s\"\n", epairs.GetKeyVal(i)->GetKey().c_str(), epairs.GetKeyVal(i)->GetValue().c_str());
	}

	// write brush sides
	for ( i = 0; i < GetNumSides(); i++ ) {
		side = GetSide( i );
		fp->WriteFloatString( "  ( %f %f %f %f ) ", side->plane[0], side->plane[1], side->plane[2], side->plane[3] );
		fp->WriteFloatString( "( ( %f %f %f ) ( %f %f %f ) ) \"%s\" 0 0 0\n",
							side->texMat[0][0], side->texMat[0][1], side->texMat[0][2],
								side->texMat[1][0], side->texMat[1][1], side->texMat[1][2],
									side->material.c_str() );
	}

	fp->WriteFloatString( " }\n}\n" );

	return true;
}
int                 CprobeIGC::Export(void*    data) const
{
    if (data)
    {
        DataProbeExport* pdme = (DataProbeExport*)data;

        pdme->p0 = GetPosition();
        pdme->time0 = m_time0;

        pdme->probeID = GetObjectID();
        pdme->exportF = true;

        pdme->clusterID = GetCluster()->GetObjectID();
        pdme->probetypeID = m_probeType->GetObjectID();

        pdme->sideID = GetSide()->GetObjectID();
        pdme->shipID = m_launcher ? m_launcher->GetObjectID() : NA;

        if (m_target)
        {
            pdme->otTarget = m_target->GetObjectType();
            pdme->oidTarget = m_target->GetObjectID();
        }
        else
        {
            pdme->otTarget = NA;
            pdme->oidTarget = NA;
        }

        pdme->createNow = m_bCreateNow;
    }

    return sizeof(DataProbeExport);
}
示例#7
0
void Camera::RotatePitch(float num)
{
	Quaternion rotation(GetSide(), num/30);
	Quaternion Conjugate = rotation.conjugate();
	Quaternion result =  (rotation.mult(Direction)).mult(Conjugate);
	Quaternion result_2 = (rotation.mult(Up)).mult(Conjugate);

	SetDirection(Vec3(result.getX(), result.getY(), result.getZ()));
	UpdateRotation();
}
示例#8
0
bool
IToplevelProtocol::TakeMinidump(nsIFile** aDump, uint32_t* aSequence)
{
  MOZ_RELEASE_ASSERT(GetSide() == ParentSide);
#ifdef MOZ_CRASHREPORTER
  return XRE_TakeMinidumpForChild(OtherPid(), aDump, aSequence);
#else
  return false;
#endif
}
/************************************************************************************************
 * CRMRandomInstance::Spawn
 *	Spawns the instance onto the landscape
 *
 * inputs:
 *  landscape: landscape object this instance will be spawned on
 *
 * return:
 *	true: spawn successful
 *  false: spawn failed
 *
 ************************************************************************************************/
bool CRMRandomInstance::Spawn ( CRandomTerrain* terrain, qboolean IsServer )
{
	mInstance->SetObjective(GetObjective());
	mInstance->SetSide(GetSide());

	if ( !mInstance->Spawn ( terrain, IsServer ) )
	{
		return false;
	}

	return true;
}
void CFSShip::ShipStatusSpotted(IsideIGC* pside)
{
    SideID  sideID = pside->GetObjectID();

    SectorID    sectorID;
    {
        IclusterIGC*    pcluster = GetIGCShip()->GetCluster();
        if (pcluster == NULL)
        {
            IstationIGC*    pstation = GetIGCShip()->GetStation();
            assert (pstation);
            pcluster = pstation->GetCluster();
        }

        sectorID = pcluster->GetObjectID();
    }

    ShipStatus* pss = &m_rgShipStatus[sideID];
	pss->SetStateTime(g.timeNow.clock());
    pss->SetState(c_ssFlying);
    pss->SetParentID(NA);
    pss->SetHullID(GetIGCShip()->GetHullType()->GetObjectID());
    pss->SetSectorID(sectorID);

    //Flag that we have been detected as well
    IsideIGC*   mySide = GetSide();
    SideID  mySideID = mySide->GetObjectID();
	if (mySide != pside && !mySide->AlliedSides(mySide, pside)) //#ALLY -was: mySide != pside (Imago fixed 7/8/09)
        m_rgShipStatus[mySideID].SetDetected(true);

    //Adjust the ship status for all of the children as well
    {
        for (ShipLinkIGC*   psl = GetIGCShip()->GetChildShips()->first();
             (psl != NULL);
             psl = psl->next())
        {
            IshipIGC*   pship = psl->data();
            CFSShip*    pfsship = ((CFSShip*)(pship->GetPrivateData()));
            ShipStatus* pss = pfsship->GetShipStatus(sideID);

            pss->SetState((pship->GetTurretID() == NA) ? c_ssObserver : c_ssTurret); 
            pss->SetHullID(NA);
            pss->SetSectorID(sectorID);
            pss->SetParentID(GetShipID());

			if (mySide != pside && !mySide->AlliedSides(mySide, pside)) //#ALLY -was != (Imago fixed 7/8/09)
                pfsship->GetShipStatus(mySideID)->SetDetected(true);
        }
    }
}
void          CFSShip::ShipStatusHidden(IsideIGC* pside)
{
    SideID  sideID = pside->GetObjectID();
    m_rgShipStatus[sideID].SetUnknown();

    IsideIGC*   mySide = GetSide();
    SideID      mySideID = mySide->GetObjectID();

    //Does anyone see us?
    bool    detectedF = false;
    {
        CFSMission* pmission = this->GetMission();
        if (pmission)  
        {
            for (SideLinkIGC*   psl = pmission->GetIGCMission()->GetSides()->first();
                 (psl != NULL);
                 psl = psl->next())
            {
				if (psl->data() != mySide && !mySide->AlliedSides(psl->data(), mySide)) //#ALLY -was: != (Imago fixed 7/8/09)
                {
                    ShipStatus* pss = GetShipStatus(psl->data()->GetObjectID());
                    if (!pss->GetUnknown())
                    {
                        detectedF = true;
                        break;
                    }
                }
            }
        }
    }

    m_rgShipStatus[mySideID].SetDetected(detectedF);

    //Adjust the ship status for all of the children as well
    {
        for (ShipLinkIGC*   psl = GetIGCShip()->GetChildShips()->first();
             (psl != NULL);
             psl = psl->next())
        {
            IshipIGC*   pship = psl->data();
            CFSShip*    pfsShip = ((CFSShip*)(pship->GetPrivateData()));
            ShipStatus* pss = pfsShip->GetShipStatus(sideID);

            pss->SetUnknown();

            pfsShip->GetShipStatus(mySideID)->SetDetected(detectedF);
        }
    }
}
示例#12
0
/*
===============
idMapBrush::GetGeometryCRC
===============
*/
unsigned int idMapBrush::GetGeometryCRC( void ) const {
	int i, j;
	idMapBrushSide *mapSide;
	unsigned int crc;

	crc = 0;
	for ( i = 0; i < GetNumSides(); i++ ) {
		mapSide = GetSide(i);
		for ( j = 0; j < 4; j++ ) {
			crc ^= FloatCRC( mapSide->GetPlane()[j] );
		}
		crc ^= StringCRC( mapSide->GetMaterial() );
	}

	return crc;
}
示例#13
0
/************************************************************************************************
 * CRMGroupInstance::Spawn
 *	Adds the group instance to the given landscape using the specified origin.  All sub instances
 *  will be added to the landscape within their min and max range from the origin.
 *
 * inputs:
 *  landscape: landscape to add the instance group to
 *  origin: origin of the instance group
 *
 * return:
 *	none
 *
 ************************************************************************************************/
bool CRMGroupInstance::Spawn ( CRandomTerrain* terrain, qboolean IsServer )
{
	rmInstanceIter_t it;

	// Spawn all the instances associated with this group
	for(it = mInstances.begin(); it != mInstances.end(); ++it)
	{
		CRMInstance* instance = *it;
		instance->SetSide(GetSide()); // which side owns it?

		// Add the instance to the landscape now
		instance->Spawn ( terrain, IsServer );
	}

	DrawAutomapSymbol();

	return true;
}
示例#14
0
void CRMInstance::DrawAutomapSymbol()
{
	TheRandomMissionManager->AddAutomapSymbol ( GetAutomapSymbol(), GetOrigin(), GetSide ( ) );
/*
	// draw proper symbol on map for instance
	switch (GetAutomapSymbol())
	{
		default:
		case AUTOMAP_NONE:
			if (HasObjective())
				CM_TM_AddObjective(GetOrigin()[0], GetOrigin()[1], GetSide());
			break;
		case AUTOMAP_BLD:
			CM_TM_AddBuilding(GetOrigin()[0], GetOrigin()[1], GetSide());
			if (HasObjective())
				CM_TM_AddObjective(GetOrigin()[0], GetOrigin()[1], GetSide());
			break;
		case AUTOMAP_OBJ:
			CM_TM_AddObjective(GetOrigin()[0], GetOrigin()[1], GetSide());
			break;
		case AUTOMAP_START:
			CM_TM_AddStart(GetOrigin()[0], GetOrigin()[1], GetSide());
			break;
		case AUTOMAP_END:
			CM_TM_AddEnd(GetOrigin()[0], GetOrigin()[1], GetSide());
			break;
		case AUTOMAP_ENEMY:
			if (HasObjective())
				CM_TM_AddObjective(GetOrigin()[0], GetOrigin()[1]);
			if (1 == Cvar_VariableIntegerValue("rmg_automapshowall"))
				CM_TM_AddNPC(GetOrigin()[0], GetOrigin()[1], false);
			break;
		case AUTOMAP_FRIEND:
			if (HasObjective())
				CM_TM_AddObjective(GetOrigin()[0], GetOrigin()[1]);
			if (1 == Cvar_VariableIntegerValue("rmg_automapshowall"))
				CM_TM_AddNPC(GetOrigin()[0], GetOrigin()[1], true);
			break;
		case AUTOMAP_WALL:
			CM_TM_AddWallRect(GetOrigin()[0], GetOrigin()[1], GetSide());
			break;
	}
*/
}
示例#15
0
int S2weaveCell::GetBoundListPosition(int sic, const P2& ptb, bool bOnBoundOutside)  
{
	if (boundlist.empty()) 
		return -1; 
	int res = 0; 
	bool bgoingup = ((sic & 2) == 0); 
	bool binV = ((sic & 1) == 0); 

	double wb = (binV ? ptb.v : ptb.u); 
	ASSERT(GetSide(sic)->wp == (binV ? ptb.u : ptb.v)); 

	for ( ; res < (int)(boundlist.size()); res++) 
	{
		if (boundlist[res].first == sic)
		{
			// handle the coincident cases with warning and properly 
			if (boundlist[res].second->w == wb) 
			{
				ASSERT(bOnBoundOutside); 
				if (!GetBoundLower(res)) 
				{
					res++; 
					if (res == (int)boundlist.size()) 
						res = 0; 
				}
				else
					ASSERT(1); // rare case of doubling back from a corner through the previous cell, which we must see.  
				return res; 
			}
			if (bgoingup ? (boundlist[res].second->w >= wb) : (boundlist[res].second->w <= wb))  
			{
				ASSERT(!bOnBoundOutside); 
				return res; 
			}
		}
		else if (boundlist[res].first > sic)
			break; 
	}
	if (res == (int)boundlist.size()) 
		res = 0; 
	ASSERT(!bOnBoundOutside); 
	return res; 
}
示例#16
0
AttackInfo BattleSquad::getAttackRolls(bool rangedattack,bool asdefender, int d)
{
	DataLibrary *datalib = DataLibrary::getSingletonPtr();
	AttackInfo attackinfo;
	int soildernum = getUnitNum();
	int atktime =  floor((-0.010907f) * soildernum * soildernum  + 1.37256f * soildernum+ 8.638347f + 0.5f);
	if(asdefender)
	{
		attackinfo.AtkTime = atktime * getAttr(ATTR_CONTER,ATTRCALC_FULL) / 10.0f;
	}
	else
	{
		attackinfo.AtkTime = atktime;
	}

	float atkf;
	if(rangedattack)
	{
		atkf = getAttr(ATTR_RANGEDATTACK, ATTRCALC_FULL);
	}
	else
	{
		atkf = getAttr(ATTR_ATTACK, ATTRCALC_FULL);
		float formation;
		formation = getAttr(ATTR_FORM, ATTRCALC_FULL);
		formation = (formation < 0.0f)?0.0f:formation;
		formation = formation * soildernum / 50.0f;
		int formtype = getFormation();
		int mydir = getDirection();
		int side = GetSide(mydir,d);
		formation *= GetFormationBonus(side, formtype);
		atkf += formation;
	}
	attackinfo.Atk = atkf;

	std::string soilderid = getSoilderId();
	float randomness;
	datalib->getData(std::string("StaticData/SoilderData/") + soilderid + std::string("/Randomness"),randomness);
	attackinfo.Randomness = randomness;

	return attackinfo;
}
示例#17
0
int32_t
IToplevelProtocol::Register(IProtocol* aRouted)
{
  if (aRouted->Id() != kNullActorId && aRouted->Id() != kFreedActorId) {
    // If there's already an ID, just return that.
    return aRouted->Id();
  }
  int32_t id = GetSide() == ParentSide ? ++mLastRouteId : --mLastRouteId;
  mActorMap.AddWithID(aRouted, id);
  aRouted->SetId(id);

  // Inherit our event target from our manager.
  if (IProtocol* manager = aRouted->Manager()) {
    MutexAutoLock lock(mEventTargetMutex);
    if (nsCOMPtr<nsIEventTarget> target = mEventTargetMap.Lookup(manager->Id())) {
      mEventTargetMap.AddWithID(target, id);
    }
  }

  return id;
}
示例#18
0
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void OverlayTransition_UpdateSideLists( void )
{
	int nOverlayCount = g_aMapWaterOverlays.Count();
	for( int iOverlay = 0; iOverlay < nOverlayCount; ++iOverlay )
	{
		mapoverlay_t *pOverlay = &g_aMapWaterOverlays.Element( iOverlay );
		if ( pOverlay )
		{
			int nSideCount = pOverlay->aSideList.Count();
			for( int iSide = 0; iSide < nSideCount; ++iSide )
			{
				side_t *pSide = GetSide( pOverlay->aSideList[iSide] );
				if ( pSide )
				{
					if ( pSide->aWaterOverlayIds.Find( pOverlay->nId ) == -1 )
					{
						pSide->aWaterOverlayIds.AddToTail( pOverlay->nId );
					}
				}
			}
		}
	}
}
示例#19
0
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void Overlay_UpdateSideLists( void )
{
	int nMapOverlayCount = g_aMapOverlays.Count();
	for( int iMapOverlay = 0; iMapOverlay < nMapOverlayCount; ++iMapOverlay )
	{
		mapoverlay_t *pMapOverlay = &g_aMapOverlays.Element( iMapOverlay );
		if ( pMapOverlay )
		{
			int nSideCount = pMapOverlay->aSideList.Count();
			for( int iSide = 0; iSide < nSideCount; ++iSide )
			{
				side_t *pSide = GetSide( pMapOverlay->aSideList[iSide] );
				if ( pSide )
				{
					if ( pSide->aOverlayIds.Find( pMapOverlay->nId ) == -1 )
					{
						pSide->aOverlayIds.AddToTail( pMapOverlay->nId );
					}
				}
			}
		}
	}
}
示例#20
0
void MinerGob::Mine(WCoord wx, WCoord wy)
{
	Assert(!InTransition());

//temp
if (!(m_ff & kfGobActive)) {
    Assert();
}

	// If we aren't being told to where to mine and we don't already
	// have a previous mining location then find a new place to mine.

	if (wx == kwxInvalid) {
		if (m_tptGalaxite.tx == kxInvalid) {
			SetState(kstMinerFindGalaxite);
		} else {

			// Go to Galaxite closest to the previous location

			FogMap *pfogm = gsim.GetLevel()->GetFogMap();
			if (pfogm->FindNearestGalaxite(m_tptGalaxite.tx, m_tptGalaxite.ty, 
					&m_tptGalaxite, (m_pplr->GetFlags() & kfPlrComputer) != 0 || ggame.IsMultiplayer())) {
				m_wptTarget.wx = WcFromTc(m_tptGalaxite.tx);
				m_wptTarget.wy = WcFromTc(m_tptGalaxite.ty);
				SetState(kstMinerApproachGalaxite);
			} else {
				// If no Galaxite found, just stay where we are (NOTE:
				// where we are is in the way of any other Miners trying
				// to use the same Processor!)

				gsim.GetLevel()->GetTriggerMgr()->SetConditionTrue(knMinerCantFindGalaxiteCondition, GetSideMask(GetSide()));
				if (m_pplr == gpplrLocal)
					ShowAlert(kidsMinerNeedsGalaxite);
				SetState(kstGuard);
			}
		}
	} else {
		// Stash mine parameters to be picked up by the Mine state

		m_wptTarget.wx = wx;
		m_wptTarget.wy = wy;
		m_tptGalaxite.tx = TcFromWc(m_wptTarget.wx);
		m_tptGalaxite.ty = TcFromWc(m_wptTarget.wy);
		SetState(kstMinerApproachGalaxite);
	}
}
示例#21
0
// operates in terms of GetScore() (which is recursive for factories)
const UnitDef* CUnitTable::GetUnitByScore(int builderUnitID, int category) {
	if (category == LASTCATEGORY)
		return 0x0;

	vector<int>* tempList = 0;
	const UnitDef* builderDef = ai->cb->GetUnitDef(builderUnitID);
	const UnitDef* tempUnitDef = 0;
	int side = GetSide(builderUnitID);
	float tempScore = 0.0f;
	float bestScore = 0.0f;

	switch (category) {
		case CAT_ENERGY:
			tempList = ground_energy;
			break;
		case CAT_MEX:
			tempList = metal_extractors;
			break;
		case CAT_MMAKER:
			tempList = metal_makers;
			break;
		case CAT_G_ATTACK:
			tempList = ground_attackers;
			break;
		case CAT_DEFENCE:
			tempList = ground_defences;
			break;
		case CAT_BUILDER:
			tempList = ground_builders;
			break;
		case CAT_FACTORY:
			tempList = ground_factories;
			break;
		case CAT_MSTOR:
			tempList = metal_storages;
			break;
		case CAT_ESTOR:
			tempList = energy_storages;
			break;
		case CAT_NUKE:
			tempList = nuke_silos;
			break;
	}

	// if we are a builder on side i, then templist must have
	// at least i + 1 elements (templist[0], ..., templist[i])
	// but if a mod is not symmetric (eg. no builders for side
	// 1) this assumption fails; enabling this breaks PURE 0.6
	// however
	//
	// if (tempList->size() >= side + 1) {
		// iterate over all units for <side> in tempList (eg. Core ground_defences)
		for (unsigned int i = 0; i != tempList[side].size(); i++) {
			int tempUnitDefID = tempList[side][i];

			// if our builder can build the i-th unit
			if (CanBuildUnit(builderDef->id, tempUnitDefID)) {
				// get the unit's heuristic score (based on current income)
				tempScore = GetScore(unitTypes[tempUnitDefID].def, category);

				if (tempScore > bestScore) {
					bestScore = tempScore;
					tempUnitDef = unitTypes[tempUnitDefID].def;
				}
			}
		}
	// }

	// if we didn't find a unit to build with score > 0 (ie.
	// if builder has no build-option matching this category)
	// then return NULL instead of first option on build menu
	// (to prevent radar farms and other bizarro side-effects)
	return ((bestScore > 0.0f)? tempUnitDef: NULL);
}
示例#22
0
/*
============
idBrush::TryMerge
============
*/
bool idBrush::TryMerge( const idBrush* brush, const idPlaneSet& planeList )
{
	int i, j, k, l, m, seperatingPlane;
	const idBrush* brushes[2];
	const idWinding* w;
	const idPlane* plane;
	
	// brush bounds should overlap
	for( i = 0; i < 3; i++ )
	{
		if( bounds[0][i] > brush->bounds[1][i] + 0.1f )
		{
			return false;
		}
		if( bounds[1][i] < brush->bounds[0][i] - 0.1f )
		{
			return false;
		}
	}
	
	// the brushes should share an opposite plane
	seperatingPlane = -1;
	for( i = 0; i < GetNumSides(); i++ )
	{
		for( j = 0; j < brush->GetNumSides(); j++ )
		{
			if( GetSide( i )->GetPlaneNum() == ( brush->GetSide( j )->GetPlaneNum() ^ 1 ) )
			{
				// may only have one seperating plane
				if( seperatingPlane != -1 )
				{
					return false;
				}
				seperatingPlane = GetSide( i )->GetPlaneNum();
				break;
			}
		}
	}
	if( seperatingPlane == -1 )
	{
		return false;
	}
	
	brushes[0] = this;
	brushes[1] = brush;
	
	for( i = 0; i < 2; i++ )
	{
	
		j = !i;
		
		for( k = 0; k < brushes[i]->GetNumSides(); k++ )
		{
		
			// if the brush side plane is the seprating plane
			if( !( ( brushes[i]->GetSide( k )->GetPlaneNum() ^ seperatingPlane ) >> 1 ) )
			{
				continue;
			}
			
			plane = &brushes[i]->GetSide( k )->GetPlane();
			
			// all the non seperating brush sides of the other brush should be at the back or on the plane
			for( l = 0; l < brushes[j]->GetNumSides(); l++ )
			{
			
				w = brushes[j]->GetSide( l )->GetWinding();
				if( !w )
				{
					continue;
				}
				
				if( !( ( brushes[j]->GetSide( l )->GetPlaneNum() ^ seperatingPlane ) >> 1 ) )
				{
					continue;
				}
				
				for( m = 0; m < w->GetNumPoints(); m++ )
				{
					if( plane->Distance( ( *w )[m].ToVec3() ) > 0.1f )
					{
						return false;
					}
				}
			}
		}
	}
	
	// add any sides from the other brush to this brush
	for( i = 0; i < brush->GetNumSides(); i++ )
	{
		for( j = 0; j < GetNumSides(); j++ )
		{
			if( !( ( brush->GetSide( i )->GetPlaneNum() ^ GetSide( j )->GetPlaneNum() ) >> 1 ) )
			{
				break;
			}
		}
		if( j < GetNumSides() )
		{
			sides[j]->flags &= brush->GetSide( i )->GetFlags();
			continue;
		}
		sides.Append( brush->GetSide( i )->Copy() );
	}
	
	// remove any side from this brush that is the opposite of a side of the other brush
	for( i = 0; i < GetNumSides(); i++ )
	{
		for( j = 0; j < brush->GetNumSides(); j++ )
		{
			if( GetSide( i )->GetPlaneNum() == ( brush->GetSide( j )->GetPlaneNum() ^ 1 ) )
			{
				break;
			}
		}
		if( j < brush->GetNumSides() )
		{
			delete sides[i];
			sides.RemoveIndex( i );
			i--;
			continue;
		}
	}
	
	contents |= brush->contents;
	
	CreateWindings();
	BoundBrush();
	
	return true;
}
示例#23
0
HRESULT CmineIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize)
{
    ZRetailAssert (data && (dataSize > sizeof(DataMineBase)));
    {
        DataMineBase*  dataMineBase = (DataMineBase*)data;

        if ((dataMineBase->exportF) && 
            ((DataMineExport*)dataMineBase)->createNow)
        {
            m_time0 = now;
        }
        else
        {
            m_time0 = pMission->GetIgcSite()->ClientTimeFromServerTime(dataMineBase->time0);
        }

        TmodelIGC<ImineIGC>::Initialize(pMission, now, data, dataSize);

        IshipIGC*         pshipLauncher;
        IclusterIGC*      pcluster;
        DataMineTypeIGC*  dataMineType;
        if (dataMineBase->exportF)
        {
            assert (dataSize >= sizeof(DataMineExport));

            DataMineExport* dataMineExport = (DataMineExport*)dataMineBase;

            m_mineType = (ImineTypeIGC*)(pMission->GetExpendableType(dataMineExport->minetypeID));
            assert (m_mineType);
            assert (m_mineType->GetObjectType() == OT_mineType);

            pcluster = pMission->GetCluster(dataMineExport->clusterID);

            assert (m_mineType);
            dataMineType = (DataMineTypeIGC*)(m_mineType->GetData());

            pshipLauncher = pMission->GetShip(dataMineExport->launcherID);
            SetSide(pMission->GetSide(dataMineExport->sideID));

            m_fraction = dataMineExport->fraction;
        }
        else
        {
            assert (dataSize == sizeof(DataMineIGC));

            DataMineIGC*    dataMine = (DataMineIGC*)dataMineBase;

            m_mineType = dataMine->pminetype;
            pcluster = dataMine->pcluster;

            assert (m_mineType);
            assert (m_mineType->GetObjectType() == OT_mineType);
            dataMineType = (DataMineTypeIGC*)(m_mineType->GetData());

            pshipLauncher = dataMine->pshipLauncher;
            SetSide(dataMine->psideLauncher);

            m_fraction = 1.0f;
        }

        if (pshipLauncher && (dataMineType->launcherDef.price == 0))
        {
            m_launcher = pshipLauncher;
            m_launcher->AddRef();
        }

        assert (GetSide());
        assert (pcluster);

        m_mineType->AddRef();

        //Load the model for the mine
        LoadMine(dataMineType->textureName, 1.0f, dataMineType->radius, dataMineType->iconName,
                 c_mtSeenBySide | c_mtPredictable | c_mtHitable | c_mtStatic);

        SetRadius(dataMineType->radius);
        SetSignature(dataMineType->signature);
        SetSecondaryName(dataMineType->launcherDef.name);

        {
            //lifespan == 0 => immortal mine that can hit until it gets terminated on the next update; this is bad
            assert (dataMineType->lifespan > 0.0f);
            m_timeExpire = m_time0 + dataMineType->lifespan;
            assert (m_timeExpire != m_time0);
        }
        SetMass(0.0f);

        m_mineID = dataMineBase->mineID;

        SetPosition(dataMineBase->p0);
        SetCluster(pcluster);

        pMission->AddMine(this);
    }

    return S_OK;
}
HRESULT CprobeIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize)
{
    assert (pMission);
    m_pMission = pMission;

    ZRetailAssert (data && (dataSize > sizeof(DataProbeBase)));
    {
        DataProbeBase*  dataProbeBase = (DataProbeBase*)data;

        if ((dataProbeBase->exportF) && 
            ((DataProbeExport*)dataProbeBase)->createNow)
        {
            m_time0 = now;
        }
        else
        {
            m_time0 = pMission->GetIgcSite()->ClientTimeFromServerTime(dataProbeBase->time0);
        }
        TmodelIGC<IprobeIGC>::Initialize(pMission, now, data, dataSize);

        IshipIGC*       pshipLauncher;
        IsideIGC*       pside;
        IclusterIGC*    pcluster;
        if (dataProbeBase->exportF)
        {
            assert (dataSize == sizeof(DataProbeExport));

            DataProbeExport* dataProbeExport = (DataProbeExport*)dataProbeBase;

            m_probeType = (IprobeTypeIGC*)(pMission->GetExpendableType(dataProbeExport->probetypeID));
            pside = pMission->GetSide(dataProbeExport->sideID);
            pcluster = pMission->GetCluster(dataProbeExport->clusterID);

            pshipLauncher = pside->GetShip(dataProbeExport->shipID);

            if (m_probeType->HasCapability(c_eabmShootOnlyTarget))
                m_target = pMission->GetModel(dataProbeExport->otTarget, dataProbeExport->oidTarget);
        }
        else
        {
            assert (dataSize == sizeof(DataProbeIGC));

            DataProbeIGC*    dataProbe = (DataProbeIGC*)dataProbeBase;

            m_probeType = dataProbe->pprobetype;
            pside = dataProbe->pside;
            pcluster = dataProbe->pcluster;

            pshipLauncher = dataProbe->pship;

            if (m_probeType->HasCapability(c_eabmShootOnlyTarget))
                m_target = dataProbe->pmodelTarget;
        }

        assert (m_probeType);
        assert (m_probeType->GetObjectType() == OT_probeType);
        m_probeType->AddRef();

        m_ammo = m_probeType->GetAmmo();

        DataProbeTypeIGC*  dataProbeType = (DataProbeTypeIGC*)(m_probeType->GetData());
        m_projectileType = m_probeType->GetProjectileType();
        if (m_projectileType)
        {
            m_projectileType->AddRef();
            m_bSeenByAll = false;

            if (pshipLauncher && (dataProbeType->launcherDef.price == 0))
                m_launcher = pshipLauncher;
        }

        assert (pcluster);

        //Load the model for the probe
        assert (iswalpha(dataProbeType->modelName[0]));
        HRESULT hr = Load(0, dataProbeType->modelName,
                          dataProbeType->textureName,
                          dataProbeType->iconName, 
                          c_mtDamagable | c_mtHitable | c_mtStatic | c_mtSeenBySide | c_mtPredictable | c_mtScanner);
        assert (SUCCEEDED(hr));

        SetRadius(dataProbeType->radius);
        SetSignature(dataProbeType->signature);
        SetSide(pside);

        SetSecondaryName(dataProbeType->launcherDef.name);

        {
            //Parts get a random orientation
            Vector  v = Vector::RandomDirection();
            Orientation o(v);
            SetOrientation(o);
        }

        //lifespan == 0 => immortal probe that can hit until it gets terminated on the next update; this is bad
        assert (dataProbeType->lifespan > 0.0f);
        m_timeExpire = m_time0 + dataProbeType->lifespan;
        assert (m_timeExpire != m_time0);


        m_nextFire = m_time0 + (m_probeType->HasCapability(c_eabmQuickReady)
                                ? 5.0f        //5 second delay
                                : 30.0f);     //30 second delay before we start to shoot

        assert (GetSide());
        SetMass(0.0f);

        m_probeID = dataProbeBase->probeID;

        SetPosition(dataProbeBase->p0);
        SetCluster(pcluster);

        pMission->AddProbe(this);

        if ((dataProbeType->dtRipcord >= 0.0f) && ((GetMyLastUpdate() - m_time0) >= dataProbeType->dtRipcord))
        {
            pMission->GetIgcSite()->ActivateTeleportProbe(this);
        }
		// mmf 04/08 destroy any probe near aleph (warp) tip as this is viewed as an exploit as the enemy 
		//           often cannot delete it
		// 
		// if (experimental game type) mmf
		const MissionParams* pmp = pMission->GetMissionParams();

		if (pmp->bExperimental) {
			Vector dV, probeV, warpV, tipdistV;
			Vector bV, tipV;
			float warp_rad, distance;
			Orientation warp_orient;
			Rotation warp_rot;
			// loop through list of warps
            for (WarpLinkIGC*   pwl = pcluster->GetWarps()->first(); (pwl != NULL); pwl = pwl->next())
                {
					IwarpIGC*   pwarp = pwl->data();
					warp_rad = pwarp->GetRadius();
					warp_orient = pwarp->GetOrientation();
					warpV = pwarp->GetPosition();
					probeV = this->GetPosition();
					dV= warpV-probeV;
					distance = dV.Length();
					warp_rot = pwarp->GetRotation();

					// if rotating (i.e. rotation is other than 0 0 1 0) abort check
					if (!((warp_rot.x()==0) && (warp_rot.y()==0) && (warp_rot.z()==1) && (warp_rot.angle()==0)))
						break;
					if (distance < (warp_rad * 2) ) {  // only check if close to tip if reasonably close to warp center
						bV = warp_orient.GetBackward();
						tipV = warpV + (bV*warp_rad);
						tipdistV = tipV-probeV;
						distance = tipdistV.Length();
						if (distance < 30) {
							debugf("Destroying probe as it was dropped too close (within 30) of aleph(warp) tip. dist = $f\n",distance);
							return S_FALSE; // this will destroy the probe
						}
					}
				}
		}		
		// mmf end	

		// mmf added code to detect tp drop near asteroid and if too close destroy it
		//     leave ActivateTeleProbe code above so enemy is alerted to the drop even though it may be destroyed
		if (dataProbeType->dtRipcord >= 0.0f)  // check to see if this is a teleprobe
		{
			Vector dV;
			float asteroid_rad, distance;
			// loop through list of asteroids
            for (AsteroidLinkIGC*   pal = pcluster->GetAsteroids()->first(); (pal != NULL); pal = pal->next())
                {
                    asteroid_rad = (pal->data()->GetRadius());
                    dV=this->GetPosition() - pal->data()->GetPosition();
					distance = dV.Length();
					if (distance < (asteroid_rad-5)) {
						debugf("Teleprobe dropped too close to asteroid (within -5) destroying probe. dist = %f, asteroid rad = %f\n",
							distance,asteroid_rad);
						// this->Terminate(); should be terminated when missionigc processes S_FALSE
						return S_FALSE; 
					}
				}
		}		
		// mmf end	
	}

    return S_OK;
}
示例#25
0
void BattleSquad::applyAttackRolls(bool rangedattack, int d, AttackInfo &attackinfo)
{
	DataLibrary *datalib = DataLibrary::getSingletonPtr();

	int soildernum = getUnitNum();
	float deff;
	if(rangedattack)
	{
		deff = getAttr(ATTR_RANGEDDEFENCE, ATTRCALC_FULL);
		deff += RANGEDDEFENCEBONUS;
		float formation;
		formation = getAttr(ATTR_FORM, ATTRCALC_FULL);
		formation = (formation < 0.0f)?0.0f:formation;
		formation = formation * soildernum / 50.0f;
		switch(getFormation())
		{
		case Line:
			formation *= FORMBONSE_LINE_RANGED;
			break;
		case Circular:
			formation *= FORMBONSE_CIRC_RANGED;
			break;
		default:
			formation *= FORMBONSE_LOOS_RANGED;
			break;
		}
		deff -= formation;
	}
	else
	{
		deff = getAttr(ATTR_DEFENCE, ATTRCALC_FULL);
		float formation;
		formation = getAttr(ATTR_FORM, ATTRCALC_FULL);
		formation = (formation < 0.0f)?0.0f:formation;
		formation = formation * soildernum / 50.0f;
		int formtype = getFormation();
		int mydir = getDirection();
		int side = GetSide(mydir,d);
		formation *= GetFormationBonus(side, formtype);
		deff += formation;
	}
	int def = floor(deff + 0.5f);

	int atk = floor(attackinfo.Atk + 0.5f);
	float perc = AtkDefToPerc(atk,def);
	float killf = perc * attackinfo.AtkTime;
	killf += killf * (rand() % (attackinfo.Randomness * 2 + 1) - attackinfo.Randomness) / 100.0f;
	int kill = floor(killf + 0.5f);
	if(kill == 0)
	{
		if(rand() % 100 < attackinfo.Randomness)
			kill = 1;
	}
	if(kill > 9)
	{
		std::string eid;
		applyEffect("Waver", eid);
	}
	if(kill > 18)
	{
		std::string eid;
		applyEffect("Waver", eid);
	}

	soildernum -= kill;
	soildernum = (soildernum < 0)? 0: soildernum;
	setUnitNum(soildernum);

	if(getType() == SQUAD_NORMAL)
	{
		int maxnum = getUnitMaxNum();
		maxnum -= kill * (1.0f - getAttr(ATTR_TOUGHNESS, ATTRCALC_FULL) / 10.0f);
		setUnitMaxNum(maxnum);
	}
}
示例#26
0
 void SubmitVertex(glsl::vec3 const & pivot, glsl::vec2 const & normal, bool isLeft, float offsetFromStart)
 {
     float const halfWidth = GetHalfWidth();
     m_geometry.emplace_back(V(pivot, TNormal(halfWidth * normal, halfWidth * GetSide(isLeft)),
                               m_colorCoord, m_texCoordGen.GetTexCoordsByDistance(offsetFromStart)));
 }
示例#27
0
inline static bool IsOnSameSide(Position const* who, Position const* other)
{
    return (GetSide(who) == GetSide(other));
}
void                 CprojectileIGC::HandleCollision(Time       timeCollision,
                                                     float                  tCollision,
                                                     const CollisionEntry&  entry,
                                                     ImodelIGC* pModel)
{
    if (pModel->GetObjectType() == OT_mine)
    {
        //Ignore collisions with minefields
        return;
    }

	if (pModel->GetObjectType() == OT_asteroid && ((IasteroidIGC*)pModel)->IsDead(GetSide()->GetObjectID()))
		return;				//#358: Ignore collisions with dead asteroids

    //A projectile hit something other than a minefield
    bool    fExplosion;
    Vector position1 = GetPosition() + GetVelocity() * tCollision;
    Vector position2 = pModel->GetPosition() + pModel->GetVelocity()  * tCollision;

    DamageTypeID type = m_projectileType->GetDamageType();
    if (pModel->GetAttributes() & c_mtDamagable)
    {
        //The target can take damage
        IdamageIGC*   pDamage = (IdamageIGC*)pModel;

        pModel->AddRef();

        DamageResult dr = pDamage->ReceiveDamage(type,
                                                 m_projectileType->GetPower() * GetSide()->GetGlobalAttributeSet().GetAttribute(c_gaDamageGuns),
                                                 timeCollision,
                                                 position2,
                                                 position1,
                                                 m_launcher);

        //No explosion because no hull damage, not visible or we killed it.
        fExplosion = (dr <= c_drHullDamage) && pModel->GetVisibleF() && (pModel->GetCluster() != NULL);

        pModel->Release();
    }
    else
         fExplosion = false;

    if (m_pExplosionData)
    {
        //This projectile would have exploded anyway -- change the explosion position & time.
        m_pExplosionData->time = timeCollision;
        m_pExplosionData->position = position1;
    }
    else
    {
        float   p = m_projectileType->GetBlastPower();
        if (p != 0.0f)
        {
            //Area effect weapon: create an explosion (no matter what)
            GetCluster()->CreateExplosion(type,
                                          p,
                                          m_projectileType->GetBlastRadius(),
                                          c_etProjectile,
                                          timeCollision,
                                          position1,
                                          m_launcher);
        }
        else if (fExplosion && ((type & c_dmgidNoDebris) == 0))
        {
            Vector pos = position1 - position2;

            pModel->GetThingSite()->AddHullHit(pos,
                                               pos.Normalize());
        }
    }

    //In any case, kill the projectile
    Terminate();
}
void    CprobeIGC::Update(Time now)
{
    if (now >= m_timeExpire)	
        GetMyMission()->GetIgcSite()->KillProbeEvent(this);
    else
    {
        {
            float   dt = m_probeType->GetRipcordDelay();
            if (dt >= 0.0f)
            {
                Time    timeActivate = m_time0 + dt;
                if ((GetMyLastUpdate() < timeActivate) &&
                    (now >= timeActivate))
                {
                    GetMyMission()->GetIgcSite()->ActivateTeleportProbe(this);
                }
            }
        }

        if (m_projectileType)
        {
            if (m_nextFire < now)
            {
                IclusterIGC*    pcluster = GetCluster();
                assert (pcluster);

                //We'll be able to take a shot
                float   lifespan = GetProjectileLifespan();
                IsideIGC*   pside = GetSide();

                const Vector&       myPosition = GetPosition();

                float   speed = m_projectileType->GetSpeed();
                if (m_ammo != 0)
                    speed *= GetSide()->GetGlobalAttributeSet().GetAttribute(c_gaSpeedAmmo);

                float   accuracy = GetAccuracy();
                float   dtimeBurst = GetDtBurst();
                float   dispersion = m_probeType->GetDispersion();
                Time    lastUpdate = GetMyLastUpdate();
                if (m_nextFire < lastUpdate)
                    m_nextFire = lastUpdate;
                assert (m_nextFire <= now);

                TmodelIGC<IprobeIGC>::Update(now);

                float   dtUpdate = m_nextFire - lastUpdate;

                //If we have a target ... find the closest enemy ship who is a valid target
                ExpendableAbilityBitMask    eabm = m_probeType->GetCapabilities();
                float       distance2Min = speed * lifespan / 1.2f;
                distance2Min *= distance2Min;
                Vector      directionMin;



                ImodelIGC*  pmodelTarget = NULL;
                if (eabm & c_eabmShootOnlyTarget)
                {
                    if (m_target && (m_target->GetCluster() == pcluster))
                    {
                        ObjectType  type = m_target->GetObjectType();
                        ValidTarget((type == OT_ship) ? ((IshipIGC*)(ImodelIGC*)m_target)->GetSourceShip() : m_target,
                                    pside, myPosition, dtUpdate, accuracy, speed, lifespan, type,
                                    &pmodelTarget, &distance2Min, &directionMin);
                    }
                }
                else
                {
                    if (eabm & c_eabmShootShips)
                    {
                        //Threats to stations get highest priority
                        GetTarget((const ModelListIGC*)(pcluster->GetShips()),
                                  pside, myPosition, dtUpdate, accuracy, speed, lifespan, OT_ship,
                                  &pmodelTarget, &distance2Min, &directionMin);
                    }

                    if (eabm & c_eabmShootMissiles)
                    {
                        GetTarget((const ModelListIGC*)(pcluster->GetMissiles()),
                                  pside, myPosition, dtUpdate, accuracy, speed, lifespan, OT_missile, 
                                  &pmodelTarget, &distance2Min, &directionMin);
                    }

                    if (eabm & c_eabmShootStations)
                    {
                        GetTarget((const ModelListIGC*)(pcluster->GetStations()),
                                  pside, myPosition, dtUpdate, accuracy, speed, lifespan, OT_station, 
                                  &pmodelTarget, &distance2Min, &directionMin);
                    }
                }

                if (pmodelTarget)
                {
                    if (m_launcher && (m_launcher->GetMission() != GetMyMission()))
                        m_launcher = NULL;

                    //It is going to shoot ... make it visible to everyone in the sector
                    if (!m_bSeenByAll)
                    {
                        m_bSeenByAll = true;
                        for (SideLinkIGC*   psl = m_pMission->GetSides()->first();
                             (psl != NULL);
                             psl = psl->next())
                        {
                            IsideIGC*   psideOther = psl->data();

                            if (!SeenBySide(psideOther))
                            {
                                //Does this side have any scanners in the sector?
                                ClusterSite*    pcs = pcluster->GetClusterSite();
                                const ScannerListIGC*   psl = pcs->GetScanners(psideOther->GetObjectID());
                                if ((psl->n() != 0) || (m_pMission->GetMissionParams()->bAllowAlliedViz && psideOther->AlliedSides(psideOther,pside))) //ALLY 7/3/09 VISIBILITY 7/11/09 imago
                                    SetSideVisibility(psideOther, true);
                                else
                                    m_bSeenByAll = false;
                            }
                        }
                    }

                    //We have a target ... fire along directionMin (modulo dispersion)
                    Orientation o = GetOrientation();
                    o.TurnTo(directionMin);
                    SetOrientation(o);
                    Vector  position = myPosition + m_probeType->GetEmissionPt() * o;

                    DataProjectileIGC   dataProjectile;
                    dataProjectile.projectileTypeID = m_projectileType->GetObjectID();

                    short   nShots = 0;
                    do
                    {
                        //Permute the "forward" direction slightly by a random amount
                        dataProjectile.forward = directionMin;
                        if (dispersion != 0.0f)
                        {
                            float   r = random(0.0f, dispersion);
                            float   a = random(0.0f, 2.0f * pi);
                            dataProjectile.forward += (r * cos(a)) * o.GetRight();
                            dataProjectile.forward += (r * sin(a)) * o.GetUp();

                            dataProjectile.forward.SetNormalize();
                        }

                        //We never move, so skip all the velocity calculations
                        dataProjectile.velocity = speed * dataProjectile.forward;

                        dataProjectile.lifespan = lifespan;

                        IprojectileIGC*  p = (IprojectileIGC*)(m_pMission->CreateObject(m_nextFire, OT_projectile, 
                                                                                        &dataProjectile, sizeof(dataProjectile)));
                        assert (p);
                        {
                            p->SetLauncher(m_launcher ? ((ImodelIGC*)m_launcher) : ((ImodelIGC*)this));
                            p->SetPosition(position);

                            p->SetCluster(pcluster);

                            p->Release();
                        }

                        nShots++;
                        m_nextFire += dtimeBurst;
                    }
                    while (m_nextFire < now);

                    if (m_ammo > 0)
                    {
                        m_ammo -= nShots;
                        if (m_ammo <= 0)
                        {
                            m_ammo = 0;
                            GetMyMission()->GetIgcSite()->KillProbeEvent(this);
                        }
                    }
                }
                else
                {
                    //No shots this cycle
                    m_nextFire = now;
                }
            }
        }

        TmodelIGC<IprobeIGC>::Update(now);
    }
}
示例#30
0
 void SubmitVertex(glsl::vec3 const & pivot, glsl::vec2 const & normal, bool isLeft)
 {
     float const halfWidth = GetHalfWidth();
     m_geometry.emplace_back(V(pivot, TNormal(halfWidth * normal, halfWidth * GetSide(isLeft)), m_colorCoord));
 }