// uses mission.df

40 value theme-stride		\ number of sprite frames in each theme
0 value theme-num			\ current theme number, use "<num> to theme-num" to set it


// Tuck more stuff away like the newer foreach'es
(*
: foreach-thing >r 1 #thing >r
	begin r@ while
	r@ rover execute
	r> thing# 1+ #thing >r repeat
	r> drop r> drop ;

: active-filter ( 'word thing -- 'word )
	dup .id@ 0= if drop exit then
	over execute ;

: foreach-active-thing ' active-filter foreach-thing drop ;
*)

// Putting these here for now because uses things.df just errored it anyway
: foreach-thing >r 1 #thing >r
	begin r@ while
	r@ rover execute
	r> thing# 1+ #thing >r repeat
	r> drop r> drop ;

: active-filter ( 'word thing -- 'word )
	dup .id@ 0= if drop exit then
	over execute ;

: foreach-active-thing ' active-filter foreach-thing drop ;

// Helper words for direct THING words to to work with the last-thing spawned/selected
: movex last-thing .slidex ;
: movey last-thing .slidey ;
: move movey movex ;
: flip! last-thing .flip! ;
: spriteid! last-thing .spriteid! ;
: %flammability! last-thing .flammability! ;
: cyoa! last-thing .cyoa! ;
: events! last-thing .events! ;
: action! last-thing .action! ;
: bbox last-thing .bbox ;
: health! last-thing .hitpoints! ;
: mass! last-thing .mass! ;
// : nocollide! last-thing .nocollide! ;
: loot! last-thing .loot! ;
: amount! last-thing .amount! ;
: noloot 0 loot! 0 amount! 0 action! ;
: angle! last-thing .angle! ;
: bcircle last-thing .bcircle ;
: drift last-thing .drift ;
: scatter last-thing .scatter ;
: as-weapon last-thing .as-weapon ;
: itemtype! last-thing .itemtype! ;
: nearest player .nearest ;
: interactee player .interact_id@ #thing ;
: opened 1 last-thing .item.opened! noloot ; // No loot in opened things by default
: spawn> spawn last-thing ;
: on-floor 1 last-thing .layer! ;
: weapon spawn as-weapon itemtype! rnd5050 lt .flip! ;
: burning 1 last-thing .burning! ;

// TODO: to complement immovable
// : lightweight ... ;
// : medweight ... ;
// : heavyweight ... ;

: immovable 1000 mass! ;
: 1weight 4 mass! ;
: 2weight 5 mass! ;
: 3weight 6 mass! ;
: 4weight 7 mass! ; // Needs 4 strength to pick up
: 5weight 8 mass! ;
: 6weight 9 mass! ; // Needs 6 strength to pick up
: swoleweight 19 mass! ; // Needs 6 + 10 strength to pick up

: nohit 1 lt .no_hit! ;
: nocollide 1 lt .nocollide! ;
: rndflip rnd5050 flip! ;
: vary-sprite rnd5050 + spriteid! rndflip ;

: themed inside_objects_base_id + theme-stride theme-num * + ;

// set up various attributes that make sense for materials
: as-wood 75 %flammability! ;
: as-cloth 95 %flammability! ;
: as-bone 25 %flammability! ;
: as-metal 5 %flammability! ;
: as-rubber 85 %flammability! ;

: this-cyoa nearest .cyoa! ;
: clear-cyoa 0 this-cyoa ;
: clear-action 0 nearest .action! ;
: clear-events 0 nearest .events! ;

: .smashy args( self )
	<- self .smack
	5 8 rnd <- self .smashybits
	10 <- self .shudder!
	sfx{ glass <- self .adjust-vol }
	sfx{ noise 8 fx .pitch! 0.25 fx .s! 250 fx .r! <- self .adjust-vol }
;

// Pull out loot values, clear from THING
: .pullloot ( thing -- amt loot )
	dup >r .amount@ 0 r@ .amount! r@ .loot@ 0 r> .loot!
;

: .loot? ( thing -- t/f )
	dup .loot@ 0= if drop false exit then
	.amount@ 0= if drop false exit then
	true
;

