Пример #1
0
void Account::UpdateAccountWidget()
{
    std::vector<Element*>::iterator it;
    for(it = GetElements().begin(); it != GetElements().end(); it++)
    {
        (*it)->UpdateGeometry(GetAccountWidget()->geometry().width());
    }

    GetAccountWidget()->update();
}
Пример #2
0
void Account::DeleteElement(int pos)
{
    accessElements->lock();

    if(!m_accountWidget->IsInEditingMode())
    {
        delete (*(GetElements().begin() + pos));
        GetElements().erase(GetElements().begin() + pos);
    }

    accessElements->unlock();
}
Пример #3
0
void VValueBag::AddElement( const StKey& inElementName, VValueBag *inBag)
{
	xbox_assert( inElementName.GetKeyLength() != 0);
	
	if (inBag != NULL)
	{
		VBagArray *bags = GetElements( inElementName);
		if (bags)
		{
			bags->AddTail( inBag);
		}
		else
		{
			bags = new VBagArray;
			if (bags != NULL)
			{
				bags->AddTail( inBag);
				if (fElements == NULL)
					fElements = new VPackedVBagArrayDictionary;
				if (fElements != NULL)
					fElements->Append( inElementName, bags);
				bags->Release();
			}
		}
	}
}
Пример #4
0
Account::~Account()
{
    qDebug() << "    Destroying Account...";

    calculThread->exit();
    if(!calculThread->wait())
        calculThread->terminate();
    delete calculThread;
    delete accessElements;
    delete m_accountOptions;
    delete navModel;

    std::vector<Element*>::iterator it;
    for(it = GetElements().begin(); it != GetElements().end(); it++)
    {
        delete (*it);
    }
    GetElements().clear();

    qDebug() << "    Account destroyed.";
}
Пример #5
0
bool VValueBag::Override( const VValueBag *inOverridingBag)
{
	bool ok = true;
	
	if (inOverridingBag != NULL)
	{
		// override attributes
		VIndex count = inOverridingBag->GetAttributesCount();
		for ( VIndex i = 1 ; i <= count ; ++i)
		{
			VString name;
			const VValueSingle *value = inOverridingBag->fAttributes.GetNthValue( i, &name);
			fAttributes.SetValue( name, *value);
		}
		
		// override elements
		VIndex overridingElementNamesCount = inOverridingBag->GetElementNamesCount();
		for( VIndex i = 1 ; (i <= overridingElementNamesCount) && ok ; ++i)
		{
			VString name;
			const VBagArray* overridingElements = inOverridingBag->GetNthElementName( i, &name);

			VBagArray* elements = GetElements( name);
			
			if ( (overridingElements->GetCount() == 1) && (elements->GetCount() == 1) )
			{
				// if there's exactly one element on both sides, let's override attributes
				ok = elements->GetNth(1)->Override( overridingElements->GetNth(1));
			}
			else
			{
				// add elements
				for( VIndex j = 1 ; (j <= overridingElements->GetCount()) && ok ; ++j)
				{
					const VValueBag* elemBag = overridingElements->GetNth(j);
					if (elemBag != NULL)
					{
						VValueBag *clonedElemBag = elemBag->Clone();
						if (clonedElemBag != NULL)
							AddElement( name, clonedElemBag);
						else
							ok = false;
						ReleaseRefCountable( &clonedElemBag);
					}
				}
			}
		}
	}

	return ok;
}
Пример #6
0
void IniSpawn::ReadSpawnEntry(DataFileMgr *inifile, const char *entryname, SpawnEntry &entry) const
{
	const char *s;
	
	entry.interval = (unsigned int) inifile->GetKeyAsInt(entryname,"interval",0);
	//don't default to NULL here, some entries may be missing in original game
	//an empty default string here will create an empty but consistent entry
	s = inifile->GetKeyAsString(entryname,"critters","");
	int crittercount = CountElements(s,',');
	entry.crittercount=crittercount;
	entry.critters=new CritterEntry[crittercount];
	ieVariable *critters = new ieVariable[crittercount];
	GetElements(s, critters, crittercount);
	while(crittercount--) {
		ReadCreature(inifile, critters[crittercount], entry.critters[crittercount]);
	}
	delete[] critters;
}
Пример #7
0
bool VValueBag::ReplaceElement( const StKey& inElementName, VValueBag *inBag)
{
	xbox_assert( inElementName.GetKeyLength() != 0);
	bool ok = false;

	if (inBag == NULL)
	{
		RemoveElements( inElementName);
	}
	else
	{
		VBagArray *bags = GetElements( inElementName);
		if (bags)
		{
			// nothing to do if we already has only one element and if that's the one we are given
			if ( (bags->GetCount() != 1) || (bags->GetNth( 1) != inBag) )
			{
				// the given bag may come from bags
				inBag->Retain();
				bags->Destroy();
				ok = bags->AddTail( inBag);
				inBag->Release();
			}
		}
		else
		{
			bags = new VBagArray;
			if (bags != NULL)
			{
				ok = bags->AddTail( inBag);
				if (fElements == NULL)
					fElements = new VPackedVBagArrayDictionary;
				if (fElements != NULL)
					fElements->Append( inElementName, bags);
				bags->Release();
			}
		}
	}
	return ok;
}
Пример #8
0
VValueBag* VValueBag::RetainUniqueElementWithAttribute( const StKey& inElementName,const StKey& inAttributeName,const VValueSingle& inAttributeValue)
{
	VBagArray* bagarray = GetElements( inElementName);

	sLONG nb_found = 0;
	VIndex index_found = 0;
	if (bagarray)
	{
		VIndex nb_bag = bagarray->GetCount();

		VValueSingle *value_same_type = inAttributeValue.Clone();

		if (value_same_type)
		{
			for (VIndex bag_index = 1; bag_index <= nb_bag;++bag_index)
			{
				const VValueBag *bag = bagarray->RetainNth(bag_index);
				if (bag)
				{
					bag->GetAttribute(inAttributeName,*value_same_type);
					if (*value_same_type == inAttributeValue)
					{
						++nb_found;
						index_found = bag_index;
					}
					bag->Release();
				}
				// Stop the loop if 2 or more were found, we'll return NULL
				if(nb_found > 1)
					break;
			}
			delete value_same_type;
		}
	}
	return (nb_found == 1) ? bagarray->RetainNth(index_found) : NULL;
}
Пример #9
0
bool CPhotoManager::Activate(IHTMLDocument2Ptr spDoc, bool bOn, CString& strHost)
{
	m_strHost = strHost;

	// spDoc could be NULL if the document is being closed
	if (spDoc == NULL && bOn)
		return false;
				
	if ((spDoc != NULL) && !IsDocInEditMode(spDoc))
		return false;

	if (bOn)
	{
		GetElements(spDoc);
		SetAllAttributes(true);
	}
	else
	{
		SetAllAttributes(false);
		m_ElementList.clear();
	}

	return true;
}
Пример #10
0
		/*
			To vshort (ideal) opamp nodes, the following conditions must be met
			- Input node = Output node (physically shorted)    OR
			- Branch count between the two nodes exceeds one
			
			If neither these conditions are met:
			- If branch count  between the two nodes is zero , vshorting is not possible
			- If branch count between the two nodes is one, branch must not consist of one element being the opamp segment in question.			
		
		  */
