Page 1 of 1

"fun with filters 3" Filtered by Dawn

Posted: Wed Aug 06, 2008 1:51 am
by Betelgeuse
so here are some less practical example but much more advanced examples of uses of filter

the first is a filter that changes as it goes through the list

Code: Select all

(setq maxListCount 10)

(setq currentListCount 0)

(setq myCurrentSize 0)


(setq testFilter (lambda nil
	;returns (0 1 2 3 6 12 24 48 96 192)
	(block (myList)
		(setq myList 0)
		(for i 1 10000 
			(setq myList (append myList i))
		)
		(filter myList currentNumber 
			(if (and (ls currentListCount maxListCount) (geq currentNumber myCurrentSize))
				(block nil
					(setq myCurrentSize (add currentNumber myCurrentSize))
					(setq currentListCount (add 1 currentListCount))
				)
			)
		)
	)
))
the second example is one where you are using filters within other filters. With this you can ask some complex questions.

Code: Select all

(setq testNestedFilter (lambda nil
	(block (shipList)
		;get ships
		(setq shipList (sysFindObject gPlayerShip "s"))

		;get only friendly ships that have unequiped items that have mass greater than 100 and do not have the static data heavy
		(setq shipList (filter (filter shipList myShip (objIsEnemy gplayership myShip)) enemyShip 
			(filter (objGetItems enemyShip "*U") element 
				(and (not (itmGetStaticData element "heavy")) (gr (itmGetMass element) 100))
			)
		))
	)
))
any questions or comments?

Posted: Wed Aug 06, 2008 1:53 am
by Aury
second one could be useful, first one I wouldn't know what to do w/ it yet though...

Posted: Wed Aug 06, 2008 1:58 am
by Betelgeuse
well the obvious use is to limit the number of elements in the result list. Like you only want the first 10 choices.

Posted: Wed Aug 06, 2008 2:00 am
by Aury
Betelgeuse wrote:well the obvious use is to limit the number of elements in the result list. Like you only want the first 10 choices.
yes, but what would you use it in-game for? I'll have to think of something...

Posted: Wed Aug 06, 2008 2:20 am
by Betelgeuse
hmm random idea
get at most ten random enemy ships from a system that are powerful enough and give them bonus cargo and a "bounty hunter" data
Then the player looks at the wanted board you could pay for a target to one of them and get a bonus for killing them and taking the cargo back to the rightful owner.

Posted: Wed Aug 06, 2008 2:38 am
by Aury
Betelgeuse wrote:hmm random idea
get at most ten random enemy ships from a system that are powerful enough and give them bonus cargo and a "bounty hunter" data
Then the player looks at the wanted board you could pay for a target to one of them and get a bonus for killing them and taking the cargo back to the rightful owner.
hmmm... very interesting... :D