static FStateLabels * CreateStateLabelList(TArray<FStateDefine> & statelist) { // First delete all empty labels from the list for (int i=statelist.Size()-1;i>=0;i--) { if (statelist[i].Label == NAME_None || (statelist[i].State == NULL && statelist[i].Children.Size() == 0)) { statelist.Delete(i); } } int count=statelist.Size(); if (count == 0) return NULL; FStateLabels * list = (FStateLabels*)M_Malloc(sizeof(FStateLabels)+(count-1)*sizeof(FStateLabel)); list->NumLabels = count; for (int i=0;i<count;i++) { list->Labels[i].Label = statelist[i].Label; list->Labels[i].State = statelist[i].State; list->Labels[i].Children = CreateStateLabelList(statelist[i].Children); } qsort(list->Labels, count, sizeof(FStateLabel), labelcmp); return list; }
void InstallStates(FActorInfo *info, AActor *defaults) { // First ensure we have a valid spawn state. FState * state = FindState(defaults, info->Class, "Spawn"); // Stateless actors that are direct subclasses of AActor // have their spawnstate default to something that won't // immediately destroy them. if (state == &AActor::States[2] && info->Class->ParentClass == RUNTIME_CLASS(AActor)) { AddState("Spawn", &AActor::States[0]); } else if (state == NULL) { // A NULL spawn state will crash the engine so set it to something that will make // the actor disappear as quickly as possible. AddState("Spawn", &AActor::States[2]); } if (info->StateList != NULL) { info->StateList->Destroy(); free(info->StateList); } info->StateList = CreateStateLabelList(StateLabels); // Cache these states as member veriables. defaults->SpawnState = info->FindState(NAME_Spawn); defaults->SeeState = info->FindState(NAME_See); // Melee and Missile states are manipulated by the scripted marines so they // have to be stored locally defaults->MeleeState = info->FindState(NAME_Melee); defaults->MissileState = info->FindState(NAME_Missile); }
void FStateDefinitions::InstallStates(PClassActor *info, AActor *defaults) { // First ensure we have a valid spawn state. FState *state = FindState("Spawn"); if (state == NULL) { // A NULL spawn state will crash the engine so set it to something valid. SetStateLabel("Spawn", GetDefault<AActor>()->SpawnState); } if (info->StateList != NULL) { info->StateList->Destroy(); M_Free(info->StateList); } info->StateList = CreateStateLabelList(StateLabels); // Cache these states as member veriables. defaults->SpawnState = info->FindState(NAME_Spawn); defaults->SeeState = info->FindState(NAME_See); // Melee and Missile states are manipulated by the scripted marines so they // have to be stored locally defaults->MeleeState = info->FindState(NAME_Melee); defaults->MissileState = info->FindState(NAME_Missile); }