struct node* SortedList(struct node* sublist1, struct node* sublist2)
{
	struct node* orderlist = NULL;
	if (sublist1 == NULL)//base case
		return(sublist2);
	else if (sublist2 == NULL)
		return(sublist1);
	if (sublist1->num <= sublist2->num)
	{
		orderlist = sublist1;
		orderlist->next = SortedList(sublist1->next, sublist2);
	}
	else
	{
		orderlist = sublist2;
		orderlist->next = SortedList(sublist1, sublist2->next);
	}
	return(orderlist);
}
struct node* MergeSort(struct node** headref)
{
	struct node* subhead = *headref;
	struct node* sublist1;
	struct node* sublist2;
	if ((subhead == NULL) || (subhead->next == NULL))//basecase
	{
		return *headref;
	}
	divide_list(subhead, &sublist1, &sublist2);
	MergeSort(&sublist1);// Recursively sort the sublists
	MergeSort(&sublist2);
	*headref = SortedList(sublist1, sublist2);//merging sublists.
	return *headref;
}
Exemple #3
0
static Term finda2(List pl, int del)
{
	int pli, ii;
	List l;
	pli=ListLength(pl);
	mmmpos=0;
	for(ii=0;ii<LagrHashSize;ii++)
	{
	
		for(l=lagr_hash[ii];l;l=ListTail(l))
		{
			List cpl=CompoundArg1(ListFirst(l));
			List vpl=0;
			List ll1,ll2;
			int pos=1;

			if(cpl==0 || ListLength(cpl)!=pli)
				continue;
			for(ll1=cpl;ll1;ll1=ListTail(ll1),pos++)
			{
				Atom a,prp;
				a=CompoundArg1(ListFirst(ll1));
				prp=GetAtomProperty(a,PROP_TYPE);
				if(is_compound(prp)&&CompoundName(prp)==OPR_FIELD &&
					CompoundArg2(prp)==NewInteger(4))
					a=CompoundArg1(prp);
				if(a==mmm)
					mmmpos=pos;
				vpl=AppendLast(vpl,a);
			}
				
			vpl=SortedList(vpl, acmp);

			for(ll1=pl,ll2=vpl;ll1;ll1=ListTail(ll1),ll2=ListTail(ll2))
				if(ListFirst(ll1)!=ListFirst(ll2))
					break;
			if(is_empty_list(ll1))
				break;
		}
	if(l)
		break;
	}
	
	if(l && del)
		lagr_hash[ii]=CutFromList(lagr_hash[ii],l);
	
	return l;
}
Exemple #4
0
void alg2_decommon_s(Term a2)
	{
	Term cfl;
	List l;
	
	cfl=ConsumeCompoundArg(a2,3);
	if(is_empty_list(cfl))
		return;
	
	for(l=CompoundArgN(a2,5);l;l=ListTail(l))
		{
		List pfl;
		List l1,l2;
		
		pfl=ConsumeCompoundArg(ListFirst(l),2);
		for(l1=cfl;l1;l1=ListTail(l1))
			{
			Atom p;
			p=CompoundArg1(ListFirst(l1));
			for(l2=pfl;l2;l2=ListTail(l2))
				{
				if(CompoundArg1(ListFirst(l2))==p)
					{
					int pw;
					pw=IntegerValue(CompoundArg2(ListFirst(l2)))
						+IntegerValue(CompoundArg2(ListFirst(l1)));
					SetCompoundArg(ListFirst(l2),2,NewInteger(pw));
					break;
					}
				}
			if(is_empty_list(l2))
				pfl=AppendFirst(pfl,CopyTerm(ListFirst(l1)));
			}
	rr:
		for(l1=pfl;l1;l1=ListTail(l1))
			if(CompoundArg2(ListFirst(l1))==NewInteger(0))
				{
				pfl=CutFromList(pfl,l1);
				goto rr;
				}
		pfl=SortedList(pfl,prtcmp);
		SetCompoundArg(ListFirst(l),2,pfl);
		}
		
	FreeAtomic(cfl);
		
	}
