File: genDEF

package info (click to toggle)
njam 1.25-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 5,376 kB
  • sloc: cpp: 3,810; sh: 2,958; perl: 384; ansic: 236; objc: 224; makefile: 112
file content (126 lines) | stat: -rw-r--r-- 3,249 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/perl -w

# Programmed by:	Jalal A. Elhusseini
# Date:			DEC 8, 2003

# Perl script to Convert a '.COOP' file used by NJAM 
# to a '.DEF' level definition file.

$ARGC = $#ARGV + 1; # Get number of arguments.

$WORLD_HEADER = "";
$LEVEL_END = "[EndEndEnd]";

$Row_START   = 0;
$Row_END     = 23;
$Col_START   = 0;
$Col_END     = 27;
$World_START = 0;
$World_END   = 19;

$WORLD_COUNT = 0;
$WORLDS_MAX  = 20;

$BLOCK        = 0x0;
$EMPTY        = 0x1;
$GHOST_HOME   = 0x2;
$DOOR         = 0x3;
$POWER        = 0x4;
$COOKIE       = 0x5;
$FREEZE       = 0x6;
$TRAP         = 0x7;
$WARP         = 0x8;
$INVISIBILITY = 0x9;

%Elements = ();		#clear hash 1st
%Elements = (	   0	=>	B,
	     	   1	=>	E,
	     	   2	=>	G,
	     	   3	=>	D,
	     	   4	=>	P,
	     	   5	=>	C,
	     	   6	=>	F,
	     	   7	=>	T,
	     	   8	=>	W,
	     	   9	=>	I, );

@Init28 = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);

# ARGUMENT ERROR Message
if ($ARGC < 2 )
{
	print "\n\n\n";
	print "Usage: genDEF INPUT_FILE (OUTPUT_FILE)\n";
	print "Do NOT include a file extension on the command line.\n";
	print "Default extension for Input  file is .COOP\n";
	print "Default extention for Output file is .DEF\n";
	print "If OUTPUT_FILE not entered then OUTPUT_FILE = INPUT_FILE'\n";
	print "File names will be capitalized.\n";
	print "\n\n\n";
}

# Open Input and output files
if ($ARGC >= 1)
{
	$INPUT_FILE_TEMP = $ARGV[0];
	$_ = $INPUT_FILE_TEMP; tr/a-z/A-Z/; $INPUT_FILE_TEMP = $_;
	$INPUT_FILE = "$INPUT_FILE_TEMP".".COOP";
	open (D_IN, $INPUT_FILE) || die "Sorry, I can't open $INPUT_FILE.\n";
	binmode D_IN;
	print "Input File = $INPUT_FILE.\n";

	if ( $ARGC == 1 ) { $OUTPUT_FILE = "$INPUT_FILE_TEMP".".DEF"; }
	else
	{ $OUTPUT_FILE = $ARGV[1];
	  $_ = $OUTPUT_FILE; tr/a-z/A-Z/; $OUTPUT_FILE = $_.".DEF";
	}
	open (D_OUT,">$OUTPUT_FILE") || die "Sorry, I can't create $OUTPUT_FILE.\n";
	print "Output File = $OUTPUT_FILE.\n";

# Create a 2D array
        for ( $Row_count = $Row_START ; $Row_count <= $Row_END  ; $Row_count++ )
        { $World[$Row_count] = [@Init]; }

# Read 20 Worlds from Input file
        for ( $World_count = $World_START ; $World_count <= $World_END  ; $World_count++ )
        {

# Read a World data into a temp 2D array.
         for ( $LOOP0 = $Col_START ; $LOOP0 <= $Col_END  ; $LOOP0++ )
         {
	  for ( $LOOP1 = $Row_START ; $LOOP1 <= $Row_END  ; $LOOP1++ )
	  { 
	   read D_IN, $Data0, 1;
	   $Data1 = ord($Data0);	   
	   print "$Data1,";
	   $World[$LOOP1][$LOOP0] = $Elements{$Data1};
	  }
	  print "\n";
         }

# Write World to the output file.
	 # Generate a World name
	 $WORLD_HEADER = "[".$INPUT_FILE_TEMP."_".$World_count."]\n";
	 printf D_OUT "%s", "$WORLD_HEADER";
	 print "Writing World $WORLD_HEADER";
         for ( $LOOP0 = $Row_START ; $LOOP0 <= $Row_END  ; $LOOP0++ )
         {
	  for ( $LOOP1 = $Col_START ; $LOOP1 <= $Col_END  ; $LOOP1++ )
	  { 
	   printf D_OUT "%s", $World[$LOOP0][$LOOP1];
	   if ( $LOOP1 <  $Col_END) { printf D_OUT "%s", ","; }
	  }
	  printf D_OUT "%s", "\n";
	 }

# next World
	 printf D_OUT "%s", "\n";
        } # next World

# Write TAG for the end of the .DEF file
	printf D_OUT "%s", "$LEVEL_END\n";

# close opened files
	close (D_IN);
	close (D_OUT);
}