: .drop-loot args( thing )
	<- thing .loot? 0= if then;
	<- thing .pullloot spawnloot 1 lt .no_hit!
	<- thing .pos lt .pos! 
	<- thing .vel 2 / swap 2 / swap lt .vel!
	-1 lt .vel.z!
	-8 lt .pos.z! 
;

: get-loot-act args( other self )
	<- self .pullloot <- other .character@ .lootamt+
	1 <- self .open! 0 <- self .cyoa!
;

: generalammo 40 %chance if 6 12 rnd LOOT_BULLET else 50 %chance if 5 10 rnd LOOT_RIFLE_SHELL else 3 7 rnd LOOT_SHOTGUN_SHELL then then ;
: general-loot
	60 %chance if generalammo else 
	80 %chance if 1 LOOT_FOOD else 1 LOOT_MEDICAL then then // two thens because two ifs, amount and loot type are on the top of stack at this point
	loot! amount!
;

// Weapons
: $weapon> $weaponid weapon last-thing ;

: weaponspawner dup :: postpone literal postpone $weapon> postpone ; ;
: $weaponword dup weaponspawner // spawn the object
	dup $weaponid swap "WEAPON_" swap $upper $cat $constant ; // create a WEAPON_* ID constant for it
: weapon: token $weaponword ;

weapon: ak47
weapon: uzi
weapon: pistol
weapon: dolt
weapon: hunting
weapon: shotgun
weapon: autoshot
weapon: slug
weapon: dawg
weapon: rifle

weapon: blowtorch
weapon: chainsaw
weapon: hatchet
weapon: spatula
weapon: sledge
weapon: wrench
weapon: nail
weapon: baseball
weapon: cleaver
weapon: kitch
weapon: wood
weapon: femur
weapon: crowbar
weapon: nightstick
weapon: cricket
weapon: aluminum
weapon: otaku
weapon: cane
weapon: golf
weapon: frying

weapon: medieval
weapon: knight
weapon: claymore

weapon: fire
weapon: beach
weapon: hockey
weapon: xtreme
weapon: umbrella
weapon: cardboard
weapon: pitchfork
weapon: shovel
weapon: tree
weapon: metal
weapon: machete1
weapon: machete2
weapon: parking

weapon: lovely
weapon: rapier
weapon: toy
weapon: gauntlet
weapon: punchquest
weapon: glove
weapon: uppercut
weapon: pool1
weapon: pool2

weapon: karate
weapon: claw
weapon: boxing
weapon: kung
weapon: pokin
weapon: morning

weapon: zombleg
weapon: spine
weapon: spineskull
weapon: rebar

weapon: devilfork
weapon: guitar
weapon: fishing

weapon: debutante
weapon: mason
weapon: sumo
weapon: rambeux
weapon: minigun
weapon: ridic
weapon: vlamb
weapon: ninja
weapon: kunai
weapon: shuriken
weapon: smokebomb

weapon: grenade
weapon: pipebomb
weapon: molotov
weapon: bottle
weapon: flamethrower

weapon: woodsword
weapon: whitesword
weapon: hero
weapon: woodboom
weapon: metalboom
weapon: windstar
weapon: lnkbomb

weapon: mjolnir

weapon: broom
weapon: mop
weapon: ultramop
weapon: snubnose
weapon: mountie
weapon: antlers
weapon: raygun
weapon: ehzerbeam
weapon: truekatana
weapon: 2x4


// Backwards compatibility with old weapon ID's still being used
// "shotgun" $weaponid constant WEAPON_SHOTGUN
// "rifle" $weaponid constant WEAPON_RIFLE
// "pistol" $weaponid constant WEAPON_PISTOL
// "baseball" $weaponid constant WEAPON_BAT
// "dolt" $weaponid constant WEAPON_REVOLVER
// "cleaver" $weaponid constant WEAPON_CLEAVER
// "wrench" $weaponid constant WEAPON_WRENCH
// "sledge" $weaponid constant WEAPON_MAUL
// "nail" $weaponid constant WEAPON_NAIL_BOARD
// "hatchet" $weaponid constant WEAPON_HATCHET
// "spatula" $weaponid constant WEAPON_SPATULA
// "kitchen" $weaponid constant WEAPON_KITCHEN_KNIFE
// "uzi" $weaponid constant WEAPON_UZI
// "ak47" $weaponid constant WEAPON_AK47