Exemple #5
0
Term ProcDelVertex(Term t, List ind)
{
	List l, pl;
	
	if(lagr_hash==NULL)
	{
		ErrorInfo(107);
		puts("DelVertex: no vertices");
		return 0;
	}
	
	
	if(!is_compound(t)||CompoundArity(t)!=1)
	{
		ErrorInfo(107);
		puts("wrong call to DelVertex");
		return 0;
	}
	
	pl=CompoundArg1(t);
	if(!is_list(pl))
	{
		ErrorInfo(107);
		puts("wrong call to DelVertex");
		return 0;
	}
	
	for(l=pl;l;l=ListTail(l))
		if(is_function(ListFirst(l),0))
			ChangeList(l,CallFunction(ListFirst(l),0));
	
	pl=SortedList(pl,acmp);
	
	l=finda2(pl,1);
	
	if(is_empty_list(l))
	{
	WarningInfo(108);printf("DelVertex: vertex ");
	WriteTerm(pl); puts(" not found");
	return 0;
	}
	
	
	return 0;
}
void GenerateRandomItemTables (CUniverse &Universe, CXMLElement *pCmdLine)
	{
	int i;
	printf("RANDOM ITEM TABLES\n\n");

	//	Create a sorted list of item types

	CSymbolTable SortedList(FALSE, TRUE);
	for (i = 0; i < Universe.GetItemTypeCount(); i++)
		{
		CItemType *pType = Universe.GetItemType(i);
		SortedList.AddEntry(pType->GetSortName(), (CObject *)pType);
		}

	//	Create the tables

	for (int iLevel = 1; iLevel <= MAX_ITEM_LEVEL; iLevel += 2)
		{
		for (TableTypes iTable = tableTypesFirst; iTable <= tableTypesCount; iTable = (enum TableTypes)((int)iTable + 1))
			{
			int iCount = 0;
			ItemEntry Table[100];

			//	Fill the table with entries for each 
			//	item at this level

			for (i = 0; i < SortedList.GetCount(); i++)
				{
				CItemType *pType = (CItemType *)SortedList.GetValue(i);
				int iScore;
				if (iCount < 100 && ItemInTable(pType, iTable, iLevel, &iScore))
					{
					Table[iCount].pType = pType;
					Table[iCount].iScore = iScore;
					iCount++;
					}
				}

			//	Compute total score

			int iTotalScore = 0;
			for (i = 0; i < iCount; i++)
				iTotalScore += Table[i].iScore;

			//	Compute chance

			for (i = 0; i < iCount; i++)
				{
				Table[i].iChance = (Table[i].iScore * 100) / iTotalScore;
				Table[i].iRemainder = (Table[i].iScore * 100) % iTotalScore;
				}

			//	Compute remainder

			int iTotalChance = 0;
			for (i = 0; i < iCount; i++)
				iTotalChance += Table[i].iChance;

			while (iTotalChance < 100)
				{
				int iBestRemainder = 0;
				int iBestEntry = -1;

				for (i = 0; i < iCount; i++)
					if (Table[i].iRemainder > iBestRemainder)
						{
						iBestRemainder = Table[i].iRemainder;
						iBestEntry = i;
						}

				Table[iBestEntry].iChance++;
				Table[iBestEntry].iRemainder = 0;
				iTotalChance++;
				}

			//	Title

			if (iCount > 0)
				{
				switch (iTable)
					{
					case tableArmorAndWeapons:
						printf("LEVEL %d: ARMOR AND WEAPONS\n\n", iLevel);
						break;

					case tableMiscItems:
						printf("LEVEL %d: MISCELLANEOUS ITEMS\n\n", iLevel);
						break;

					case tableUsefulItems:
						printf("LEVEL %d: USEFUL ITEMS\n\n", iLevel);
						break;
					}

				//	Print table

				for (i = 0; i < iCount; i++)
					if (Table[i].iChance > 0)
						{
						//DWORD dwFlags;
						printf("%d\t%s\n", 
								Table[i].iChance,
								//Table[i].pType->GetName(&dwFlags, true).GetASCIIZPointer());
								Table[i].pType->GetSortName().GetASCIIZPointer());
						}

				printf("\n");
				}
			}
		}
	}