void circuit_t::VshortIdealOpampInputs ()
{


	list <element_t*> ooi_list = GetElements ( (ElementType)  CmpElement ("OOI"));					// Get a list of OON sections
	  
	/* 
	  Check that there is a branch between the output and the inverting node of all opamps
		*/  
	for (list<element_t*>::iterator i = ooi_list.begin(); i != ooi_list.end(); i++)
	{
		
		//TODO: case where the path between inv. and out. is indirect. i.e. check if there is ANY path between both points
		// maybe list <element_t*> GetOpampPath ()
		
		list<branch_t*> inv_to_out_branches = GetBranches ((*i)->OpampInputNode(), (*i)->OpampOutputNode()); 
						  
		// Input and output nodes are shorted (as in voltage follower), skip testing.
		if (SameOrVshortedNodes ((*i)->OpampInputNode(), (*i)->OpampOutputNode()))
		{
		  goto do_vshort;
		} /* if */

		// more than one branch between inv and out		  
		if  ( inv_to_out_branches.size() > 1)
		{		
		  goto do_vshort;
		} /* if */
		 
		// one branch with more than one member
		if (inv_to_out_branches.size() == 1  &&  (inv_to_out_branches.front()->items.size() > 1))
		{
		  goto do_vshort;
		} /* if */
		
		// one branch with more than one member
		if (inv_to_out_branches.size() == 1  &&  (inv_to_out_branches.front()->items.size() == 1) && inv_to_out_branches.front()->items.front().e != *i) 
		{
		  goto do_vshort;
		} /* if */
		
		no_vshort:


		error ("Saturating ideal opamp");

				
		continue;		// dont vshort
		
		
		/*
	      Set operation amplifier virtual shorts 
		 */
		do_vshort:

		if (!OpampHasPossibleDrivingSources(*i))
		{
			goto no_vshort;
		} /* if */
		
		
	//	cout << "Will vshort opamp..." << endl;
						
		element_t* oon = (*i)->OpampConjugate ();							// retrieve associated opamp element
				
		if (oon != NONE)
		{
			/*
				Set feedback flags 
				*/			
			(*i)->opamp_fedback = true;
			oon->opamp_fedback  = true;
			SetVirtualShort ((*i)->OpampInputNode(), oon->OpampInputNode());	// Virtual-short the non-output nodes of the opamp elements	
		} /* if */
		else
		{
		//		error ("Opamps must have a proper negative feedback to function.");
		} /* else */
		
	} /* for */
	
} /* circuit_t::VshortIdealOpampInputs */
Пример #11
0
int Account::GetSize()
{
    return GetElements().size();
}
Пример #12
0
Element* Account::GetElementAt(int index)
{
    return GetElements().at(index);
}
Пример #13
0
void IniSpawn::InitSpawn(const ieResRef DefaultArea)
{
	const char *s;

	Holder<DataFileMgr> inifile = GetIniFile(DefaultArea);
	if (!inifile) {
		strnuprcpy(NamelessSpawnArea, DefaultArea, 8);
		return;
	}

	s = inifile->GetKeyAsString("nameless","destare",DefaultArea);
	strnuprcpy(NamelessSpawnArea, s, 8);
	s = inifile->GetKeyAsString("nameless","point","[0.0]");
	int x,y;
	if (sscanf(s,"[%d.%d]", &x, &y)!=2) {
		x=0;
		y=0;
	}
	NamelessSpawnPoint.x=x;
	NamelessSpawnPoint.y=y;

	s = inifile->GetKeyAsString("nameless", "partyarea", DefaultArea);
	strnuprcpy(PartySpawnArea, s, 8);
	s = inifile->GetKeyAsString("nameless", "partypoint", "[0.0]");
	if (sscanf(s,"[%d.%d]", &x, &y) != 2) {
		x = NamelessSpawnPoint.x;
		y = NamelessSpawnPoint.y;
	}
	PartySpawnPoint.x = x;
	PartySpawnPoint.y = y;

	//35 - already standing
	//36 - getting up
	NamelessState = inifile->GetKeyAsInt("nameless","state",36);

	namelessvarcount = inifile->GetKeysCount("namelessvar");
	if (namelessvarcount) {
		NamelessVar = new VariableSpec[namelessvarcount];
		for (y=0;y<namelessvarcount;y++) {
			const char* Key = inifile->GetKeyNameByIndex("namelessvar",y);
			strnlwrcpy(NamelessVar[y].Name, Key, 32);
			NamelessVar[y].Value = inifile->GetKeyAsInt("namelessvar",Key,0);
		}
	}

	localscount = inifile->GetKeysCount("locals");
	if (localscount) {
		Locals = new VariableSpec[localscount];
		for (y=0;y<localscount;y++) {
			const char* Key = inifile->GetKeyNameByIndex("locals",y);
			strnlwrcpy(Locals[y].Name, Key, 32);
			Locals[y].Value = inifile->GetKeyAsInt("locals",Key,0);
		}
	}

	s = inifile->GetKeyAsString("spawn_main","enter",NULL);
	if (s) {
		ReadSpawnEntry(inifile.get(), s, enterspawn);
	}

	s = inifile->GetKeyAsString("spawn_main","exit",NULL);
	if (s) {
		ReadSpawnEntry(inifile.get(), s, exitspawn);
	}

	s = inifile->GetKeyAsString("spawn_main","events",NULL);
	if (s) {
		eventcount = CountElements(s,',');
		eventspawns = new SpawnEntry[eventcount];
		ieVariable *events = new ieVariable[eventcount];
		GetElements(s, events, eventcount);
		int ec = eventcount;
		while(ec--) {
			ReadSpawnEntry(inifile.get(), events[ec], eventspawns[ec]);
		}
		delete[] events;
	}
	//maybe not correct
	InitialSpawn();
}
Пример #14
0
//unimplemented tags (* marks partially implemented, # marks not working in original either):
//*check_crowd
// control_var
// spec_area
//*death_faction
//*death_team
// check_by_view_port
//*do_not_spawn
// hold_selected_point_key
// inc_spawn_point_index
//*find_safest_point
//#spawn_time_of_day
// exit - similar to enter[spawn], this is a spawn branch type (on exiting an area?)
// PST only
//*auto_buddy
//*detail_level
void IniSpawn::ReadCreature(DataFileMgr *inifile, const char *crittername, CritterEntry &critter) const
{
	const char *s;
	int ps;
	
	memset(&critter,0,sizeof(critter));

	//first assume it is a simple numeric value
	critter.TimeOfDay = (ieDword) inifile->GetKeyAsInt(crittername,"time_of_day", 0xffffffff);

	//at this point critter.TimeOfDay is usually 0xffffffff
	s = inifile->GetKeyAsString(crittername,"time_of_day",NULL);
	if (s && strlen(s)>=24) {
		ieDword value = 0;
		ieDword j = 1;
		for(int i=0;i<24 && s[i];i++) {
			if (s[i]=='0' || s[i]=='o') value |= j;
			j<<=1;
		}
		//turn off individual bits marked by a 24 long string scheduling
		//example: '0000xxxxxxxxxxxxxxxx00000000'
		critter.TimeOfDay^=value;
	}

	if (inifile->GetKeyAsBool(crittername,"do_not_spawn",false)) {
		//if the do not spawn flag is true, ignore this entry
		return;
	}

	s = inifile->GetKeyAsString(crittername,"detail_level",NULL);
	if (s) {
		ieDword level;

		switch(s[0]) {
			case 'h': case 'H': level = 2; break;
			case 'm': case 'M': level = 1; break;
			default: level = 0; break;
		}
		//If the detail level is lower than this creature's detail level,
		//skip this entry, creature_count is 0, so it will be ignored at evaluation of the spawn
		if (level>detail_level) {
			return;
		}
	}

	//all specvars are using global, but sometimes it is explicitly given
	s = inifile->GetKeyAsString(crittername,"spec_var",NULL);
	if (s) {
		if ((strlen(s)>9) && s[6]==':' && s[7]==':') {
			strnuprcpy(critter.SpecContext, s, 6);
			strnlwrcpy(critter.SpecVar, s+8, 32);
		} else {
			strnuprcpy(critter.SpecContext, "GLOBAL", 6);
			strnlwrcpy(critter.SpecVar, s, 32);
		}
	}

	//add this to specvar at each spawn
	ps = inifile->GetKeyAsInt(crittername,"spec_var_inc", 0);
	critter.SpecVarInc=ps;

	//use this value with spec_var_operation to determine spawn
	ps = inifile->GetKeyAsInt(crittername,"spec_var_value",0);
	critter.SpecVarValue=ps;
	//this operation uses DiffCore
	s = inifile->GetKeyAsString(crittername,"spec_var_operation","");
	critter.SpecVarOperator=GetDiffMode(s);
	//the amount of critters to spawn
	critter.TotalQuantity = inifile->GetKeyAsInt(crittername,"spec_qty",1);
	critter.SpawnCount = inifile->GetKeyAsInt(crittername,"create_qty",critter.TotalQuantity);

	//the creature resource(s)
	s = inifile->GetKeyAsString(crittername,"cre_file",NULL);
	if (s) {
		critter.creaturecount = CountElements(s,',');
		critter.CreFile=new ieResRef[critter.creaturecount];
		GetElements(s, critter.CreFile, critter.creaturecount);
	} else {
		Log(ERROR, "IniSpawn", "Invalid spawn entry: %s", crittername);
	}

	s = inifile->GetKeyAsString(crittername,"point_select",NULL);
	
	if (s) {
		ps=s[0];
	} else {
		ps=0;
	}

	s = inifile->GetKeyAsString(crittername,"spawn_point",NULL);
	if (s) {
		//expect more than one spawnpoint
		if (ps=='r') {
			//select one of the spawnpoints randomly
			int count = core->Roll(1,CountElements(s,']'),-1);
			//go to the selected spawnpoint
			while(count--) {
				while(*s++!=']') ;
			}
		}
		//parse the selected spawnpoint
		int x,y,o;
		if (sscanf(s,"[%d,%d:%d]", &x, &y, &o)==3) {
			critter.SpawnPoint.x=(short) x;
			critter.SpawnPoint.y=(short) y;
			critter.Orientation=o;
		} else
		if (sscanf(s,"[%d.%d:%d]", &x, &y, &o)==3) {
			critter.SpawnPoint.x=(short) x;
			critter.SpawnPoint.y=(short) y;
			critter.Orientation=o;
		} else
		if (sscanf(s,"[%d,%d]", &x, &y)==2) {
			critter.SpawnPoint.x=(short) x;
			critter.SpawnPoint.y=(short) y;
			critter.Orientation=core->Roll(1,16,-1);
		} else
		if (sscanf(s,"[%d.%d]", &x, &y)==2) {
			critter.SpawnPoint.x=(short) x;
			critter.SpawnPoint.y=(short) y;
			critter.Orientation=core->Roll(1,16,-1);
		}
	}
	
	//store or retrieve spawn point
	s = inifile->GetKeyAsString(crittername,"spawn_point_global", NULL);
	if (s) {
		switch (ps) {
		case 'e':
			critter.SpawnPoint.fromDword(CheckVariable(map, s+8,s));
			break;
		default:
			//see save_selected_point
			//SetVariable(map, s+8, s, critter.SpawnPoint.asDword());
			break;
		}
	}

	//take facing from variable
	s = inifile->GetKeyAsString(crittername,"spawn_facing_global", NULL);
	if (s) {
		switch (ps) {
		case 'e':
			critter.Orientation=(int) CheckVariable(map, s+8,s);
			break;
		default:
			//see save_selected_point
			//SetVariable(map, s+8, s, (ieDword) critter.Orientation);
			break;
		}
	}

	s = inifile->GetKeyAsString(crittername,"save_selected_point",NULL);
	if (s) {
		if ((strlen(s)>9) && s[6]==':' && s[7]==':') {
			SetVariable(map, s+8, s, critter.SpawnPoint.asDword());
		} else {
			SetVariable(map, s, "GLOBAL", critter.SpawnPoint.asDword());
		}
	}
	s = inifile->GetKeyAsString(crittername,"save_selected_facing",NULL);
	if (s) {
		if ((strlen(s)>9) && s[6]==':' && s[7]==':') {
			SetVariable(map, s+8, s, (ieDword) critter.Orientation);
		} else {
			SetVariable(map, s, "GLOBAL", (ieDword) critter.Orientation);
		}
	}

	//sometimes only the orientation is given, the point is stored in a variable
	ps = inifile->GetKeyAsInt(crittername,"facing",-1);
	if (ps!=-1) critter.Orientation = ps;
	ps = inifile->GetKeyAsInt(crittername, "ai_ea",-1);
	if (ps!=-1) critter.SetSpec[AI_EA] = (ieByte) ps;
	ps = inifile->GetKeyAsInt(crittername, "ai_team",-1);
	if (ps!=-1) critter.SetSpec[AI_TEAM] = (ieByte) ps;
	ps = inifile->GetKeyAsInt(crittername, "ai_general",-1);
	if (ps!=-1) critter.SetSpec[AI_GENERAL] = (ieByte) ps;
	ps = inifile->GetKeyAsInt(crittername, "ai_race",-1);
	if (ps!=-1) critter.SetSpec[AI_RACE] = (ieByte) ps;
	ps = inifile->GetKeyAsInt(crittername, "ai_class",-1);
	if (ps!=-1) critter.SetSpec[AI_CLASS] = (ieByte) ps;
	ps = inifile->GetKeyAsInt(crittername, "ai_specifics",-1);
	if (ps!=-1) critter.SetSpec[AI_SPECIFICS] = (ieByte) ps;
	ps = inifile->GetKeyAsInt(crittername, "ai_gender",-1);
	if (ps!=-1) critter.SetSpec[AI_GENDER] = (ieByte) ps;
	ps = inifile->GetKeyAsInt(crittername, "ai_alignment",-1);
	if (ps!=-1) critter.SetSpec[AI_ALIGNMENT] = (ieByte) ps;

	s = inifile->GetKeyAsString(crittername,"spec",NULL);
	if (s) {
		int x[9];
		
		ps = sscanf(s,"[%d.%d.%d.%d.%d.%d.%d.%d.%d]", x, x+1, x+2, x+3, x+4, x+5,
			x+6, x+7, x+8);
		if (ps == 0) {
			strnuprcpy(critter.ScriptName, s, 32);
			critter.Flags|=CF_CHECK_NAME;
			memset(critter.Spec,-1,sizeof(critter.Spec));
		} else {
			while(ps--) {
				critter.Spec[ps]=(ieByte) x[ps];
			}
		}
	}

	s = inifile->GetKeyAsString(crittername,"script_name",NULL);
	if (s) {
		strnuprcpy(critter.ScriptName, s, 32);
	}

	//iwd2 script names (override remains the same)
	//special 1 == area
	s = inifile->GetKeyAsString(crittername,"script_special_1",NULL);
	if (s) {
		strnuprcpy(critter.AreaScript,s, 8);
	}
	//special 2 == class
	s = inifile->GetKeyAsString(crittername,"script_special_2",NULL);
	if (s) {
		strnuprcpy(critter.ClassScript,s, 8);
	}
	//special 3 == general
	s = inifile->GetKeyAsString(crittername,"script_special_3",NULL);
	if (s) {
		strnuprcpy(critter.GeneralScript,s, 8);
	}
	//team == specific
	s = inifile->GetKeyAsString(crittername,"script_team",NULL);
	if (s) {
		strnuprcpy(critter.SpecificScript,s, 8);
	}

	//combat == race
	s = inifile->GetKeyAsString(crittername,"script_combat",NULL);
	if (s) {
		strnuprcpy(critter.RaceScript,s, 8);
	}
	//movement == default
	s = inifile->GetKeyAsString(crittername,"script_movement",NULL);
	if (s) {
		strnuprcpy(critter.DefaultScript,s, 8);
	}

	//pst script names
	s = inifile->GetKeyAsString(crittername,"script_override",NULL);
	if (s) {
		strnuprcpy(critter.OverrideScript,s, 8);
	}
	s = inifile->GetKeyAsString(crittername,"script_class",NULL);
	if (s) {
		strnuprcpy(critter.ClassScript,s, 8);
	}
	s = inifile->GetKeyAsString(crittername,"script_race",NULL);
	if (s) {
		strnuprcpy(critter.RaceScript,s, 8);
	}
	s = inifile->GetKeyAsString(crittername,"script_general",NULL);
	if (s) {
		strnuprcpy(critter.GeneralScript,s, 8);
	}
	s = inifile->GetKeyAsString(crittername,"script_default",NULL);
	if (s) {
		strnuprcpy(critter.DefaultScript,s, 8);
	}
	s = inifile->GetKeyAsString(crittername,"script_area",NULL);
	if (s) {
		strnuprcpy(critter.AreaScript,s, 8);
	}
	s = inifile->GetKeyAsString(crittername,"script_specifics",NULL);
	if (s) {
		strnuprcpy(critter.SpecificScript,s, 8);
	}
	s = inifile->GetKeyAsString(crittername,"dialog",NULL);
	if (s) {
		strnuprcpy(critter.Dialog,s, 8);
	}

	//flags
	if (inifile->GetKeyAsBool(crittername,"death_scriptname",false)) {
		critter.Flags|=CF_DEATHVAR;
	}
	if (inifile->GetKeyAsBool(crittername,"death_faction",false)) {
		critter.Flags|=CF_FACTION;
	}
	if (inifile->GetKeyAsBool(crittername,"death_team",false)) {
		critter.Flags|=CF_TEAM;
	}
	ps = inifile->GetKeyAsInt(crittername,"good_mod",0);
	if (ps) {
		critter.Flags|=CF_GOOD;
		critter.DeathCounters[DC_GOOD] = ps;
	}
	ps = inifile->GetKeyAsInt(crittername,"law_mod",0);
	if (ps) {
		critter.Flags|=CF_LAW;
		critter.DeathCounters[DC_LAW] = ps;
	}
	ps = inifile->GetKeyAsInt(crittername,"lady_mod",0);
	if (ps) {
		critter.Flags|=CF_LADY;
		critter.DeathCounters[DC_LADY] = ps;
	}
	ps = inifile->GetKeyAsInt(crittername,"murder_mod",0);
	if (ps) {
		critter.Flags|=CF_MURDER;
		critter.DeathCounters[DC_MURDER] = ps;
	}
	if(inifile->GetKeyAsBool(crittername,"auto_buddy", false)) {
		critter.Flags|=CF_BUDDY;
	}

	//don't spawn when spawnpoint is visible
	if (inifile->GetKeyAsBool(crittername,"ignore_can_see",false)) {
		critter.Flags|=CF_IGNORECANSEE;
	}
	//unsure, but could be similar to previous
	if (inifile->GetKeyAsBool(crittername,"check_view_port", false)) {
		critter.Flags|=CF_CHECKVIEWPORT;
	}
	//unknown, this is used only in pst
	if (inifile->GetKeyAsBool(crittername,"check_crowd", false)) {
		critter.Flags|=CF_CHECKCROWD;
	}
	//unknown, this is used only in pst
	if (inifile->GetKeyAsBool(crittername,"find_safest_point", false)) {
		critter.Flags|=CF_SAFESTPOINT;
	}
	//disable spawn based on game difficulty
	if (inifile->GetKeyAsBool(crittername,"area_diff_1", false)) {
		critter.Flags|=CF_NO_DIFF_1;
	}
	if (inifile->GetKeyAsBool(crittername,"area_diff_2", false)) {
		critter.Flags|=CF_NO_DIFF_2;
	}
	if (inifile->GetKeyAsBool(crittername,"area_diff_3", false)) {
		critter.Flags|=CF_NO_DIFF_3;
	}
}
Пример #15
0
void Saturn1b::AutoPilot(double autoT)
{
	TRACESETUP("Saturn1b::AutoPilot");

	const double GRAVITY=6.67259e-11;
	static int first_time=1;
	static int t = 0;
	static int out_level=0;
	double level=0.;
	double altitude;
	double pitch;
	double pitch_c;
	double heading;
	double bank;
	VECTOR3 rhoriz;

	double TO_HDG = agc.GetDesiredAzimuth();

	AltitudePREV = altitude = GetAltitude();
	VESSELSTATUS vsp;
	GetStatus(vsp);
	double totalRot=0;
	totalRot=vsp.vrot.x+vsp.vrot.y+vsp.vrot.z;
	if (fabs(totalRot) >= 0.0025){
		StopRot = true;
	}

	// This vector rotation will be used to tell if heads up (rhoriz.z<0) or heads down.
	HorizonRot(_V(1,0,0), rhoriz);

	//
	// Shut down the engines when we reach the desired
	// orbit.
	//

	double apogee, perigee;
	OBJHANDLE ref = GetGravityRef();
	GetApDist(apogee);
	GetPeDist(perigee);
	apogee = (apogee - oapiGetSize(ref)) / 1000.;
	perigee = (perigee - oapiGetSize(ref)) / 1000.;

	// We're aiming for periapsis and shutdown when apoapsis is reached at the opposite side of the orbit
	if (apogee >= agc.GetDesiredApogee() && perigee >= agc.GetDesiredPerigee() - 0.1) {
		// See Saturn::CheckForLaunchShutdown()
		if (GetThrusterLevel(th_main[0]) > 0){
			SetThrusterLevel(th_main[0], 0);			
			if (oapiGetTimeAcceleration() > 1.0)
				oapiSetTimeAcceleration(1.0);

			agc.LaunchShutdown();

			// Reset autopilot commands
			AtempP  = 0;
			AtempY  = 0;
			AtempR  = 0;			
		}
		return;
	}

	// navigation
	pitch = GetPitch();
	pitch = pitch*180./PI;
	//sprintf(oapiDebugString(), "Autopilot %f", altitude);
	// guidance
	pitch_c = GetCPitch(autoT);
	// control
	if (altitude > 4500) {
		// Damp roll motion
		bank = GetBank();
		bank = bank *180. / PI;
		if (bank > 90) bank = bank - 180.;
		else if (bank < -90) bank = bank + 180.;
		AtempR = -bank / 20.0;
		if (fabs(bank) < 0.3) AtempR = 0;

		// navigation
		pitch = GetPitch();
		pitch = pitch * 180. / PI;

		if (IGMEnabled) {
			VECTOR3 target;
			double pit, yaw;
			double bradius = oapiGetSize(ref);
			double bmass = oapiGetMass(ref);
			double mu = GRAVITY * bmass;
			// Aim for periapsis
			double altco = agc.GetDesiredPerigee() * 1000.;
			double velo = sqrt(mu / (bradius + altco));
			target.x = velo;
			target.y = 0.0;
			target.z = altco;
			LinearGuidance(target, pit, yaw);
			AtempP=(pit * DEG - pitch) / 30.0;
			if (AtempP < -0.15) AtempP = -0.15;
			if (AtempP >  0.15) AtempP =  0.15;
		}
		else {
			 // guidance
			pitch_c = GetCPitch(autoT);

			 // control
			double SatApo;
			GetApDist(SatApo);

			if ((SatApo >= ((agc.GetDesiredApogee() *.90) + ERADIUS)*1000) || MissionTime >= IGMStartTime)
				IGMEnabled = true;
		
			level = pitch_c - pitch;

			//sprintf(oapiDebugString(), "Autopilot Pitch Mode%f", elemSaturn1B.a );

			if (fabs(level)<10 && StopRot){	// above atmosphere, soft correction
				AtempP = 0.0;
				AtempR = 0.0;
				AtempY = 0.0;
				StopRot = false;
			}
			if (fabs(level)<0.05){	// above atmosphere, soft correction
				AtempP = 0.0;
				AtempR = 0.0;
				AtempY = 0.0;
			}
			else if (level>0 && fabs(vsp.vrot.z) < 0.09){
				AtempP = -(fabs(level) / 10.);
				if (AtempP < -1.0)AtempP = -1.0;
				if (rhoriz.z>0) AtempP = -AtempP;
			}
			else if (level<0 && fabs(vsp.vrot.z) < 0.09) {
				AtempP = (fabs(level) / 10.);
				if (AtempP > 1.0) AtempP = 1.0;
				if (rhoriz.z>0) AtempP = -AtempP;
			}
			else {
				AtempP = 0.0;
				AtempR = 0.0;
				AtempY = 0.0;
			}
			// sprintf(oapiDebugString(), "autoT %f AtempP %f AtempR %f AtempY %f altitude %f pitch %f pitch_c %f", 
			//  					       autoT, AtempP, AtempR, AtempY, altitude, pitch, pitch_c);
		}
	}
	// sprintf(oapiDebugString(), "Alt %f Pitch %f Roll %f Yaw %f autoT %f", altitude, AtempP, AtempR, AtempY, autoT);

	double slip;
	VECTOR3 az;
	VECTOR3 up, north, east, ygl, zgl, zerogl;
	OBJHANDLE hbody=GetGravityRef();
	double bradius=oapiGetSize(hbody);

	// set up our reference frame
	Local2Global(_V(0.0, 0.0, 0.0), zerogl);
	Local2Global(_V(0.0, 1.0, 0.0), ygl);
	Local2Global(_V(0.0, 0.0, 1.0), zgl);
	ygl=ygl-zerogl;
	zgl=zgl-zerogl;

	oapiGetHeading(GetHandle(),&heading);
	heading = heading*180./PI;

	// Inclination control
	static int incinit = 0; 
	static ELEMENTS elemlast; 
	static double incratelast;

	ELEMENTS elem;
	GetElements(ref, elem, 0, 0, FRAME_EQU);
	double incrate = (elem.i - elemlast.i) / oapiGetSimStep();
	double incraterate = (incrate - incratelast) / oapiGetSimStep();	
	double target = (agc.GetDesiredInclination() - elem.i * DEG) / (FirstStageShutdownTime - MissionTime);

	if (agc.GetDesiredInclination() != 0 && autoT > 45) {	
		if (incinit < 2) {
			incinit++;
			AtempY = 0;
		} else {
			if (autoT < FirstStageShutdownTime - 10) {	
				AtempY = (incrate * DEG - target) / 0.7 + incraterate * DEG / 2.;
				if (AtempY < -0.1) AtempY = -0.1;
				if (AtempY >  0.1) AtempY =  0.1;
			} else if (autoT < FirstStageShutdownTime + 10) {	
				AtempY = 0;
			} else {
				AtempY = (elem.i * DEG - agc.GetDesiredInclination()) / 7. + (incrate * DEG ) / 1.;
				if (AtempY < -0.01) AtempY = -0.01;
				if (AtempY >  0.01) AtempY =  0.01;
			}
		}
	}
	
	elemlast = elem;
	incratelast = incrate;

	// stage handling
	switch (stage){
		case LAUNCH_STAGE_ONE:
			GetRelativePos(hbody, up);
			up=Normalize(up);
			agc.EquToRel(PI/2.0, 0.0, bradius, north);
			north=Normalize(north);
			east=Normalize(CrossProduct(north, up));
			north=Normalize(CrossProduct(up, east));
			az=east*sin(TO_HDG*RAD)-north*cos(TO_HDG*RAD);
			if(autoT < 60.0) normal=Normalize(CrossProduct(up, az));

			slip=GetSlipAngle()*DEG;

			if(autoT < 10.) {
				AtempR=0.0;
				AtempY=0.0;
				// cancel out the yaw maneuver...
				AtempY=(-0.4+asin(zgl*normal)*DEG)/20.0;
			}

			if(autoT > 10.0 && autoT < 30.0) {
				// roll program
				AtempR=asin(ygl*normal)*DEG/20.0;
				AtempY=asin(zgl*normal)*DEG/20.0;
				if (AtempR < -0.25) AtempR = -0.25;
				if (AtempR >  0.25) AtempR =  0.25;
			}

			if(autoT > 30.0 && autoT < 45.0) {
				//pitch and adjust for relative wind
				AtempR=asin(ygl*normal)*DEG/20.0;
				//AtempY=(slip+asin(zgl*normal)*DEG)/20.0;
				AtempY=(TO_HDG-(heading+slip))/20.0;
				if (AtempR < -0.25) AtempR = -0.25;
				if (AtempR >  0.25) AtempR =  0.25;
			}
			pitch = GetPitch();
			pitch=pitch*180./PI;
			pitch_c=GetCPitch(autoT);
			AtempP = (pitch_c - pitch);

			// Fix for LC 39
			if (autoT < 10 && heading > 180)
				AtempP = -(180. - pitch_c - pitch);

			if (AtempP > 1.0) AtempP = 1.0;
			if (AtempP < -1.0) AtempP = -1.0;

			// zero angle-of-attack...
			if(autoT > 45.0 && autoT < 115.0) {

				/// \todo Disabled for now, the Saturn 1B doesn't seem to do that...
				//double aoa=GetAOA()*DEG;
				//pitch_c=pitch+aoa-0.3;

				AtempP=(pitch_c - pitch) / 5.0;
				if(AtempP < -0.2) AtempP = -0.2;
				if(AtempP >  0.2) AtempP = 0.2;
				// sprintf(oapiDebugString(), " pitch=%.3f pc=%.3f ap=%.3f", pitch, pitch_c, AtempP);
			}
			if (autoT > 115.0) {
				if (autoT < 120.0) {
					if (AtempP < -0.1) AtempP = -0.1;
					if (AtempP >  0.1) AtempP =  0.1;
				} else {
					if (AtempP < -0.2) AtempP = -0.2;
					if (AtempP >  0.2) AtempP =  0.2;
				}
				normal=Normalize(CrossProduct(Normalize(vsp.rpos), Normalize(vsp.rvel)));
			}
			// sprintf(oapiDebugString(), "roll=%.3f yaw=%.3f slip=%.3f sum=%.3f hdg+slip=%.3f hdg=%.3f ay=%.3f", 
			//     asin(ygl*normal)*DEG, asin(zgl*normal)*DEG, slip, slip+asin(zgl*normal)*DEG, heading+slip, heading, AtempY);
			// sprintf(oapiDebugString(), "autoT %f AtempP %f AtempR %f AtempY %f altitude %f pitch %f pitch_c %f rhoriz.z %f", 
			//     autoT, AtempP, AtempR, AtempY, altitude, pitch, pitch_c, rhoriz.z);
			/*
			char buffer[80];
			sprintf(buffer,"AtempP %f AtempR %f AtempY %f", AtempP, AtempR, AtempY);	
			TRACE(buffer);
			*/

			AttitudeLaunch1();
			break;

		case LAUNCH_STAGE_SIVB:
			AttitudeLaunchSIVB();
			break;
	}

	// sprintf(oapiDebugString(), "AP - inc %f rate %f target %f raterate %f AtempP %f AtempR %f AtempY %f", elem.i * DEG, incrate * DEG, target, incraterate * DEG, AtempP, AtempR, AtempY);
	// sprintf(oapiDebugString(), "AP - pitch %f pitch_c %f heading %f AtempP %f AtempR %f AtempY %f", pitch, pitch_c, heading, AtempP, AtempR, AtempY);
}
Пример #16
0
bool VertexBuffer::SetSize(unsigned vertexCount, unsigned elementMask, bool dynamic)
{
    return SetSize(vertexCount, GetElements(elementMask), dynamic);
}