Esempio n. 1
0
HRESULT CchaffIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, unsigned int dataSize)
{
    TmodelIGC<IchaffIGC>::Initialize(pMission, now, data, dataSize);

    ZRetailAssert (data && (dataSize == sizeof(DataChaffIGC)));
    DataChaffIGC*  dataChaff = (DataChaffIGC*)data;

    m_pChaffTypeData = (DataChaffTypeIGC*)(dataChaff->pchafftype->GetData());

    LoadDecal(m_pChaffTypeData->textureName, NULL,
              Color(1.0f, 1.0f, 1.0f, 1.0f),
              false,
              1.0f,
              c_mtNotPickable | c_mtPredictable);

    Time    time0 = pMission->GetIgcSite()->ClientTimeFromServerTime(dataChaff->time0);

    SetRadius(1.0f);
    SetPosition(dataChaff->p0 + Seconds(now - time0).count() * dataChaff->v0);
    SetVelocity(dataChaff->v0);

    {
        Rotation    r(Vector(0.0f, 0.0f, 1.0f), 2.75f);
        SetRotation(r);
    }

    SetMass(0.0f);

    m_timeExpire = time0 + Seconds(m_pChaffTypeData->lifespan);

    SetCluster(dataChaff->pcluster);

    return S_OK;
}
Esempio n. 2
0
FatDirEntry1x*
CmtFat::CreateFileName( cpchar pattern ) {
  uint32 subDir = 0;
  //Войти в поддиректорий
  pattern = GetSubDir( pattern, &subDir );
  if( pattern ) {
    //Успешно вошли в поддиректорий
    CmtFatFinder finder( subDir );
    while(1) {
      FatDirEntry1x *ptr = GetNextFileEntry( &finder );
      if( ptr == 0 ) {
        //Пустых записей не обнаружено, попробовать увеличить директорий
        if( IncreaseDir( subDir ) != CMTE_OK )
          return 0;
        else {
          //Директорий увеличен, повторить попытку поиска
          finder.Set( subDir );
          continue;
          }
        }
      //Проверить, что запись пустая
      if( ptr->mFileName[0] == 0 || ptr->mFileName[0] == 0xe5 ) {
        //Запись пустая, заполнить имя
        int c;
        for( c = 0; c < 8 && *pattern != '.' && *pattern; c++ ) {
          ptr->mFileName[c] = cmtCharUpper( *pattern++ );
          }
        //Добить оставшуюся часть имени пробелами
        while( c < 8 ) ptr->mFileName[c++] = ' ';
        //Добраться до точки
        while( *pattern && *pattern != '.' ) pattern++;
        if( *pattern == '.' ) pattern++;
        for( c = 0; c < 3 && *pattern; c++ ) {
          ptr->mExtension[c] = cmtCharUpper( *pattern++ );
          }
        //Добить оставшуюся часть имени пробелами
        while( c < 3 ) ptr->mExtension[c++] = ' ';
        CmtSystemTime ft;
        ft.GetSystem();
        //Заполнить остальные поля
        ptr->mAttrib = FA_ARHIV;
        ptr->mReserved[0] = ptr->mReserved[1] = 0;
        ptr->mUpdateTime =     //time create/update
        ptr->mCreationTime = ft.FFTime();
        ptr->mUpdateDate =     //date create/update
        ptr->mAccessDate =
        ptr->mCreationDate = ft.FFDate();
        ptr->mFirstClusterHigh = 0; // higher
        ptr->mFileSize = 0;
        ptr->SetFirstCluster32( GetFreeCluster() );
        if( ptr->GetFirstCluster32() > 0 )
          SetCluster( ptr->GetFirstCluster32(), END_CLUSTER );
        dirtyDirSector = 1;
        return ptr;
        }
      }
    }
  return 0; //Нет файла
  }
Esempio n. 3
0
//==============================================================================
//--------------------- FAT - общая --------------------------------------------
int32
CmtFat::IncreaseDir( uint32 startDir ) {
  //Распределить новый кластер
  uint32 cluster = GetFreeCluster();
  if( cluster == 0 || cluster == END_CLUSTER ) return CMTE_FS_DISK_FULL;
  //Получить последний кластер
  uint32 last;
  while( startDir != 0 && startDir != END_CLUSTER ) {
    last = startDir;
    startDir = GetCluster( startDir );
    }
  //Установить цепочку
  SetCluster( last, cluster );
  SetCluster( cluster, END_CLUSTER );
  //Подготовить кластер директория
  InitDirCluster( cluster );
  return CMTE_OK;
  }