Exemple #7
0
static int set_ppl(void)
	{
	List l;
	
	if(PROP_PPL==0) PROP_PPL=NewAtom("pprtlst",0);
	if(prop_gened)
		return 1;
	if(vlist==0) 
		
	{
		vlist=all_vert_list();
		for(l=vlist; !is_empty_list(l); l=ListTail(l))
		{
		Term a2;
		a2=ListFirst(l); 
		alg2_common_s(a2);
		alg2_common_n(a2);
		alg2_red_cos(a2);
		alg2_red_orth(a2);
		}
	}
			
	for(l=vlist; !is_empty_list(l); l=ListTail(l))
		{
		List pl,l1,l2,lr;
		
		pl=CompoundArg1(ListFirst(l));
		if(ListLength(pl)<3 || CompoundArg2(ListFirst(l))==NewInteger(0) ||
		 is_empty_list(CompoundArgN(ListFirst(l),5)))
			continue;
			

#ifdef DBG_PPL
		WriteVertex(pl); printf(": ");
#endif
		
		l1=pl;
		while(!is_empty_list(l1))
			{
			Atom pp,app;
			Term prop;
			pp=CompoundArg1(ListFirst(l1));
			prop=GetAtomProperty(pp,PROP_TYPE);
			app=remcc(pp);
			if(!ListMember(plist,app))
				plist=AppendFirst(plist,app);
			
#ifdef DBG_PPL
			WriteTerm(app); printf(" -> ");
#endif
			
			
			lr=NewList();
			l2=pl;
			while(!is_empty_list(l2))
				{
				Atom a;
				if(l2==l1)
					{
					l2=ListTail(l2);
					continue;
					}
				a=remcc(CompoundArg1(ListFirst(l2)));
				lr=AppendLast(lr,a);
				l2=ListTail(l2);
				}
			
			prop=GetAtomProperty(app,PROP_PPL);
			if(prop==0)
				SetAtomProperty(app,PROP_PPL,AppendFirst(NewList(),lr));
			else
				AppendLast(prop,lr);
#ifdef DBG_PPL
			WriteTerm(lr); printf(" ");
#endif
			while(!is_empty_list(l1) && 
					remcc(CompoundArg1(ListFirst(l1)))==app)
				l1=ListTail(l1);
			}
#ifdef DBG_PPL
		puts("");
#endif
		}
		
	if(ListLength(plist)>1)		
		plist=SortedList(plist,p__cmp);
		
	prop_gened=1;
	return 1;
	}