: to-thing-pos swap .pos rot .pos! ;

// Events for dropping stuff
voc{ mission

// Mission-specific event variables
0 value me# 			// THING the event is for
0 value them#			// ID of THING interacting with me
0 value eventid

: me me# #thing ;
: them them# #thing ;

: store-event-info // FOR THING EVENTS ONLY
//	"STORE EVENT INFO" type .s cr
	to eventid
	thing# to me#
	me .interact_id@ to them#
;

// The resulting defined word handles ALL events for the THING
: thing-event: : postpone store-event-info ; immediate

: drop-here	me swap -1 over .vel.z! to-thing-pos ;

// THING events during mission
thing-event: break-container
	eventid THING_EVENT_BREAK <> ?;
	me .loot? 0?;
	me .drop-loot
;

thing-event: break-container-glass
	eventid THING_EVENT_WAS_HIT <> ?;
	me .item.opened@ not if me .smashy then
	1 me .open!
	0 me .action!
	me .loot? 0?;
	me .drop-loot lt-droploot-vel 0.25 0.5 frnd lt .vel.y!
;

thing-event: break-skel
	eventid THING_EVENT_BREAK <> ?;
	rnd5050 ?;
	femur drop-here
;

thing-event: break-with-wood
	eventid THING_EVENT_BREAK <> ?;
	rnd5050 ?;
	wood drop-here
;

thing-event: pump-event
	eventid THING_EVENT_NO_LOOT = if 0 me .action! then;
;

: pump-act args( other self )
	ANIM_LOOTING <- other .anim.state!
	30 <- other .stun!
	-8 <- other .shudder!
	<- other .vel 0.5 xymul <- other .vel!
;

}

: pumpable mission{ ' pump-event lt .events! ' pump-act lt .action! } ;
: pumpgas pumpable amount! LOOT_GAS loot! particles_base_id 0x 3a + lt .action_icon! ;

: container-loot-act args( other self )
	<- other <- self get-loot-act
	30 <- other  .stun!
	-8 <- other  .shudder!
	<- other  .vel 0.5 xymul <- other  .vel!
	0 <- self .action!
;

: car-loot
	50 %chance if 10 35 rnd pumpgas else general-loot then
;

: container-smash-act args( other self )
	<- self .smashy
	<- other <- self container-loot-act
;

