ALERROR CIntegralRotationDesc::InitFromXML (SDesignLoadCtx &Ctx, const CString &sUNID, CXMLElement *pDesc) // InitFromXML // // Initialize from an XML descriptor { // If we have a Maneuver element, then use that (and ignore other attributes) CXMLElement *pManeuver = pDesc->GetContentElementByTag(MANEUVER_TAG); if (pManeuver) { m_iManeuverability = 0; m_iCount = pManeuver->GetAttributeIntegerBounded(ROTATION_COUNT_ATTRIB, 1, -1, STD_ROTATION_COUNT); // Max rotation rate is in degrees per tick. Later we convert that to rotation frames per tick // (but not until we figure out the number of rotation frames). m_rDegreesPerTick = pManeuver->GetAttributeDoubleBounded(MAX_ROTATION_RATE_ATTRIB, 0.01, -1.0, 360.0 / STD_ROTATION_COUNT); // Also convert rotation acceleration m_rAccelPerTick = pManeuver->GetAttributeDoubleBounded(ROTATION_ACCEL_ATTRIB, 0.01, -1.0, m_rDegreesPerTick); m_rAccelPerTickStop = pManeuver->GetAttributeDoubleBounded(ROTATION_STOP_ACCEL_ATTRIB, 0.01, -1.0, m_rAccelPerTick); } // Otherwise we look for attributes on the root (this is backwards compatible // with version prior to API 20 else { m_iCount = pDesc->GetAttributeIntegerBounded(ROTATION_COUNT_ATTRIB, 1, -1, STD_ROTATION_COUNT); // The original maneuverability value is the number of half-ticks that // we take per rotation frame. // // NOTE: For compatibility we don't allow maneuverability less than 2, which was the // limit using the old method (1 tick delay). m_iManeuverability = pDesc->GetAttributeIntegerBounded(MANEUVER_ATTRIB, 2, -1, 2); // Convert that to degrees per tick m_rDegreesPerTick = (m_iCount > 0 ? (STD_SECONDS_PER_UPDATE * 360.0) / (m_iCount * m_iManeuverability) : 0.0); // Default acceleration is equal to rotation rate m_rAccelPerTick = m_rDegreesPerTick; m_rAccelPerTickStop = m_rDegreesPerTick; } return NOERROR; }
bool IDockScreenDisplay::GetDisplayOptions (SInitCtx &Ctx, SDisplayOptions *retOptions, CString *retsError) // GetDisplayOptions // // Initializes the display options structure, which is used by list and // selector displays. { DEBUG_TRY // Initialize background image options CString sBackgroundID; if (Ctx.pDesc->FindAttribute(BACKGROUND_ID_ATTRIB, &sBackgroundID)) { // If the attribute exists, but is empty (or equals "none") then // we don't have a background if (sBackgroundID.IsBlank() || strEquals(sBackgroundID, CONSTLIT("none"))) retOptions->BackgroundDesc.iType = backgroundNone; else if (strEquals(sBackgroundID, TYPE_HERO)) { retOptions->BackgroundDesc.iType = backgroundObjHeroImage; retOptions->BackgroundDesc.pObj = Ctx.pLocation; } // If the ID is "object" then we should ask the object else if (strEquals(sBackgroundID, TYPE_OBJECT)) { retOptions->BackgroundDesc.pObj = Ctx.pLocation; if (Ctx.pLocation->IsPlayer()) retOptions->BackgroundDesc.iType = backgroundObjSchematicImage; else retOptions->BackgroundDesc.iType = backgroundObjHeroImage; } else if (strEquals(sBackgroundID, TYPE_SCHEMATIC)) { retOptions->BackgroundDesc.iType = backgroundObjSchematicImage; retOptions->BackgroundDesc.pObj = Ctx.pLocation; } // If the ID is "player" then we should ask the player ship else if (strEquals(sBackgroundID, DATA_FROM_PLAYER)) { CSpaceObject *pPlayer = g_pUniverse->GetPlayerShip(); if (pPlayer) { retOptions->BackgroundDesc.iType = backgroundObjSchematicImage; retOptions->BackgroundDesc.pObj = pPlayer; } } // Otherwise, we expect an integer else { retOptions->BackgroundDesc.iType = backgroundImage; retOptions->BackgroundDesc.dwImageID = strToInt(sBackgroundID, 0); } } // Initialize control rect. If we have a background, then initialize to // backwards compatible position. Otherwise, we take up the full range. if (retOptions->BackgroundDesc.iType != backgroundDefault) { retOptions->rcControl.left = 4; retOptions->rcControl.top = 12; retOptions->rcControl.right = 548; retOptions->rcControl.bottom = 396; } else { retOptions->rcControl.left = 0; retOptions->rcControl.top = 23; retOptions->rcControl.right = 600; retOptions->rcControl.bottom = 502; } // Get the type if (Ctx.pDisplayDesc && Ctx.pDisplayDesc->FindAttribute(TYPE_ATTRIB, &retOptions->sType)) NULL; else retOptions->sType = Ctx.pDesc->GetAttribute(TYPE_ATTRIB); // There are a couple of different ways to get options (for backwards // compatibility). CXMLElement *pOptions; if ((pOptions = Ctx.pDesc->GetContentElementByTag(LIST_OPTIONS_TAG)) == NULL && (pOptions = Ctx.pDesc->GetContentElementByTag(LIST_TAG)) == NULL && (pOptions = Ctx.pDisplayDesc) == NULL) return true; retOptions->pOptions = pOptions; // Read from the element retOptions->sDataFrom = pOptions->GetAttribute(DATA_FROM_ATTRIB); if (!pOptions->FindAttribute(CRITERIA_ATTRIB, &retOptions->sItemCriteria)) retOptions->sItemCriteria = pOptions->GetAttribute(LIST_ATTRIB); retOptions->sInitialItemCode = pOptions->GetAttribute(INITIAL_ITEM_ATTRIB); retOptions->sRowHeightCode = pOptions->GetAttribute(ROW_HEIGHT_ATTRIB); // Init code CXMLElement *pInitCode = pOptions->GetContentElementByTag(ON_DISPLAY_INIT_TAG); if (pInitCode == NULL) pInitCode = pOptions; retOptions->sCode = pInitCode->GetContentText(0); // List options retOptions->bNoArmorSpeedDisplay = pOptions->GetAttributeBool(NO_ARMOR_SPEED_DISPLAY_ATTRIB); retOptions->bActualItems = pOptions->GetAttributeBool(DISPLAY_ACTUAL_ATTRIB); retOptions->cxIcon = pOptions->GetAttributeIntegerBounded(ICON_WIDTH_ATTRIB, 0, -1, ICON_WIDTH); retOptions->cyIcon = pOptions->GetAttributeIntegerBounded(ICON_HEIGHT_ATTRIB, 0, -1, ICON_HEIGHT); retOptions->rIconScale = pOptions->GetAttributeDoubleBounded(ICON_SCALE_ATTRIB, 0.0, -1.0, 1.0); // Selector options retOptions->bNoEmptySlots = pOptions->GetAttributeBool(NO_EMPTY_SLOTS_ATTRIB); retOptions->sSlotNameCode = pOptions->GetAttribute(SLOT_NAME_ATTRIB); // See if we have control position if (pOptions->FindAttributeInteger(POS_X_ATTRIB, (int *)&retOptions->rcControl.left)) { retOptions->rcControl.top = pOptions->GetAttributeIntegerBounded(POS_Y_ATTRIB, 0, -1); retOptions->rcControl.right = retOptions->rcControl.left + pOptions->GetAttributeIntegerBounded(WIDTH_ATTRIB, 0, -1); retOptions->rcControl.bottom = retOptions->rcControl.top + pOptions->GetAttributeIntegerBounded(HEIGHT_ATTRIB, 0, -1); } return true; DEBUG_CATCH }