Exemple #8
0
Term ProcChVertex(Term t, List ind)
{
	List l, pl, ml;
	Term rpl;
	Atom a1, a2;
	int pli;
	int ii;
	
	if(lagr_hash==NULL)
	{
		ErrorInfo(107);
		puts("ChVertex: no vertices");
		return 0;
	}
	
	
	if(!is_compound(t)||CompoundArity(t)!=2)
	{
		ErrorInfo(107);
		puts("wrong call to ChVertex");
		return 0;
	}
	
	pl=CompoundArg1(t);
	for(l=pl;l;l=ListTail(l))
		if(is_function(ListFirst(l),0))
			ChangeList(l,CallFunction(ListFirst(l),0));
	
	rpl=CompoundArg2(t);
	if(!is_list(pl)|| !is_compound(rpl) || CompoundArity(rpl)!=2)
	{
		ErrorInfo(107);
		puts("wrong call to ChVertex");
		return 0;
	}
	a1=CompoundArg1(rpl);a2=CompoundArg2(rpl);
	if(!is_parameter(a1)||!is_parameter(a2))
	{
		ErrorInfo(107);
		puts("wrong call to ChVertex");
		return 0;
	}

	pl=SortedList(pl,acmp);
	
	l=finda2(pl,0);
	
	if(is_empty_list(l))
	{
	WarningInfo(108);printf("ChVertex: vertex ");
	WriteTerm(pl); puts(" not found");
	return 0;
	}
	
	ml=CompoundArgN(ListFirst(l),5);
	ii=0;
		
	for(l=ml;l;l=ListTail(l))
	{
		List l1;
		for(l1=CompoundArg2(ListFirst(l));l1;l1=ListTail(l1))
			if(CompoundArg1(ListFirst(l1))==a1)
			{
				SetCompoundArg(ListFirst(l1),1,a2);ii++;
			}
	}
	
	
	if(ii==0)
	{
	WarningInfo(107);printf("ChVertex: vertex ");WriteTerm(pl);
			printf("has no '%s' within.\n",AtomValue(a1));
	}	
	
	return 0;
}
Exemple #9
0
Term ProcCoefVrt(Term t, List ind)
{
	List l,pl,ml;
	int  ii;
	Term a2;
	int g=0, g5=0, re=0, im=0, abbr=0, cmplx=0;
	
	if(!is_compound(t) || CompoundArity(t)>2 || !is_list(CompoundArg1(t)))
	{
		ErrorInfo(0);
		puts("wrong parameters of CoefVrt function.");
		return 0;
	}
	
	if(lagr_hash==NULL)
	{
		ErrorInfo(107);
		puts("CoefVrt: no vertices");
		return 0;
	}
	
	mmm=0;
	if(CompoundArity(t)==2)
	{
		List ol=CompoundArg2(t);
		if(!is_list(ol))
		{
		ErrorInfo(107);
		puts("CoefVrt: second argument is not a list.");
		return 0;
		}
		for(;ol;ol=ListTail(ol))
		{
			Term o=ListFirst(ol);
			if(is_compound(o))
			{
				o=CompoundArg1(o);
				if(!is_atom(o) || !is_particle(o,0))
				{
					ErrorInfo(0);
					printf("CoefVrt: ");WriteTerm(o);
					puts(" is not a particle.\n");
					return 0;
				}
				mmm=o;
				continue;
			}
			if(!is_atom(o))
			{
				ErrorInfo(0);
				printf("CoefVrt: ");WriteTerm(o);
				puts(" is not an option.\n");
				return 0;
			}
			if(strcmp("gamma",AtomValue(o))==0)
			{
				g++;
				continue;
			}
			if(strcmp("gamma5",AtomValue(o))==0)
			{
				g5++;
				continue;
			}
			if(strcmp("re",AtomValue(o))==0)
			{
				re++;
				continue;
			}
			if(strcmp("im",AtomValue(o))==0)
			{
				im++;
				continue;
			}
			if(strcmp("abbr",AtomValue(o))==0)
			{
				abbr++;
				continue;
			}
			{
				ErrorInfo(0);
				printf("CoefVrt: ");WriteTerm(o);
				puts(" is not an option.\n");
				return 0;
			}
		}
	}
			
	if(re&&im)
		re=im=0;
			
	pl=ConsumeCompoundArg(t,1);
	for(l=pl;l;l=ListTail(l))
		if(is_function(ListFirst(l),0))
			ChangeList(l,CallFunction(ListFirst(l),0));

/*	for(l=pl;l;l=ListTail(l))
	{
		Term aa=ListFirst(l);
		if(is_compound(aa)&&CompoundName(aa)==A_ANTI)
			ChangeList(l,GetAtomProperty(CompoundArg1(aa),A_ANTI));
	}*/
	pl=SortedList(pl,acmp);
	
	l=finda2(pl,0);
	
	if(mmm && !mmmpos)
	{
		ErrorInfo(0);
		printf("CoefVrt: particle ");
		WriteTerm(mmm);
		puts(" not found in the vertex");
		return 0;
	}
	
		
	
	
	if(is_empty_list(l))
	{
	ErrorInfo(108);
	printf("CoefVrt: vertex ");
	WriteTerm(pl);
	puts(" not found");
	return NewInteger(0);
	}
	
	a2=CopyTerm(ListFirst(l));
	
	
	alg2_symmetrize(a2);
	alg2_common_n(a2);
	{
		int sv=kill_gamma_pm;
		kill_gamma_pm=1;
		alg2_red_1pm5(a2);
		kill_gamma_pm=sv;
	}
	alg2_recommon_n(a2);
		
	ml=ConsumeCompoundArg(a2,5);
	for(l=ml;l;l=ListTail(l))
	{
		List l1,ll;
		int tg=0, tg5=0, tm=0;
		for(l1=CompoundArgN(ListFirst(l),3);l1;l1=ListTail(l1))
		{
			Term tt=ListFirst(l1);
			if(CompoundName(tt)==OPR_SPECIAL && CompoundArg1(tt)==A_GAMMA)
				tg++;
			if(CompoundName(tt)==OPR_SPECIAL && CompoundArg1(tt)==A_GAMMA5)
				tg5++;
			if(CompoundName(tt)==A_MOMENT && CompoundArg1(tt)==
						NewInteger(mmmpos))
				tm++;
		}
		if(g!=tg || g5!=tg5 || (mmm && !tm))
		{
			SetCompoundArg(ListFirst(l),1,0);
			continue;
		}
		if(!re && !im)
			continue;
		for(l1=CompoundArg2(ListFirst(l));l1;l1=ListTail(l1))
			if(GetAtomProperty(CompoundArg1(ListFirst(l1)),A_ANTI))
				cmplx++;
	}

	if( (re||im) && !cmplx)
		for(l=ml;l;l=ListTail(l))
		{
		List ll,l1;
		if(CompoundArg1(ListFirst(l))==0)
			continue;
		ll=ConsumeCompoundArg(ListFirst(l),2);
		for(l1=ll;l1;l1=ListTail(l1))
			if(CompoundArg1(ListFirst(l1))==A_I)
				break;
		if( (re && l1) || (im && !l1) )
			SetCompoundArg(ListFirst(l),1,0);
		if(im && l1)
			ll=CutFromList(ll,l1);
		SetCompoundArg(ListFirst(l),2,ll);
		}

		
rpt:
	for(l=ml;l;l=ListTail(l))
		if(CompoundArg1(ListFirst(l))==0)
		{
			ml=CutFromList(ml,l);
			break;
		}
	if(l)
		goto rpt;
	
	SetCompoundArg(a2,5,ml);
	alg2_recommon_n(a2);
	alg2_common_s(a2);
	alg2_red_cos(a2);
	alg2_red_orth(a2);
	alg2_red_sico(a2);
	alg2_red_comsico(a2);
	alg2_recommon_n(a2);
	if(abbr)
	{
		int trisv=opTriHeu;
		alg2_eval_vrt(a2);
		doing_abbr=0;
		opTriHeu=trisv;
	}
	
	{
	int n,d;
	Term cf;
	Term res;
	n=IntegerValue(CompoundArg1(CompoundArg2(a2)));
	d=IntegerValue(CompoundArg2(CompoundArg2(a2)));
	cf=l2expr(CompoundArgN(a2,3),n);
	ml=CompoundArgN(a2,5);
	if(ml==0)
		return NewInteger(0);
	res=l2expr(CompoundArg2(ListFirst(ml)),
			IntegerValue(CompoundArg1(ListFirst(ml))));
	for(l=ListTail(ml);l;l=ListTail(l))
	{
		Term ccc;
		n=IntegerValue(CompoundArg1(ListFirst(l)));
		ccc=l2expr(CompoundArg2(ListFirst(l)),n>0?n:-n);
		if(n>0)
			res=MakeCompound2(OPR_PLUS,res,ccc);
		else
			res=MakeCompound2(OPR_MINUS,res,ccc);
	}
	if(res==NewInteger(1))
		res=cf;
	else
		res=MakeCompound2(OPR_MLT,cf,res);
	if(d!=1)
		res=MakeCompound2(OPR_DIV,res,NewInteger(d));
	if( (im||re) && cmplx)
		res=MakeCompound1(NewAtom(re?"creal":"cimag",0),res);
		
	return res;
	}
	return a2;
	
}
Exemple #10
0
void alg1_opt_let(Term a1)
{
	List l,l1,l2,lm=ConsumeCompoundArg(a1,1);
	List nl=0;
	Label mylbl=NewLabel();
	
	/*printf("%d -> ",ListLength(lm));*/
	
	for(l=lm;l;l=ListTail(l))
	{
		Term m1=ListFirst(l);
		int n,d,g;
		List ln=ConsumeCompoundArg(m1,3);
		List ld=ConsumeCompoundArg(m1,4);
		Term f1=0, f2=0, w=0;
		n=IntegerValue(CompoundArg1(m1));
		d=IntegerValue(CompoundArg2(m1));
				
	rpt1:
		for(l1=ld;l1;l1=ListTail(l1))
		{
			int n=ListMember(ln,ListFirst(l1));
			if(n)
			{
				ld=CutFromList(ld,l1);
				l1=ListNthList(ln,n);
				ln=CutFromList(ln,l1);
				goto rpt1;
			}
			if(CompoundArg2(ListFirst(l1))==A_SQRT2)
			{
				Term t=ListFirst(l1);
				ChangeList(l1,0);
				ld=CutFromList(ld,l1);
				ln=AppendFirst(ln,t);
				d*=2;
				goto rpt1;
			}
		}
	rpt2:
		for(l1=ln;l1;l1=ListTail(l1))
			if(CompoundArg2(ListFirst(l1))==A_SQRT2)
			{
				List l2;
				for(l2=ListTail(l1);l2;l2=ListTail(l2))
					if(CompoundArg2(ListFirst(l2))==A_SQRT2)
					{
						ln=CutFromList(ln,l1);
						ln=CutFromList(ln,l2);
						n*=2;
						goto rpt2;
					}
				}
		g=gcf(n,d);
		n/=g;
		d/=g;
		
		for(l1=ln;l1;l1=l1?ListTail(l1):0)
		{
			Term sp=ListFirst(l1);
			if(CompoundName(sp)==OPR_PARAMETER)
				continue;
			if(CompoundName(sp)==OPR_FIELD)
			{
				if(f1==0)
					f1=l1;
				else if(f2==0)
					f2=l1;
				else
				{
					ErrorInfo(1280);
					puts("bad let-sub: >2 prtc");
					return;
				}
				continue;
			}
			if(CompoundName(sp)==OPR_WILD)
			{
				if(w)
				{
					ErrorInfo(1281);
					puts("bad let-sub: unk spec");
					return;
				}
				w=l1;
				continue;
			}
			ErrorInfo(110);
			WriteTerm(sp);puts(" : bad let: unk stuff");
			return;
		}
		
		if(f2==0)
		{
			ErrorInfo(112);
			puts("bad let-subs: not 2 prtc");
			return;
		}
		
		l1=f1;f1=ListFirst(f1);ChangeList(l1,0);ln=CutFromList(ln,l1);
		l1=f2;f2=ListFirst(f2);ChangeList(l1,0);ln=CutFromList(ln,l1);
		if(w)
		{l1=w;w=ListFirst(w);ChangeList(l1,0);ln=CutFromList(ln,l1);}
		
		ln=SortedList(ln,prmcmp);
		ld=SortedList(ld,prmcmp);
		
		if((GetAtomProperty(CompoundArg2(f1),A_ANTI)==CompoundArg2(f1) ||
				GetAtomProperty(CompoundArg2(f2),A_ANTI)==CompoundArg2(f2))
			&& strcmp(AtomValue(CompoundArg2(f1)),AtomValue(CompoundArg2(f2)))>0)
		{
			Term tmp=f1;
			f1=f2;
			f2=tmp;
		}
		
		if(ListLength(CompoundArg1(f1))==1 && ListLength(CompoundArg1(f1))==1)
		{
			Term i1=ListFirst(CompoundArg1(f1));
			Term i2=ListFirst(CompoundArg1(f2));
			if(CompoundName(CompoundArg1(i1))!=A_COLOR ||
				CompoundName(CompoundArg1(i2))!=A_COLOR ||
					CompoundArg2(i1)!=CompoundArg2(i2))
			{
				ErrorInfo(233);
				puts("bad color stru in let-sub.");
				return;
			}
			SetCompoundArg(i1,2,mylbl);
			SetCompoundArg(i2,2,mylbl);
		}
		
		ln=AppendLast(ln,f1);
		ln=AppendLast(ln,f2);
		if(w) ln=AppendLast(ln,w);
		
		SetCompoundArg(m1,1,NewInteger(n));
		SetCompoundArg(m1,2,NewInteger(d));
		SetCompoundArg(m1,3,ln);
		SetCompoundArg(m1,4,ld);
		
		for(l1=nl;l1;l1=ListTail(l1))
		{
			if(EqualTerms(CompoundArgN(ListFirst(l1),3),ln) &&
					EqualTerms(CompoundArgN(ListFirst(l1),4),ld) &&
					IntegerValue(CompoundArg2(ListFirst(l1)))*d>0)
			{
				Term om1=ListFirst(l1);
				int n1=IntegerValue(CompoundArg1(om1));
				int d1=IntegerValue(CompoundArg2(om1));
				int rn,rd,cc=0;
				if(d1<0)
				{
					d=-d;d1=-d1;cc=1;
				}
				rn=n*d1+n1*d;
				rd=d*d1;
				if(rn==0)
				{
					nl=CutFromList(nl,l1);
					break;
				}
				g=gcf(rn,rd);
				rn/=g; rd/=g;
				if(cc) rd=-rd;
				SetCompoundArg(om1,1,NewInteger(rn));
				SetCompoundArg(om1,2,NewInteger(rd));
				FreeAtomic(m1);
				break;
			}
		}
		
		if(l1==0)
			nl=AppendLast(nl,m1);
		
	}
	
	RemoveList(lm);
	/*DumpList(nl);*/
	
	/*printf("%d\n",ListLength(nl));*/
	SetCompoundArg(a1,1,nl);
}
Exemple #11
0
ALERROR CListSaveFilesTask::OnExecute (ITaskProcessor *pProcessor, CString *retsResult)

