All pastes #101860 Raw Edit

Anonymous

public text v1 · immutable
#101860 ·published 2006-07-27 06:16 UTC
rendered paste body
;--------------------Map laden
Function e_map_load(name$,root$="maps/")
	Local x,y,i,header$,stream,ec
	
	;löschen
	e_cls()
	
	;Existiert Map?
	If FileType(root$+name$+".map")<>1 Then
		con_add("Error: Can't find "+name$+".map!",0)
		Return 0
	EndIf
	
	;Waypoints
	map_waypoints=e_waypoints_load(name$)
	
	;Lesen
	con_add("Loading "+name$+".map",0)
	stream=ReadFile(root$+name$+".map")
	
	;ID-Header
	header$=ReadLine(stream)
	If Instr(header$, "Unreal Software's Counter-Strike 2D Map File")=0 Then
		con_add("Error: Can't load "+name$+".map - no Counter-Strike 2D map!",0)
		Return 0
	EndIf
	
	;Fakes
	map_back_scr_tile=ReadByte(stream)
	For i=1 To 9
		ReadByte(stream)
	Next
	For i=1 To 10
		ReadInt(stream)
	Next
	For i=1 To 10
		ReadLine(stream)
	Next
	
	;Map Header
	map_code$=ReadLine(stream)
	map_name$=name$
	map_tileset$=ReadLine(stream)
	map_tilesc=ReadByte(stream):Local map_tilesc_loaded=map_tilesc
	map_xsize=ReadInt(stream)
	map_ysize=ReadInt(stream)
	map_back$=ReadLine(stream)
	map_back_h=0
	map_back_x=0
	map_back_y=0
	map_back_scr_x=ReadInt(stream)
	map_back_scr_y=ReadInt(stream)
	map_bg_r=ReadByte(stream)
	map_bg_g=ReadByte(stream)
	map_bg_b=ReadByte(stream)
	map_storm_x#=0
	map_storm_y#=0
	
	;Maximale Größe
	If map_xsize>10000 Then map_xsize=10000:con_add("Error: Invalid X-Size",0,0)
	If map_ysize>10000 Then map_ysize=10000:con_add("Error: Invalid Y-Size",0,0)
			
	;Background Color/Image initialisieren
	ClsColor map_bg_r,map_bg_g,map_bg_b
	If map_back$<>"" And Instr(map_back$,".")=0 Then map_back$=map_back$+".jpg"
	If FileType("gfx/backgrounds/"+map_back$)=1 Then
		map_back_h=LoadImage("gfx/backgrounds/"+map_back$)
	Else
		map_back_h=0
	EndIf
	
	;zwischen-Test
	header$=ReadLine(stream)
	If header$<>"ed.erawtfoslaernu" Then
		con_add("Error: Can't load "+name$+".map - invalid/damaged map header!",0)
		Return 0
	EndIf
		
	;Tile Modes
	If Not e_loadtiles(map_tileset$) Then Return 0
	Dim tile_mode(map_tilesc_loaded)
	For i=0 To map_tilesc_loaded
		tile_mode(i)=ReadByte(stream)
	Next
	
	;Tiles
	Dim map(map_xsize,map_ysize,3)
	For x=0 To map_xsize
		For y=0 To map_ysize
			map(x,y,0)=ReadByte(stream)
			If map(x,y,0)>map_tilesc Then
				map(x,y,0)=0
				map(x,y,3)=tile_mode(0)
			Else
				map(x,y,3)=tile_mode(map(x,y,0))
			EndIf
		Next
	Next
		
	;Entities
	ec=ReadInt(stream)
	If ec>10000 Then ec=10000:con_add("Error: Invalid Entity Count",0,0)
	For i=1 To ec
		entity.entity=New entity
		entity\name$=ReadLine(stream)
		entity\typ=ReadByte(stream)
		entity\h=0
		entity\x=ReadInt(stream)
		entity\y=ReadInt(stream)
		entity\trigger$=ReadLine(stream)
		For x=0 To 9
			entity\value_int[x]=ReadInt(stream)
			entity\value_str$[x]=ReadLine(stream)
		Next
	Next
	
	;In Entities verwendete Ressourcen laden / Enities einstellen
	For entity.entity=Each entity
		Select entity\typ
			;inf_animation
			Case 8
				entity\value_int[8]=entity\value_int[0]
			;inf_storm
			Case 9
				map_storm_x#=Float(Sin(entity\value_int[0])*entity\value_int[1])/10.0
				map_storm_y#=Float(-Cos(entity\value_int[0])*entity\value_int[1])/10.0
			;env_sprite
			Case 22
				e_res_load(entity\value_str$[0],1,entity\value_str$[2])
				e_setup_sprite(entity\x,entity\y)
			;env_sound
			Case 23
				entity\h=e_res_load(entity\value_str$[0],0)
			;env_image
			Case 28
				entity\h=e_res_load(entity\value_str$[0],2)
		End Select
	Next
	
	;Entities Cachen
	For entity.entity=Each entity
		entityc.entityc=New entityc
		entityc\name$=entity\name$
		entityc\typ=entity\typ
		entityc\h=entity\h
		entityc\x=entity\x
		entityc\y=entity\y
		entityc\trigger$=entity\trigger$
		For x=0 To 9
			entityc\value_int[x]=entity\value_int[x]
			entityc\value_str$[x]=entity\value_str$[x]
		Next
	Next
	
	;Entities in Map Array speichern
	;Leeren
	For x=0 To map_xsize
		For y=0 To map_ysize
			map(x,y,1)=-1
		Next
	Next
	;Fläche
	Local ax,ay,a
	For entity.entity=Each entity
		If entity_area(entity\typ)>0 Then
			a=entity_area(entity\typ)
			For ax=entity\x-a To entity\x+a
				For ay=entity\y-a To entity\y+a
					If ax>=0 Then
						If ay>=0 Then
							If ax<=map_xsize Then
								If ay<=map_ysize Then
									map(ax,ay,1)=entity\typ
								EndIf
							EndIf
						EndIf
					EndIf
				Next
			Next
		EndIf
	Next
	;Punkt
	For entity.entity=Each entity
		If entity\x>=0 Then
			If entity\y>=0 Then
				If entity\x<=map_xsize Then
					If entity\y<=map_ysize Then
						map(entity\x,entity\y,1)=entity\typ
					EndIf
				EndIf
			EndIf
		EndIf
	Next
	;Dynamic Walls (env_breakable)
	For entity.entity=Each entity
		If entity\typ=25 Then
			If entity\x>=0 Then
				If entity\y>=0 Then
					If entity\x<=map_xsize Then
						If entity\y<=map_ysize Then
							If entity\value_int[6]=0 Then
								map(entity\x,entity\y,3)=1	;Wall (Shadow)
							ElseIf entity\value_int[6]=1 Then
								map(entity\x,entity\y,3)=3	;Block (no Shadow)
							Else
								map(entity\x,entity\y,3)=2	;Obstacle (Obstacle Shadow)
							EndIf
						EndIf
					EndIf
				EndIf
			EndIf
		EndIf
	Next
	;Overwrite Entities (löschen Flächen wieder
	For entity.entity=Each entity
		;info_nobuying
		If entity\typ=11 Then
			For x=0 To map_xsize
				For y=0 To map_ysize
					If map(x,y,1)<3 Then map(x,y,1)=-1
				Next
			Next
		EndIf
	Next
	
	;Map Cachen
	Dim map_c(map_xsize,map_ysize,3)
	For x=0 To map_xsize
		For y=0 To map_ysize
			map_c(x,y,0)=map(x,y,0)
			map_c(x,y,1)=map(x,y,1)
			map_c(x,y,2)=map(x,y,2)
			map_c(x,y,3)=map(x,y,3)
		Next
	Next
	
	;Auf 0|0 setzen
	e_x=0
	e_y=0
	
	;Start Time setzen
	e_starttime=MilliSecs()
	
	;Schließen
	CloseFile(stream)
	
	;Info Text?
	map_briefing=0
	Dim map_info$(17)
	If FileType(root$+name$+".txt")=1 Then
		stream=ReadFile(root$+name$+".txt")
		i=0
		While Not Eof(stream)
			map_info$(i)=ReadLine(stream)
			i=i+1
			If i=18 Then Exit
		Wend
		CloseFile(stream)
		map_briefing=1
	EndIf
	
	e_map_reset(0)
	
	;Mapcycle
	e_sv_mapcyclems=MilliSecs()
	e_sv_round=0
	
	;Ausgabe
	con_add("Map "+name$+".map loaded",0)
	hud_mapload=1
	Return 1
		
End Function