Differences From Artifact [3baab0ddf11cca7d]:
- File
src/game.d
- 2012-07-14 14:22:32 - part of checkin [a0c3529225] on branch trunk - code cleanup (user: kinaba) [annotate]
- 2012-07-14 16:58:31 - part of checkin [b1ce0206cd] on branch trunk - Revert. (user: kinaba) [annotate]
To Artifact [a105238bfa87f17a]:
- File
src/game.d
- 2012-07-14 17:20:35 - part of checkin [b8acb5f918] on branch trunk - trampoline parsing and rendering. (user: kinaba) [annotate]
88 88
89 //////////////////////////////////////////////////////////////////////////////// 89 ////////////////////////////////////////////////////////////////////////////////
90 90
91 class Map 91 class Map
92 { 92 {
93 mixin DeriveShow; 93 mixin DeriveShow;
94 94
95 static Map load(string[] raw_data, string[string] params) | 95 static Map load(string[] raw_data, string[string] params, char[char] tra
96 { 96 {
97 // TODO: choose optimal representation. 97 // TODO: choose optimal representation.
98 return new Map(raw_data, params); | 98 return new Map(raw_data, params, trampo);
99 } 99 }
100 100
101 char[][] data; 101 char[][] data;
102 Pos robot; 102 Pos robot;
103 Pos lift; 103 Pos lift;
104 int waterproof; 104 int waterproof;
> 105 Pos[char] tr_target;
> 106 Pos[][char] tr_source;
105 107
106 Map clone() const { return new Map(this); } 108 Map clone() const { return new Map(this); }
107 this(in Map m) { 109 this(in Map m) {
108 foreach(s; m.data) 110 foreach(s; m.data)
109 this.data ~= s.dup; 111 this.data ~= s.dup;
110 this.robot = m.robot.clone(); 112 this.robot = m.robot.clone();
111 this.lift = m.lift.clone(); 113 this.lift = m.lift.clone();
112 this.waterproof = m.waterproof; 114 this.waterproof = m.waterproof;
113 } 115 }
114 116
115 this(string[] raw_data, string[string] params) | 117 this(string[] raw_data, string[string] params, char[char] trampo)
116 { 118 {
117 int width = 0; 119 int width = 0;
118 foreach(r; raw_data) 120 foreach(r; raw_data)
119 width = max(width, r.length); 121 width = max(width, r.length);
120 foreach(r; raw_data) { 122 foreach(r; raw_data) {
121 this.data ~= r.dup; 123 this.data ~= r.dup;
122 this.data[$-1].length = width; 124 this.data[$-1].length = width;
................................................................................................................................................................................
126 for(int y=1; y<=H; ++y) 128 for(int y=1; y<=H; ++y)
127 for(int x=1; x<=W; ++x) { 129 for(int x=1; x<=W; ++x) {
128 if(this[y,x] == 'R') 130 if(this[y,x] == 'R')
129 this.robot = new Pos(y,x); 131 this.robot = new Pos(y,x);
130 if(this[y,x] == 'L' || this[y,x] == 'O') 132 if(this[y,x] == 'L' || this[y,x] == 'O')
131 this.lift = new Pos(y,x); 133 this.lift = new Pos(y,x);
132 } 134 }
> 135
> 136 Pos[char] tr_pos;
> 137 for(int y=1; y<=H; ++y)
> 138 for(int x=1; x<=W; ++x) {
> 139 char c = this[y,x];
> 140 if('1'<=c && c<='9' || 'A'<=c&&c<='I')
> 141 tr_pos[c] = new Pos(y,x);
> 142 }
133 143
134 this.waterproof = params.get("Waterproof", "5").to!int(); 144 this.waterproof = params.get("Waterproof", "5").to!int();
> 145 foreach(fr,to; trampo) {
> 146 tr_target[fr] = tr_pos[to];
> 147 if(to !in tr_source) tr_source[to] = [];
> 148 tr_source[to] ~= tr_pos[to];
> 149 }
135 } 150 }
136 151
137 const @property { 152 const @property {
138 int H() { return data.length; } 153 int H() { return data.length; }
139 int W() { return data[0].length; } 154 int W() { return data[0].length; }
140 } 155 }
141 156
................................................................................................................................................................................
281 string[string] params; 296 string[string] params;
282 297
283 // Raw map data; read until empty line. 298 // Raw map data; read until empty line.
284 for(string line; !(line=input.readln().chomp()).empty; ) 299 for(string line; !(line=input.readln().chomp()).empty; )
285 raw_data ~= line; 300 raw_data ~= line;
286 301
287 // Additional commands; read until EOF. 302 // Additional commands; read until EOF.
> 303 char[char] trampo;
288 for(string line; !(line=input.readln()).empty; ) { 304 for(string line; !(line=input.readln()).empty; ) {
289 string[] ss = line.split(); 305 string[] ss = line.split();
290 if( ss.length == 2 ) 306 if( ss.length == 2 )
291 params[ss[0]] = ss[1]; 307 params[ss[0]] = ss[1];
> 308 if( ss.length == 4 && ss[0]=="Trampoline" && ss[2]=="tar
> 309 trampo[ss[1][0]] = ss[3][0];
292 } 310 }
293 311
294 return load(raw_data, params); | 312 return load(raw_data, params, trampo);
295 } 313 }
296 314
297 static Game load(string[] raw_data, string[string] params) | 315 static Game load(string[] raw_data, string[string] params, char[char] tr
298 { 316 {
299 return new Game(raw_data, params); | 317 return new Game(raw_data, params, trampo);
300 } 318 }
301 319
302 this(string[] raw_data, string[string] params) | 320 this(string[] raw_data, string[string] params, char[char] trampo)
303 { 321 {
304 this.map = Map.load(raw_data, params); | 322 this.map = Map.load(raw_data, params, trampo);
305 this.water = Water.load(params); 323 this.water = Water.load(params);
306 } 324 }
307 325
308 Game clone() const { return new Game(this); } 326 Game clone() const { return new Game(this); }
309 this(in Game g) { 327 this(in Game g) {
310 map = g.map.clone(); 328 map = g.map.clone();
311 water = g.water.clone(); 329 water = g.water.clone();