CVector CreateVectorFromList (CCodeChain &CC, ICCItem *pList) // CreateVectorFromList // // Creates a vector from a code chain list { CVector vVec; if (pList->IsList()) CreateBinaryFromList(CC, pList, &vVec); else if (pList->IsInteger()) { CSpaceObject *pObj = CreateObjFromItem(CC, pList); if (pObj) vVec = pObj->GetPos(); } return vVec; }
bool IDockScreenDisplay::ParseBackgrounDesc (ICCItem *pDesc, SBackgroundDesc *retDesc) // ParseBackroundDesc // // Parses a descriptor. Returns TRUE if successful. { CCodeChain &CC = g_pUniverse->GetCC(); // Nil means no default value if (pDesc->IsNil()) retDesc->iType = backgroundDefault; // If we have a struct, we expect a certain format else if (pDesc->IsSymbolTable()) { CString sType = pDesc->GetStringAt(FIELD_TYPE); if (sType.IsBlank() || strEquals(sType, TYPE_NONE)) retDesc->iType = backgroundNone; else if (strEquals(sType, TYPE_HERO)) { retDesc->iType = backgroundObjHeroImage; retDesc->pObj = CreateObjFromItem(CC, pDesc->GetElement(FIELD_OBJ)); if (retDesc->pObj == NULL) return false; } else if (strEquals(sType, TYPE_IMAGE)) { retDesc->iType = backgroundImage; ICCItem *pImage = pDesc->GetElement(FIELD_IMAGE); if (pImage == NULL) return false; else if (pImage->IsInteger()) retDesc->dwImageID = pImage->GetIntegerValue(); else return false; } else if (strEquals(sType, TYPE_OBJECT)) { retDesc->pObj = CreateObjFromItem(CC, pDesc->GetElement(FIELD_OBJ)); if (retDesc->pObj == NULL) return false; if (retDesc->pObj->IsPlayer()) retDesc->iType = backgroundObjSchematicImage; else retDesc->iType = backgroundObjHeroImage; } else if (strEquals(sType, TYPE_SCHEMATIC)) { retDesc->iType = backgroundObjSchematicImage; retDesc->pObj = CreateObjFromItem(CC, pDesc->GetElement(FIELD_OBJ)); if (retDesc->pObj == NULL) return false; } else return false; } // Otherwise, we can't parse. // // LATER: We should eventually handle a list-based image descriptor, but we // would need to enhance SBackgroundDesc for that. else return false; // Success return true; }
bool GetPosOrObject (CEvalContext *pEvalCtx, ICCItem *pArg, CVector *retvPos, CSpaceObject **retpObj, int *retiLocID) // GetPosOrObject // // pArg is either a position or an object. We return a position and/or the object. { CCodeChain &CC(*pEvalCtx->pCC); CVector vPos; CSpaceObject *pObj = NULL; int iLocID = -1; if (pArg->IsNil()) NULL; else if (pArg->IsList()) { // Is this a location criteria? CString sTag = pArg->GetElement(0)->GetStringValue(); if (strEquals(sTag, CONSTLIT("location"))) { CSystem *pSystem = g_pUniverse->GetCurrentSystem(); if (pSystem == NULL) return false; // Get the criteria and parse it CString sCriteria = (pArg->GetCount() > 1 ? pArg->GetElement(1)->GetStringValue() : NULL_STR); if (sCriteria.IsBlank()) return false; CAttributeCriteria Criteria; if (Criteria.Parse(sCriteria) != NOERROR) return false; // Get a random location if (!pSystem->FindRandomLocation(Criteria, 0, NULL, &iLocID)) return false; // Return the position CLocationDef *pLoc = pSystem->GetLocation(iLocID); vPos = pLoc->GetOrbit().GetObjectPos(); } // Otherwise, we assume a vector else vPos = CreateVectorFromList(CC, pArg); } else { pObj = CreateObjFromItem(CC, pArg); if (pObj) vPos = pObj->GetPos(); } // Done if (retvPos) *retvPos = vPos; if (retpObj) *retpObj = pObj; if (retiLocID) *retiLocID = iLocID; return true; }
CDamageSource GetDamageSourceArg (CCodeChain &CC, ICCItem *pArg) // GetDamageSourceArg // // Returns a CDamageSource { if (pArg->IsNil()) return CDamageSource(NULL, killedByDamage); // Killed by the given object (explosion) else if (pArg->IsInteger()) { CSpaceObject *pSource = CreateObjFromItem(CC, pArg); return CDamageSource(pSource, killedByDamage); } // Custom death; string describes the cause of death (no explosion) else if (pArg->IsIdentifier()) { CString sCause = pArg->GetElement(0)->GetStringValue(); return CDamageSource(NULL, killedByOther, NULL, sCause, 0); } // Killed by a custom cause (explosion) else if (pArg->IsList() && pArg->GetCount() == 2 && pArg->GetElement(0)->IsIdentifier()) { CString sSourceName = pArg->GetElement(0)->GetStringValue(); DWORD dwSourceFlags = (DWORD)pArg->GetElement(1)->GetIntegerValue(); return CDamageSource(NULL, killedByDamage, NULL, sSourceName, dwSourceFlags); } // Full control over death else if (pArg->IsList()) { CSpaceObject *pSource = NULL; CSpaceObject *pSecondarySource = NULL; CString sSourceName; DWORD dwSourceFlags = 0; DestructionTypes iCause = killedByDamage; if (pArg->GetCount() >= 1) pSource = CreateObjFromItem(CC, pArg->GetElement(0)); if (pArg->GetCount() >= 2) iCause = ::GetDestructionCause(pArg->GetElement(1)->GetStringValue()); if (pArg->GetCount() >= 3) pSecondarySource = CreateObjFromItem(CC, pArg->GetElement(2)); if (pArg->GetCount() >= 4) sSourceName = pArg->GetElement(3)->GetStringValue(); if (pArg->GetCount() >= 5) dwSourceFlags = (DWORD)pArg->GetElement(4)->GetIntegerValue(); return CDamageSource(pSource, iCause, pSecondarySource, sSourceName, dwSourceFlags); } else return CDamageSource(); }
CStation *CreateStationObjFromItem (CCodeChain &CC, ICCItem *pArg) { CSpaceObject *pObj = CreateObjFromItem(CC, pArg); return (pObj ? pObj->AsStation() : NULL); }
CShip *CreateShipObjFromItem (CCodeChain &CC, ICCItem *pArg) { CSpaceObject *pObj = CreateObjFromItem(CC, pArg); return (pObj ? pObj->AsShip() : NULL); }
CDamageSource GetDamageSourceArg (CCodeChain &CC, ICCItem *pArg) // GetDamageSourceArg // // Returns a CDamageSource { if (pArg->IsNil()) return CDamageSource(NULL, killedByDamage); // Killed by the given object (explosion) else if (pArg->IsInteger()) { // NOTE: CDamageSource knows how to deal with destroyed objects, so it // is OK if we don't bother checking here whether pSource is destroyed. CSpaceObject *pSource = CreateObjFromItem(CC, pArg); return CDamageSource(pSource, killedByDamage); } // Custom death; string describes the cause of death (no explosion) else if (pArg->IsIdentifier()) { CString sCause = pArg->GetElement(0)->GetStringValue(); // If the cause happens to be a destruction cause ID, then use that. DestructionTypes iCause = ::GetDestructionCause(sCause); if (iCause != killedNone) return CDamageSource(NULL, iCause, NULL, NULL_STR, 0); // Otherwise, this is a custom death return CDamageSource(NULL, killedByOther, NULL, sCause, 0); } // Killed by a custom cause (explosion) else if (pArg->IsList() && pArg->GetCount() == 2 && pArg->GetElement(0)->IsIdentifier()) { CString sSourceName = pArg->GetElement(0)->GetStringValue(); DWORD dwSourceFlags = (DWORD)pArg->GetElement(1)->GetIntegerValue(); return CDamageSource(NULL, killedByDamage, NULL, sSourceName, dwSourceFlags); } // Full control over death else if (pArg->IsList()) { CSpaceObject *pSource = NULL; CSpaceObject *pSecondarySource = NULL; CString sSourceName; DWORD dwSourceFlags = 0; DestructionTypes iCause = killedByDamage; if (pArg->GetCount() >= 1) pSource = CreateObjFromItem(CC, pArg->GetElement(0)); if (pArg->GetCount() >= 2) iCause = ::GetDestructionCause(pArg->GetElement(1)->GetStringValue()); if (pArg->GetCount() >= 3) pSecondarySource = CreateObjFromItem(CC, pArg->GetElement(2)); if (pArg->GetCount() >= 4) sSourceName = pArg->GetElement(3)->GetStringValue(); if (pArg->GetCount() >= 5) dwSourceFlags = (DWORD)pArg->GetElement(4)->GetIntegerValue(); return CDamageSource(pSource, iCause, pSecondarySource, sSourceName, dwSourceFlags); } else return CDamageSource(); }