void CTrigger::SaveState (CFile& cf, bool bObjTrigger) { cf.WriteByte (sbyte (m_info.nType)); if (bObjTrigger) cf.WriteShort (m_info.flags); else cf.WriteByte (sbyte (m_info.flags)); cf.WriteByte (m_info.nLinks); cf.WriteFix (m_info.value); cf.WriteFix (m_info.time); for (int i = 0; i < MAX_TRIGGER_TARGETS; i++) { cf.WriteShort (m_info.segments [i]); cf.WriteShort (m_info.sides [i]); } cf.WriteFix (m_info.tOperated); }
int CreateObject (ubyte nType, ubyte nId, short nCreator, short nSegment, const CFixVector& vPos, const CFixMatrix& mOrient, fix xSize, ubyte cType, ubyte mType, ubyte rType) { short nObject; CObject *objP; #if DBG if (nType == OBJ_WEAPON) { nType = nType; if ((nCreator >= 0) && (OBJECTS [nCreator].info.nType == OBJ_ROBOT)) { nType = nType; if ((nDbgSeg >= 0) && (nSegment == nDbgSeg)) nDbgSeg = nDbgSeg; } if (nId == FLARE_ID) nType = nType; if (gameData.objs.bIsMissile [(int) nId]) nType = nType; } else if (nType == OBJ_ROBOT) { #if 0 if (ROBOTINFO ((int) nId).bossFlag && (BOSS_COUNT >= MAX_BOSS_COUNT)) return -1; #endif } else if (nType == OBJ_HOSTAGE) nType = nType; else if (nType == OBJ_FIREBALL) nType = nType; else if (nType == OBJ_REACTOR) nType = nType; else if (nType == OBJ_DEBRIS) nType = nType; else if (nType == OBJ_MARKER) nType = nType; else if (nType == OBJ_PLAYER) nType = nType; else if (nType == OBJ_POWERUP) { nType = nType; if (nId == POW_MONSTERBALL) nId = nId; } #endif //if (GetSegMasks (vPos, nSegment, 0).m_center)) if (nSegment < -1) nSegment = -nSegment - 2; else nSegment = FindSegByPos (vPos, nSegment, 1, 0); if ((nSegment < 0) || (nSegment > gameData.segs.nLastSegment)) return -1; if (nType == OBJ_DEBRIS) { if (gameData.objs.nDebris >= gameStates.render.detail.nMaxDebrisObjects) return -1; } // Find next free object if (0 > (nObject = AllocObject ())) return -1; objP = OBJECTS + nObject; objP->SetId (nObject); // Zero out object structure to keep weird bugs from happening in uninitialized fields. objP->info.nSignature = gameData.objs.nNextSignature++; objP->info.nType = nType; objP->info.nId = nId; objP->info.vLastPos = objP->info.position.vPos = vPos; objP->SetOrigin (vPos); objP->info.xSize = xSize; objP->info.nCreator = sbyte (nCreator); objP->info.xLifeLeft = IMMORTAL_TIME; if (IsMultiGame && (gameData.app.nGameMode & GM_ENTROPY) && (nType == OBJ_POWERUP) && (nId == POW_ENTROPY_VIRUS)) { if ((nCreator >= 0) && (OBJECTS [nCreator].info.nType == OBJ_PLAYER)) objP->info.nCreator = sbyte (GetTeam (OBJECTS [nCreator].info.nId) + 1); if (extraGameInfo [1].entropy.nVirusLifespan > 0) objP->info.xLifeLeft = I2X (extraGameInfo [1].entropy.nVirusLifespan); } objP->info.position.mOrient = mOrient; objP->info.controlType = cType; objP->info.movementType = mType; objP->info.renderType = rType; objP->info.contains.nType = -1; objP->info.nAttachedObj = -1; if (objP->info.controlType == CT_POWERUP) objP->cType.powerupInfo.nCount = 1; // Init physics info for this CObject if (objP->info.movementType == MT_PHYSICS) objP->SetStartVel ((CFixVector*) &CFixVector::ZERO); if (objP->info.renderType == RT_POLYOBJ) objP->rType.polyObjInfo.nTexOverride = -1; objP->SetCreationTime (gameData.time.xGame); if (objP->info.nType == OBJ_WEAPON) { Assert (objP->info.controlType == CT_WEAPON); objP->mType.physInfo.flags |= WI_persistent (objP->info.nId) * PF_PERSISTENT; objP->cType.laserInfo.xCreationTime = gameData.time.xGame; objP->cType.laserInfo.nLastHitObj = 0; objP->cType.laserInfo.xScale = I2X (1); } else if (objP->info.nType == OBJ_DEBRIS) gameData.objs.nDebris++; if (objP->info.controlType == CT_POWERUP) objP->cType.powerupInfo.xCreationTime = gameData.time.xGame; else if (objP->info.controlType == CT_EXPLOSION) objP->cType.explInfo.attached.nNext = objP->cType.explInfo.attached.nPrev = objP->cType.explInfo.attached.nParent = -1; objP->Link (); objP->LinkToSeg (nSegment); memset (&objP->HitInfo (), 0, sizeof (CObjHitInfo)); #if 1 if (IsMultiGame && IsCoopGame && (nType == OBJ_WEAPON) && gameData.objs.bIsMissile [int (nId)] && (nCreator >= 0) && (OBJECTS [nCreator].info.nType == OBJ_PLAYER)) { extern char powerupToObject [MAX_POWERUP_TYPES]; for (int i = 0; i < MAX_POWERUP_TYPES; i++) { if (powerupToObject [i] == nId) gameData.multiplayer.maxPowerupsAllowed [i]--; } } #endif OBJECTS [nObject].ResetDamage (); OBJECTS [nObject].SetTarget (NULL); return nObject; }