Esempio n. 4
0
// Constructor
Node::Node(float x, float y, int RL, Cluster *cluster, Node *nexthop)
    :Point(x, y)
{
    SetCluster(cluster);
    SetNextHop(nexthop);
    hops_to_sink = 0;
    params_init.RL = RL;
    params_init.active = true;
    Reset();
}
Esempio n. 5
0
void
CmtFat::FreeClusters( uint32 cluster ) {
  if( cluster == 0 || cluster == END_CLUSTER ) return;
  if( cluster < curFreeCluster )
    curFreeCluster = cluster;
  while( cluster != END_CLUSTER ) {
    uint32 next = GetCluster( cluster );
    SetCluster( cluster, 0 );
    if( curFreeCluster > cluster )
      curFreeCluster = cluster;
    cluster = next;
    }
  }
Esempio n. 6
0
HRESULT CbuoyIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, unsigned int dataSize)
{
    TmodelIGC<IbuoyIGC>::Initialize(pMission, now, data, dataSize);

    ZRetailAssert (data && (dataSize == sizeof(DataBuoyIGC)));
    DataBuoyIGC*  dataBuoy = (DataBuoyIGC*)data;

    LoadDecal("buoy", "buoyicon",
              Color(1.0f, 1.0f, 1.0f, 1.0f),
              false,
              1.0f,
              c_mtStatic | c_mtPredictable);

    SetRadius(20.0f);
    SetPosition(dataBuoy->position);
    {
        Rotation    r(Vector(0.0f, 0.0f, 1.0f), 0.5f);
        SetRotation(r);
    }
    m_type = dataBuoy->type;

    m_buoyID = (dataBuoy->buoyID == NA) ? pMission->GenerateNewBuoyID() : dataBuoy->buoyID;

    IclusterIGC* pcluster = pMission->GetCluster(dataBuoy->clusterID);

    if (dataBuoy->type == c_buoyCluster)
        SetSecondaryName(pcluster->GetName());
    else
        SetSecondaryName("waypoint");

    SetMass(0.0f);

    pMission->AddBuoy(this);

    SetCluster(pcluster);

    return S_OK;
}
Esempio n. 7
0
/////////////////////////////////////////////////////////////////////////////
// CwarpIGC
HRESULT     CwarpIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize)
{
    TmodelIGC<IwarpIGC>::Initialize(pMission, now, data, dataSize);

    ZRetailAssert (data && (dataSize == sizeof(DataWarpIGC)));
    {
        DataWarpIGC*  dataWarp = (DataWarpIGC*)data;
        m_warpDef = dataWarp->warpDef;

        IclusterIGC*    cluster = pMission->GetCluster(dataWarp->clusterID);
        ZRetailAssert (cluster);
        {
            //  , use the real texture name
            HRESULT rc = LoadWarp(dataWarp->warpDef.textureName,
                                  dataWarp->warpDef.iconName,
                                  c_mtStatic | c_mtHitable | c_mtSeenBySide | c_mtPredictable);

            assert (SUCCEEDED(rc));
            {
                SetRadius((float)m_warpDef.radius);

                SetPosition(dataWarp->position);
                SetVelocity(Vector::GetZero());

                {
                    Orientation o(dataWarp->forward);
                    SetOrientation(o);
                }
                SetRotation(dataWarp->rotation);
                SetCluster(cluster);

                SetMass(0.0f);
				// KG- hack for unmovable alephs (to avoid a IGC file format change)
				// aleph name with a leading '*' denotes a fixed position aleph
				// so remove the '*' from the name and set m_bFixedPosition to true
				// Andon: Added mass limits to alephs. It checks for a leading '+'
				// and if found it searches for a ':' - It then takes everything after
				// this and turns it into a number. After that, it replaces the ':' with
				// a '(' and adds a ')' to the end.
				if (dataWarp->name[0] == '*')
				{
					m_bFixedPosition = true;
					if (dataWarp->name[1] == '+')//Andon: Added for if the aleph is both unmoved and mass limited
					{
						ZString name = dataWarp->name;
						int MassFind = name.Find(':',0); 
						char* mass = &(dataWarp->name[MassFind+2]); 
						m_MassLimit = atoi(mass);
						name.ReplaceAll(":" ,'('); //Replaces the : with a (
						const char* alephname = &(name[2]); //Removes the leading '*+'
						char* newAlephName = new char[25];
						const char* nameSuffix = ")"; //Adds a ) to the end
						strncpy(newAlephName, alephname, strlen(alephname)+1);
						strncat(newAlephName, nameSuffix, strlen(nameSuffix)+1);
						SetName(newAlephName);
					}
					else
					{
						SetName(&(dataWarp->name[1])); // skip the leading '*'
						m_MassLimit = -1;
					}
				}
				else if (dataWarp->name[0] == '+')
				{
					ZString name = dataWarp->name;
					int MassFind = name.Find(':',0);
					char* mass = &(dataWarp->name[MassFind+1]);
					m_MassLimit = atoi(mass);
					name.ReplaceAll(":" ,'('); //Replaces the : with a (
					const char* alephname = &(name[1]);//Skip the leading '+'
					char* newAlephName = new char[25];
					const char* nameSuffix = ")"; //Adds a ) to the end
					strncpy(newAlephName, alephname, strlen(alephname)+1);
					strncat(newAlephName, nameSuffix, strlen(nameSuffix)+1);
					SetName(newAlephName);
				}
				else
				{
                	SetName(dataWarp->name);
					m_MassLimit = -1;
				}

                SetSignature(dataWarp->signature);

                pMission->AddWarp(this);
            }
        }
    }

    return S_OK;
}
Esempio n. 8
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;
}
/////////////////////////////////////////////////////////////////////////////
// CasteroidIGC
HRESULT     CasteroidIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize)
{
	ZeroMemory(&m_builderseensides, sizeof(bool) * c_cSidesMax); //Imago 8/10
    TmodelIGC<IasteroidIGC>::Initialize(pMission, now, data, dataSize);

    ZRetailAssert (data && (dataSize == sizeof(DataAsteroidIGC)));
    {
        DataAsteroidIGC*  dataAsteroid = (DataAsteroidIGC*)data;
        m_asteroidDef = dataAsteroid->asteroidDef;
		
        IclusterIGC*    cluster = pMission->GetCluster(dataAsteroid->clusterID);
        ZRetailAssert (cluster);
        {
            HRESULT rc = Load(0,
                              m_asteroidDef.modelName,
                              m_asteroidDef.textureName,
                              m_asteroidDef.iconName,
                              c_mtStatic | c_mtHitable | c_mtDamagable | c_mtSeenBySide | c_mtPredictable);
            assert (SUCCEEDED(rc));

            SetRadius((float)m_asteroidDef.radius);
            SetPosition(dataAsteroid->position);
            {
                Orientation o(dataAsteroid->forward, dataAsteroid->up);
                SetOrientation(o);
            }
			
			// Turkey 01/2014 AME is bugged, rotation axis should be a normalized vector
			Rotation r = dataAsteroid->rotation;
			Vector axis = r.axis().Normalize();
			r.axis(axis);
            SetRotation(r);

            SetSignature(dataAsteroid->signature);

            m_fraction = dataAsteroid->fraction;
			if (m_fraction > 1.0f) m_fraction = 1.0f; // Turkey 01/2014 AME is bugged, gives rocks 100.4% hitpoints (241/240)

            if (dataAsteroid->name[0] != '\0')
                SetName(dataAsteroid->name);
            else
                SetSecondaryName(dataAsteroid->name + 1);

            SetCluster(cluster);

			//Xynth #100 7/2010 Need to initialize oreseenbyside for all sides
			for (SideLinkIGC* psl = this->GetMission()->GetSides()->first(); psl != NULL; psl = psl->next())
			{
				IsideIGC* pside = psl->data();									
				oreSeenBySide.Set(pside, 0.0);									
			}

			m_lastUpdateOre = 0.0;  //Xynth #132 7/2010 Should update first time this is mined
			m_inhibitUpdate = false; //Xynth #225 9/10 		
		    m_inhibitCounter = -1;
#ifdef DEBUG
            {
                //Verify that there is no pre-existing asteroid with the same ID
                for (AsteroidLinkIGC*   pal = pMission->GetAsteroids()->first(); (pal != NULL); pal = pal->next())
                {
                    assert (pal->data()->GetObjectID() != m_asteroidDef.asteroidID);
                }
            }
#endif
            pMission->AddAsteroid(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;
}