EPMTOOLS = ./epmtools
POV=povray
QUALITY=HiQ.ini

.DELETE_ON_ERROR:
.PRECIOUS: %.epm %.pbm %.ppm.gz
.PHONY: conv.% %.test

all:  conv.normal conv.felix conv.insect conv.wuschel conv.wusel conv.ping conv.golem conv.sticky conv.tutorial

PHASES=1 2 3
SPECIALPOSES=L L1 L2 W W2 W3 DD DL DU DR
NORMALPOSES=$(foreach d,D L U R,$(d)_S $(d)_0 $(d)_1 $(d)_2 $(d)_3)

POSES = B $(SPECIALPOSES) $(NORMALPOSES)

conv.%: $(foreach pose,$(POSES),fertig/%_$(pose).epm)
	@echo "$* finished"

clean:
	-rm -f *.pgm *.epm *.pbm *.tmp fertig/*.grn fertig/*.red fertig/*.blu fertig/*.pgm tmp/*

					      
realclean: clean
	-rm fertig/*.ppm.gz fertig/*.epm fertig/*.pbm
					      
					      
%.red %.grn %.blu: %.ppm.gz
	gunzip < $< > $*.ppm
	ppmtorgb3 $*.ppm
	-rm $*.ppm

%.helmet.pgm: %_1.red %_3.grn
	pnmarith -sub $^  >$@

%.face.pgm: %_1.grn %_3.grn
	pnmarith -sub $^  >$@

%.body.pgm: %_1.blu %_3.grn
	pnmarith -sub $^  >$@

%.handsfeet.pgm: %_2.red %_3.grn
	pnmarith -sub $^  >$@

%.armslegs.pgm: %_2.grn %_3.grn
	pnmarith -sub $^  >$@

%.backpack.pgm: %_2.blu %_3.grn
	pnmarith -sub $^  >$@

%.pbm: %_3.blu %_3.grn
	pnmarith -sub $^ | pgmtopbm -threshold -value 0.5 >$@

%.epm: %.pbm %.helmet.pgm %.face.pgm %.body.pgm %.handsfeet.pgm %.armslegs.pgm %.backpack.pgm %_3.grn
	$(EPMTOOLS)/pgmtoepm $*.helmet.pgm $*.face.pgm $*.body.pgm \
		$*.handsfeet.pgm $*.armslegs.pgm $*.backpack.pgm \
		$*_3.grn >$@
	$(EPMTOOLS)/epmcompress $@
	-rm -f $@~

# Rendern:

# big winner sprites
%_B_1.ppm.gz %_B_2.ppm.gz %_B_3.ppm.gz:
	if [ ! -d ./$(notdir $*) ]; then echo "where is '$(notdir $*)'?" ; exit 1 ; fi
	export DESTNAME=$* ; $(POV) +L./$(notdir $*) +L./include BigWinner.ini +Ob$(notdir $*).tmp

# special sprites
$(foreach phase,$(PHASES),$(foreach suffix,$(SPECIALPOSES),%_$(suffix)_$(phase).ppm.gz)): 
	if [ ! -d ./$(notdir $*) ]; then echo "where is '$(notdir $*)'?" ; exit 1 ; fi
	export DESTNAME=$* ; $(POV) +L./$(notdir $*) +L./include AllPlayerSpecial.ini $(QUALITY) +Os$(notdir $*).tmp

# "normal" sprites
$(foreach phase,$(PHASES),$(foreach suffix,$(NORMALPOSES),%_$(suffix)_$(phase).ppm.gz)): 
	if [ ! -d ./$(notdir $*) ]; then echo "where is '$(notdir $*)'?" ; exit 1 ; fi
	export DESTNAME=$* ; $(POV) +L./$(notdir $*) +L./include AllPlayerAnimation.ini $(QUALITY) +Op$(notdir $*).tmp

test.%:
	$(POV) +L./$(notdir $*) +L./include Anschauen.ini +O$*_test.tmp
	-rm $*_test.tmp

walk.%:
	$(POV) +L./$(notdir $*) +L./include WalkFluidly.ini +Otmp/$*_testwalk.ppm

win.%:
	$(POV) +L./$(notdir $*) +L./include WinFluidly.ini +Otmp/$*_testwin.ppm

lose.%:
	$(POV) +L./$(notdir $*) +L./include LoseFluidly.ini +Otmp/$*_testlose.ppm