: container lt .container ' container-loot-act action! general-loot 
	mission{ ' break-container } last-thing .events!
;

: lootable postpone container ; immediate

: smash-n-loot
	' container-smash-act action!
	mission{ ' break-container-glass } last-thing .events!
;

// TODO: Ugh, gotta make it work with stuff that can be opened... perhaps center around base unopened sprite?
// : uncentered 1 last-thing .uncentered! ;
: uncentered ;

// THING will use an OPEN sprite frame
: openable 1 last-thing .openable! uncentered ;

: fridge
	spawn					\ spawns a blank object to the current anchor point
	0x 22 themed spriteid!	\ sets its sprite to 0x22 (hex) and applies the "themed" modifier to the value to use whatever the theme is (set in theme-num)
	rnd5050 flip!			\ randomly flips the sprite
	bbox					\ sets up a bounding box for collision, and mass estimated by size
	\ TODO: Add loot into the fridge!
	swoleweight
	openable container		\ makes it a container
	as-metal
	100 health!
;

defer toiletwish

: toilet-loot args( other self )
	<- other <- self container-loot-act // Call the base action
	gstats{ ' toilets-opened ++ } // Our custom behaviour after that
	gstats{ toilets-opened } 299 > if
		cyoa{ toiletwish }
		gstats{ 0 to toilets-opened }
	then
;

: toilet
	spawn
	0x 1a themed spriteid!
	bbox
	immovable openable container ' toilet-loot action!
	25 health!
	rnd5050 if 1 lt .flies! then
;

: bathtub
	spawn
	0x 1c themed spriteid!
	bbox immovable
	100 health!
;

: sink
	spawn
	0x 1d themed spriteid!
	bbox immovable
	25 health!
;

: dropswood mission{ ' break-with-wood } last-thing .events! ;

: chair spawn 0x 15 themed vary-sprite bbox 1 mass!
	3 health! as-wood dropswood ;
: couch spawn 0x c themed spriteid! rndflip bbox as-cloth dropswood 12 health! ;
: lazyboy spawn 0x d themed vary-sprite bbox as-cloth dropswood 9 health! ;
: bed spawn 0x 6 themed vary-sprite bbox as-cloth dropswood 6 health! ;
: endtable spawn 0x 14 themed spriteid! rndflip bbox
	as-wood dropswood ;
: smalltable spawn 0x 10 themed vary-sprite bbox as-wood dropswood ;
: table spawn 0x 12 themed vary-sprite bbox as-wood dropswood 6 health! ;
: table-hori spawn 0x 12 themed spriteid! rndflip bbox as-wood dropswood 3 health! ;
: smalltable-hori spawn 0x 10 themed spriteid! rndflip bbox as-wood dropswood ;
: pictable table special_objects32_base_id 0x 64 + rnd5050 + spriteid! bbox 9 health! ;
: pictable1 table special_objects32_base_id 0x 64 + spriteid! bbox 9 health! ;
: pictable2 table special_objects32_base_id 0x 65 + spriteid! bbox 9 health! ;

: cupboard spawn 0 themed spriteid! bbox openable container as-wood ;

: drawers spawn 2 themed spriteid! bbox openable container as-wood ;

: smallshelf spawn 8 themed spriteid! bbox openable container as-wood ;
: bigshelf spawn 0x a themed spriteid! bbox openable container as-wood 9 health! ;

: kitchensink spawn 0x 24 themed spriteid! bbox immovable uncentered ;
: stove spawn 0x 20 themed spriteid! bbox openable container immovable ; // TODO: Change counter appliances to tiles

: liedown 90 rndsign * angle! rndflip ;

: skel spawn skeletons_base_id rnd5050 + spriteid! bcircle 1 mass! liedown 
	as-bone mission{ ' break-skel } last-thing .events!
	5 onein if 1 lt .flies! then
;

: skeldog skel skeletons_base_id 0x 8 + spriteid! ;
: skelrat skel skeletons_base_id 0x b + spriteid! ;
: skelalien skel skeletons_base_id 0x 9 + spriteid! ;
: skeltaur skel skeletons_base_id 2 + spriteid! ;

// kepachanges

: skelscat skel scatter ;

: lovingset
	smalltable drift
	couch drift -5 movey
	lazyboy scatter
	1 for endtable scatter next
;

( index -- xoff yoff )
: 4corners
	3 & case
		0 of -1 -1 endof
		1 of -1 1 endof
		2 of 1 -1 endof
		3 of 1 1 endof
	endcase
;

: randbednchairs
	mrand // random starting index for getting 4 corners
	dup 4corners bed movex movey
	1+ dup 4corners chair movex movey
	1+ dup 4corners chair movex movey
	1+ 4corners chair movex movey
;

: carwreck spawn car_wrecks_base_id 0 11 rnd + lt .spriteid!
	bbox lt .rad.x@ 4 - lt .rad.x!

	lt .rad.y@ 0.8 * lt .rad.y!

	lt .sprh 4 / 6 - lt .anim.off.y!
	1 lt .no_hit!
	lt .rad.x@ 16 + lt .wallbox.x!
	lt .rad.y@ 24 + lt .wallbox.y!

// immovable
	500 lt .mass!
	rndflip 0 %flammability!
;

: burningwreck carwreck 100 %flammability! burning ;

: shoppingcart
	spawn special_objects32_base_id 0x 17 + lt .spriteid!
	bbox 5 lt .hitpoints! as-metal 2 lt .mass! rndflip
;

: sec>tick 60 * ;

: .repeating_timer 2dup .timer_hint! .timer! ;
: .retrigger_timer dup .timer_hint@ swap .timer! ;

// Periodic zombie spawner
// Usage: <seconds> time-zomber
// EXAMPLE: 2 tick-zomber // spawn a zombie every 2 seconds
// NOTE: Spawner is an object like any other, can be placed using lt etc.

: invisible
	1 lt .no_hit!
	1 lt .nocollide!
	0 lt .spriteid!
;

}

: carts-scatter for shoppingcart scatter next ;
: carts-here for shoppingcart drift next ;

// : vending spawn special_objects32_base_id 0x 9 + spriteid! bbox as-metal 25 health! 20 mass!
: vending spawn special_objects32_base_id 0x 9 + spriteid! bbox as-metal 25 health! 20 mass!
	openable smash-n-loot
;

: storefridge vending container special_objects32_base_id 0x 10 + spriteid! bbox 25 health! immovable ;

// TODO: Make it explode with gas cloud if broken

mission{

	: particleme me me .pos me .pos.z@ particle{ new pos.z! pos! } ;

	: flameflicker
		particle{
			-1 1 frnd 0.5 * vel.x@ + vel.x!
			-0.5 -2 frnd vel.y@ + vel.y!
			glowy
			1 clr.r!
			0 1 frnd clr.g!
			0 clr.b!
			0.75 grow!
			0.75 1 frnd scale!
		}
	;

	thing-event: flamebitz locals( thing )
		eventid THING_EVENT_LAND = eventid THING_EVENT_BOUNCE = or eventid THING_EVENT_WALL = or eventid THING_EVENT_OVERLAP = or if
			0 me .timer!

			eventid THING_EVENT_OVERLAP = if
				me .pos.z@ -1 > if exit then
				me .interact_id@ #thing -> thing
				// Push it back a wee bit
				<- thing .typeid@ THING_ZOMBIE = if
					me .vel 0.1 xymul <- thing .vel xyadd <- thing .vel!
				then
			then

			0 0 me .vel!

			particleme particle{ particles_base_id 0x 2f + spriteid!
				flameflicker
				4 ticks! 3 fade_out!
				0 fade_in!
				-0.5 vel.z!
				1 1.25 frnd scale!
				0.9 grow!
				0 angle!
				rnd5050 flipx!
				}
		then;

		eventid THING_EVENT_BUMP = if then;

		eventid THING_EVENT_TIMER = if
			particle{ particleme 3 ticks! }
			me .vel xyangle

			particle{ angle! particles_base_id 0x 2e + spriteid!
				5 ticks! ticks@ fade_out!
				flameflicker
				me .vel vel!
				0 vel.x!
				0 vel.y!
				0 vel.z!
				1 1.25 frnd scale!
				rnd5050 flipx!
				0.9 grow!
				vel.z@ 0.25 * vel.z!
				glowy
			}

			me .anim.counter@ if 60 me .burning! 1 me .timer! then
		then;
	;

	: splash-vel
		-0 -1 frnd lt .vel.z!
		-8 lt .pos.z!
		0 360 frnd anglexy 0 0.5 frnd * lt .vel.y! 0 0.5 frnd * lt .vel.x!
	;

	: flamesplash locals( thing )
		spawn lt -> thing
		me .pos <- thing .pos!
		1 <- thing .nocollide!
		100 <- thing .flammability!
		0 <- thing .spriteid!
		splash-vel
		<- thing .gravity@ 0.5 * <- thing .gravity!
		8 <- thing .rad.x!
		16 <- thing .rad.z!
		mission{ ' flamebitz } <- thing .events!
		1 <- thing .timer!
		60 <- thing .anim.counter!
		3 <- thing .hitpoints!

		sfx{
			noise me .adjust-vol 100 fx .a! 0.5 0.75 frnd fx .pitch!
			50 500 frnd fx .filt!
			0 0.5 fx .q!
		}
	;
}

: breaksplode-event args( me eventid )
	<- eventid THING_EVENT_BREAK <> if then;
	<- me .pos xyboom
;

: breaksplode3-event args( me eventid )
	<- eventid THING_EVENT_BREAK <> if then;
	<- me .pos xyboom
	<- me .pos.x@ 16 - <- me .pos.y@ xyboom
	<- me .pos.x@ 16 + <- me .pos.y@ xyboom
;

: .breaksplode ' breaksplode-event swap .events! ;
: .breaksplode3 ' breaksplode3-event swap .events! ;

: bbqtank spawn special_objects16_base_id spriteid! as-metal 15 health! lt .breaksplode ;

: pumps spawn special_objects48_base_id 0x b + lt .spriteid!
	bbox lt .rad.x@ 4 - lt .rad.x!
	lt .rad.y@ 0.5 * lt .rad.y!
	lt .sprh 4 / 0 - lt .anim.off.y!
//	1 lt .no_hit!
	1000 lt .mass!
	20 lt .hitpoints!
	rndflip 0 %flammability!
	lt .breaksplode3
;

: flipside lt .pos.x@ map{ pixelw } 0.5 * - sign 0 < lt .flip! ;
: revflipside lt .pos.x@ map{ pixelw } 0.5 * - sign 0 > lt .flip! ;

: checkoutobj spawn special_objects64_base_id lt .spriteid! bbox immovable ;
: checkout checkoutobj flipside ;
: revcheckout checkoutobj revflipside ;

: cashcounter spawn special_objects64_base_id 2 + spriteid! as-metal bbox immovable 1 lt .no_hit!
	flipside
	8 lt .rad.y@ + lt .rad.y!
	lt .rad.x@ lt .wallbox.x!
	lt .rad.y@ lt .wallbox.y!
;

: rarefood onein if LOOT_FOOD loot! 1 2 rnd amount! then; noloot opened ;

: cinderblock spawn special_objects16_base_id 16 + spriteid! as-metal 250 health! 3weight bbox ;
: tire spawn special_objects16_base_id 14 + spriteid! as-rubber 250 health! 2weight ;
: bigtire spawn special_objects16_base_id 15 + spriteid! as-rubber 500 health! 5weight ;

: edumpster spawn special_objects32_base_id 0x 66 + spriteid! bbox as-metal 500 health! 1 lt .flies! ;
: dumpster edumpster openable container 50 mass! ;

// : onfloor 1 lt .layer! ;
: onfloor 1 lt .onfloor! ;
: onplayer player .pos lt .pos! drop ;

: add-gas LOOT_GAS addloot ;
: add-food LOOT_FOOD addloot ;
: add-medical LOOT_MEDICAL addloot ;
: add-bullet LOOT_BULLET addloot ;
: add-shell LOOT_SHOTGUN_SHELL addloot ;
: add-rifle LOOT_RIFLE_SHELL addloot ;

: #kill #thing 0 swap .hitpoints! ;
: killit .id@ #kill ;
: silentkillit 0 swap .id! ;
: deleteme player .nearest_interact_id@ #thing silentkillit ;

: delete-cover-events 0 args( me eventid thing )
	<- eventid THING_EVENT_PUSH = if
//		beep
//		<- me .timer@ 7 & if then;
//		<- me .timer@ 1 > if then;
		<- me .interact_id@ #thing -> thing
		<- thing .mass@ 100 < if then;
		32 <- me .timer!
		<- thing silentkillit
	then;

	// Times up, no more deleting stuff
	<- eventid THING_EVENT_TIMER = if
		1 <- me .onfloor!
		<- me .bbox
	then;
;

: delete-covering
	' delete-cover-events lt .events!
	32 lt .timer!
	0 lt .nocollide!
	0 lt .onfloor!
	10 lt .rad.x!
	10 lt .rad.y!
;

: book spawn special_objects16_base_id 17 0 2 rnd + + spriteid! 2 health! bbox 3 mass! ;
: magazine spawn special_objects16_base_id 20 0 2 rnd + + spriteid! 2 health! bbox 1 mass! onfloor ;
: wrotenote spawn special_objects16_base_id 23 + spriteid! 50 health! bbox 1 mass! onfloor ;
: goldkey spawn special_objects16_base_id 24 + spriteid! 50 health! bbox 1 mass! onfloor ;
: keychain spawn special_objects16_base_id 25 + spriteid! 50 health! bbox 1 mass! onfloor ;
: safe spawn special_objects32_base_id 0 rnd5050 if 2 + then + lt .spriteid! bbox as-metal openable immovable 200 health! ;
: labmachine spawn special_objects64_base_id 0x 7 + lt .spriteid! bbox as-metal immovable 200 health! ;
: altarstand spawn special_objects48_base_id 1 + lt .spriteid! immovable lt .sprh 2 / 8 - lt .anim.off.y! 8 lt .rad.x! ;

: .clr! args( r g b thing )
	<- r <- thing .clr.r!
	<- g <- thing .clr.g!
	<- b <- thing .clr.b!
;

: .clr@ args( thing )
	<- thing .clr.r@
	<- thing .clr.g@
	<- thing .clr.b@
;

// Give a metallic item a rusty tint
: .rusty 1 over .clr.r! 0.75 over .clr.g! 0.5 over .clr.b! drop ;

// Get a -1 or 1 for current flip direction
: .flipx .flip@ -2 * 1+ ;

: .ghosty args( thing )
	1 <- thing .glow!
	0 0.5 1 <- thing .clr!
;

: .zomb? .typeid@ THING_ZOMBIE = ;

: zomboff dup mission{ .zomb? } 0= if drop then;
	dup .mapid@ curmapsel <> if drop then;
	silentkillit
;

: kill-zombies-here
	mission{ ' zomboff foreach-active-thing }
;

: zombsplat dup mission{ .zomb? } 0= if drop then;
	dup .mapid@ curmapsel <> if drop then;
	killit
;

: splat-zombies-here
	mission{ ' zombsplat foreach-active-thing }
;

// ex 32 32 skelscatxy
: skelscatxy skel lt .scatterxy ;

// SEARCHES FOR MULTIPLE WEAPON ID'S IN GROUP, TRUNK

0 stack
	WEAPON_PISTOL shove
	WEAPON_SNUBNOSE shove
	WEAPON_UZI shove
	WEAPON_DOLT shove
constant WEAPON_LIST_HANDGUNS

0 stack
	WEAPON_RIFLE shove
	WEAPON_HUNTING shove
	WEAPON_SLUG shove
	WEAPON_AK47 shove
constant WEAPON_LIST_RIFLE

0 stack
	WEAPON_RIFLE shove
	WEAPON_HUNTING shove
	WEAPON_SLUG shove
	WEAPON_AK47 shove
	WEAPON_PISTOL shove
	WEAPON_SNUBNOSE shove
	WEAPON_UZI shove
	WEAPON_DOLT shove
	WEAPON_DAWG shove
	WEAPON_AUTOSHOT shove
	WEAPON_MINIGUN shove
	WEAPON_VLAMB shove
	WEAPON_RIDIC shove
	WEAPON_FLAMETHROWER shove
constant WEAPON_LIST_FIREARM

0 stack
	WEAPON_KITCH shove
	WEAPON_CLEAVER shove
	WEAPON_MACHETE1 shove
	WEAPON_MACHETE2 shove
	WEAPON_RAMBEUX shove
	WEAPON_MASON shove
constant WEAPON_LIST_KNIVES

: lt-to-thing
	dup .pos lt .pos!
	.mapid@ lt .mapid!
;

: .inside? .inside_id 0= not ;
: .inside@ .inside_id #thing ;
: .interacting? thing# player .nearest_interact_id@ = ;

: hospitalmachine spawn special_objects32_base_id 0x 5a + lt .spriteid! bbox as-metal 15 health! ;		
: stretcher spawn special_objects32_base_id 0x 57 + lt .spriteid! rndflip
	bbox as-metal ;
: hospitalcurtain spawn special_objects32_base_id 0x 5b + lt .spriteid!
	bbox as-metal ;	
: wheelchair spawn special_objects32_base_id 0x 55 + lt .spriteid! rndflip
	bbox as-metal 10 health! ;
	
	
: dumbrack
	spawn special_objects32_base_id 0x 70 + lt .spriteid! rndflip
	25 health! bbox swoleweight as-metal immovable
;

: gymbike
	spawn special_objects32_base_id 0x 71 + lt .spriteid!
	bbox immovable as-metal
;

: treadmill
	spawn special_objects32_base_id 0x 72 + lt .spriteid! rndflip
	15 health! bbox swoleweight as-metal
;

: olympicbar
	spawn special_objects32_base_id 0x 73 + lt .spriteid!
	20 health! bbox 6weight as-metal immovable
;

: barbell
	spawn special_objects32_base_id 0x 74 + lt .spriteid!
	12 health! bbox 4weight as-metal
;
: dumbbell3 2 + + lt .spriteid! 7 health! bbox 2weight ;
: dumbbell2 1 + + lt .spriteid! 5 health! bbox 1weight ;
: dumbbell1 0 + + lt .spriteid! 3 health! bbox ;
: dumbbell
	spawn special_objects32_base_id 0x 75 
	50 %chance if dumbbell2 else 50 %chance if dumbbell1 else dumbbell3 then then
	as-metal
;


// AI stuff
: .followed .ai.followid@ #thing ;