//	OnExecute
//
//	Execute the task
	
	{
	int i;

	const CVisualPalette &VI = m_HI.GetVisuals();

	//	Make a list of all files in the directory

	TArray<CString> SaveFiles;
	bool bAtLeastOneFolder = false;
	for (i = 0; i < m_Folders.GetCount(); i++)
		{
		if (!fileGetFileList(m_Folders[i], NULL_STR, CONSTLIT("*.sav"), 0, &SaveFiles))
			::kernelDebugLogMessage("Unable to read from save file folder: %s", m_Folders[i]);
		else
			bAtLeastOneFolder = true;
		}

	//	If we couldn't read from any folder, return an error

	if (!bAtLeastOneFolder)
		{
		*retsResult = ERR_DIRECTORY_FAILED;
		return ERR_FAIL;
		}

	//	Sort by modified time (most recent first)

	TSortMap<CTimeDate, CString> SortedList(DescendingSort);
	for (i = 0; i < SaveFiles.GetCount(); i++)
		SortedList.Insert(fileGetModifiedTime(SaveFiles[i]), SaveFiles[i]);

	//	Generate a Reanimator list of the profile. The root will be a CAniListBox

	m_pList = new CAniListBox;
	m_pList->SetPropertyMetric(PROP_FADE_EDGE_HEIGHT, 0.0);
	m_pList->SetPropertyMetric(PROP_PADDING_BOTTOM, (Metric)MAJOR_PADDING_BOTTOM);

	//	Set the selection style for the list

	IAnimatron *pStyle = new CAniRoundedRect;
	pStyle->SetPropertyColor(PROP_COLOR, VI.GetColor(colorAreaDialogInputFocus));
	pStyle->SetPropertyOpacity(PROP_OPACITY, 255);
	pStyle->SetPropertyString(PROP_LINE_TYPE, LINE_TYPE_SOLID);
	pStyle->SetPropertyColor(PROP_LINE_COLOR, VI.GetColor(colorAreaDialogHighlight));
	pStyle->SetPropertyInteger(PROP_LINE_WIDTH, SELECTION_BORDER_WIDTH);
	pStyle->SetPropertyInteger(PROP_UL_RADIUS, SELECTION_CORNER_RADIUS);
	pStyle->SetPropertyInteger(PROP_UR_RADIUS, SELECTION_CORNER_RADIUS);
	pStyle->SetPropertyInteger(PROP_LL_RADIUS, SELECTION_CORNER_RADIUS);
	pStyle->SetPropertyInteger(PROP_LR_RADIUS, SELECTION_CORNER_RADIUS);
	m_pList->SetStyle(STYLE_SELECTION_FOCUS, pStyle);

	pStyle = new CAniRoundedRect;
	pStyle->SetPropertyColor(PROP_COLOR, VI.GetColor(colorAreaDialogInputFocus));
	pStyle->SetPropertyOpacity(PROP_OPACITY, 255);
	pStyle->SetPropertyInteger(PROP_UL_RADIUS, SELECTION_CORNER_RADIUS);
	pStyle->SetPropertyInteger(PROP_UR_RADIUS, SELECTION_CORNER_RADIUS);
	pStyle->SetPropertyInteger(PROP_LL_RADIUS, SELECTION_CORNER_RADIUS);
	pStyle->SetPropertyInteger(PROP_LR_RADIUS, SELECTION_CORNER_RADIUS);
	m_pList->SetStyle(STYLE_SELECTION, pStyle);

	//	No need to log image load

	g_pUniverse->SetLogImageLoad(false);

	//	Loop over all files and add them to the scroller

	int y = MAJOR_PADDING_TOP;
	for (i = 0; i < SortedList.GetCount(); i++)
		{
		CString sFilename = SortedList[i];
		CGameFile GameFile;

		//	Ignore files that we can't open

		if (GameFile.Open(sFilename) != NOERROR)
			continue;

		//	If the universe is not valid, then this is not a proper save file
		//	(this can happen in the first system).

		if (!GameFile.IsUniverseValid())
			continue;

		//	If we're signed in, then we only show games for the given user
		//	(or unregistered games).

		if (GameFile.IsRegistered() && !strEquals(GameFile.GetUsername(), m_sUsername))
			continue;

		//	Generate a record for the file

		IAnimatron *pEntry;
		int cyHeight;
		CreateFileEntry(GameFile, SortedList.GetKey(i), y, &pEntry, &cyHeight);

		m_pList->AddEntry(sFilename, pEntry);
		y += cyHeight + INTER_LINE_SPACING;

		//	Done

		GameFile.Close();
		}

	g_pUniverse->SetLogImageLoad(true);

	//	Done

	return NOERROR;
	}
