Script::RefVariable* ScriptBuffer::ResolveRef(const char* refName) { Script::RefVariable* newRef = NULL; Script::RefListEntry* listEnd = &refVars; // see if it's already in the refList for (Script::RefListEntry* cur = &refVars; cur; cur = cur->next) { listEnd = cur; if (cur->var && !_stricmp(cur->var->name.m_data, refName)) return cur->var; } // not in list // is it a local ref variable? VariableInfo* varInfo = vars.GetVariableByName(refName); if (varInfo && GetVariableType(varInfo, NULL) == Script::eVarType_Ref) { newRef = (Script::RefVariable*)FormHeap_Allocate(sizeof(Script::RefVariable)); newRef->form = NULL; } else // is it a form or global? { TESForm* form = GetFormByID(refName); if (form) { TESObjectREFR* refr = DYNAMIC_CAST(form, TESForm, TESObjectREFR); if (refr && !refr->IsPersistent()) // only persistent refs can be used in scripts return NULL; newRef = (Script::RefVariable*)FormHeap_Allocate(sizeof(Script::RefVariable)); memset(newRef, 0, sizeof(Script::RefVariable)); newRef->form = form; } } if (newRef) // got it, add to refList { newRef->name.Set(refName); newRef->varIdx = 0; if (!refVars.var) refVars.var = newRef; else { Script::RefListEntry* entry = (Script::RefListEntry*)FormHeap_Allocate(sizeof(Script::RefListEntry)); entry->var = newRef; entry->next = NULL; listEnd->next = entry; } numRefs++; return newRef; } else return NULL; }
bool Cmd_SetDoorTeleport_Execute(COMMAND_ARGS) { // linkedDoor x y z (rot). if omitted, coords/rot taken from linked ref *result = 0; if (!thisObj || thisObj->baseForm->typeID != kFormType_Door) return true; TESObjectREFR* linkedDoor = NULL; float x = 999; float y = 999; float z = 999; float rot = 999; if (GetByTypeCast(thisObj->extraDataList, RandomTeleportMarker)) return true; if (ExtractArgs(EXTRACT_ARGS, &linkedDoor, &x, &y, &z, &rot) && linkedDoor && linkedDoor->IsPersistent()) // ###TODO: necessary for linkedref to be door? { ExtraTeleport* tele = GetByTypeCast(thisObj->extraDataList, Teleport); if (!tele) { tele = ExtraTeleport::Create(); thisObj->extraDataList.Add(tele); } tele->data->linkedDoor = linkedDoor; if (x == 999 && y == 999 && z == 999) { x = linkedDoor->posX; y = linkedDoor->posY; z = linkedDoor->posZ; } if (rot == 999) rot = linkedDoor->rotZ; else rot *= kDegreeToRad; tele->data->x = x; tele->data->y = y; tele->data->z = z; tele->data->zRot = rot; *result = 1; } return true; }
static bool Cmd_SetPlayersLastRiddenHorse_Execute(COMMAND_ARGS) { TESObjectREFR* horseRef = NULL; *result = 0.0; // must be a persistent reference since game keeps a pointer to it if (ExtractArgs(PASS_EXTRACT_ARGS, &horseRef) && horseRef && horseRef->IsPersistent()) { Creature* horse = OBLIVION_CAST(horseRef, TESObjectREFR, Creature); // must be a creature if (horse && horse->baseForm) { TESCreature* horseBase = OBLIVION_CAST(horse->baseForm, TESForm, TESCreature); // base must be a horse-type creature if (horseBase && horseBase->type == TESCreature::eCreatureType_Horse) { (*g_thePlayer)->lastRiddenHorse = horse; *result = 1.0; } } } return true; }