@@ -41,7 +41,7 @@ pub const Client = struct {
4141 try std .io .getStdOut ().writer ().print ("server closed the connection\n " , .{});
4242 return false ;
4343 }
44- print ("MSG: {s}\n " , .{buff .items });
44+ // print("MSG: {s}\n", .{buff.items});
4545
4646 try self .parse (buff .items , allocator );
4747 return true ;
@@ -70,7 +70,6 @@ pub const Client = struct {
7070 try self .send ("n" );
7171 try self .send (&(self .name ));
7272 try self .send ("\n " );
73- print ("x: {d}, y: {d}\n " , .{ self .game .? .board .x , self .game .? .board .y });
7473 }
7574 },
7675 @intFromEnum (Message .Type .yes ) = > {
@@ -119,8 +118,6 @@ pub const Client = struct {
119118 unit .y = try std .fmt .parseUnsigned (u32 , it3 .next ().? , 10 );
120119 unit .hp = try std .fmt .parseUnsigned (u32 , it3 .next ().? , 10 );
121120 try self .game .? .newUnit (playerName , unit );
122-
123- print ("{d} {d} {d} {d}\n " , .{ self .game .? .units .get (unit .id ).? .id , unit .x , self .game .? .units .get (unit .id ).? .y , unit .hp });
124121 }
125122 }
126123 self .game .? .printPlayerNames ();
@@ -148,7 +145,6 @@ pub const Client = struct {
148145 const hp = try std .fmt .parseUnsigned (u32 , it .next ().? , 10 );
149146
150147 self .game .? .board .getField (x , y ).res_hp = hp ;
151- // self.game.?.board.printResources();
152148 },
153149 @intFromEnum (Message .Type .unit ) = > {
154150 var it = std .mem .tokenizeAny (u8 , buff [1.. ], " \n " );
@@ -158,9 +154,7 @@ pub const Client = struct {
158154 const x = try std .fmt .parseUnsigned (u32 , it .next ().? , 10 );
159155 const y = try std .fmt .parseUnsigned (u32 , it .next ().? , 10 );
160156
161- print ("{s} got new unit\n " , .{playerName });
162157 try self .game .? .newUnit (playerName , Unit { .id = id , .x = x , .y = y , .hp = 100 });
163- self .game .? .board .printUnits (& self .game .? );
164158 },
165159 @intFromEnum (Message .Type .leave ) = > {
166160 const playerName = buff [1.. ]; // player name
@@ -170,10 +164,8 @@ pub const Client = struct {
170164 self .state = State .Ready ;
171165 try self .send ("j\n " );
172166 } else {
173- print ("{s} left\n " , .{playerName });
174167 try self .game .? .deletePlayer (playerName );
175168 }
176- self .game .? .board .printUnits (& self .game .? );
177169 },
178170 @intFromEnum (Message .Type .lost ) = > {
179171 const playerName = buff [1.. ]; // player name
@@ -227,22 +219,22 @@ pub const Client = struct {
227219 },
228220 @intFromEnum (Message .Type .join ) = > {
229221 try self .game .? .newPlayer (buff [1.. ]);
230- print ("{s} joined\n " , .{buff [1.. ]});
231222 },
232223 @intFromEnum (Message .Type .tick ) = > {
233224 const player = self .game .? .findPlayer (& self .name ).? ;
234225 var it = player .units .valueIterator ();
235226 while (it .next ()) | unit | {
236- const fieldc = self .game .? .board .getClosestResourceFieldPosition (unit .* .x , unit .* .y );
237- if (fieldc ) | fc | {
238- const cds = coordOps .towards (unit .* .x , unit .* .y , fc .x , fc .y );
239- const max_len = 10 ; // TO DO figure out max_len from config sent by server
240- var buf : [max_len ]u8 = undefined ;
241- if (cds .x == unit .* .x and cds .y == unit .* .y ) {
242- try self .send ("d" );
243- try self .send (try std .fmt .bufPrint (& buf , "{}" , .{unit .* .id }));
244- try self .send ("\n " );
245- } else {
227+ const max_len = 10 ; // TO DO figure out max_len from config sent by server
228+ var buf : [max_len ]u8 = undefined ;
229+
230+ if (self .game .? .board .getField (unit .* .x , unit .* .y ).res_hp != null ) {
231+ try self .send ("d" );
232+ try self .send (try std .fmt .bufPrint (& buf , "{}" , .{unit .* .id }));
233+ try self .send ("\n " );
234+ } else {
235+ const fieldc = self .game .? .board .getClosestUnoccupiedResourceFieldPosition (unit .* .x , unit .* .y );
236+ if (fieldc ) | fc | {
237+ const cds = coordOps .towards (unit .* .x , unit .* .y , fc .x , fc .y );
246238 try self .send ("m" );
247239 try self .send (try std .fmt .bufPrint (& buf , "{}" , .{unit .* .id }));
248240 try self .send (" " );
@@ -254,9 +246,7 @@ pub const Client = struct {
254246 }
255247 }
256248 },
257- else = > {
258- print ("got invalid message type character {c}\n " , .{t });
259- },
249+ else = > {},
260250 }
261251 }
262252
0 commit comments