Exemple #12
0
void alg2_recommon_s(Term a2)
	{
	List m2l,l,la,l1;
	m2l=CompoundArgN(a2,5);
	l=m2l;
	if(is_empty_list(l))
		return;
	la=CopyTerm(CompoundArg2(ListFirst(l)));
	l=ListTail(l);
	while(!is_empty_list(l))
		{
		la=p_m_p_s(la,CompoundArg2(ListFirst(l)));
		l=ListTail(l);
		}
	l=la;
	while(!is_empty_list(l))
		{
		if(IntegerValue(CompoundArg2(ListFirst(l)))==0 || 
				(!(TexOutput||FAOutput) &&
				GetAtomProperty(CompoundArg1(ListFirst(l)),A_DUMMY_PRM)) ||
				(FAOutput && GetAtomProperty(CompoundArg1(ListFirst(l)),
					A_INFINITESIMAL)) )
			{
			la=CutFromList(la,l);
			l=la;
			}
		else
			l=ListTail(l);
		}
	if(is_empty_list(la))
		return;
    l1=ConsumeCompoundArg(a2,3);
    for(l=la;l;l=ListTail(l))
        {
        List l2;
        for(l2=l1;l2;l2=ListTail(l2))
            {
			if(CompoundArg1(ListFirst(l2))==CompoundArg1(ListFirst(l)))
				{
				int b1, b2;
				b1=IntegerValue(CompoundArg2(ListFirst(l)));
				b2=IntegerValue(CompoundArg2(ListFirst(l2)));
				b1+=b2;
				if(b1==0)
					l1=CutFromList(l1,l2);
				else
					SetCompoundArg(ListFirst(l2),2,NewInteger(b1));
				break;
				}
			}
		if(is_empty_list(l2))
			l1=AppendFirst(l1,CopyTerm(ListFirst(l)));
		}

	l1=SortedList(l1,prtcmp);
	SetCompoundArg(a2,3,l1);

	l=m2l;
	while(!is_empty_list(l))
		{
		Term t;
		List l2,l3;
		t=ListFirst(l);
		l1=ConsumeCompoundArg(t,2);
		l2=la;
		while(!is_empty_list(l2))
			{
			Term t2;
			t2=ListFirst(l2);
			l3=l1;
			while(!is_empty_list(l3))
				{
				Term t3;
				t3=ListFirst(l3);
				if(CompoundArg1(t2)==CompoundArg1(t3))
					{
					int np;
					np=IntegerValue(CompoundArg2(t3))-IntegerValue(CompoundArg2(t2));
					if(np)
						{
						SetCompoundArg(t3,2,NewInteger(np));
						goto l2cnt;
						}
					else
						{
						l1=CutFromList(l1,l3);
						goto l2cnt;
						}
					}
				l3=ListTail(l3);
				}
			l1=AppendLast(l1,MakeCompound2(OPR_POW,CompoundArg1(t2),
						NewInteger(-IntegerValue(CompoundArg2(t2)))));
			/*puts("Internal error: csm failed");*/
		l2cnt:
			l2=ListTail(l2);
			}
		l1=SortedList(l1,prtcmp);
		SetCompoundArg(t,2,l1);
		l=ListTail(l);
		}

	FreeAtomic(la);
	}