@@ -6,7 +6,7 @@ const coords = @import("coordinateOps.zig").coords;
66
77pub const Unit = struct { id : u32 = undefined , hp : u32 = undefined , x : u32 = undefined , y : u32 = undefined , owner : ? * Player = undefined };
88
9- pub const Field = struct { unit_id : ? u32 , res_hp : ? u32 };
9+ pub const Field = struct { unit : ? * Unit , res_hp : ? u32 };
1010
1111pub const Board = struct {
1212 fields : []Field ,
@@ -18,7 +18,7 @@ pub const Board = struct {
1818 const b = Board { .fields = try allocator .alloc (Field , x * y ), .x = x , .y = y , .allocator = allocator };
1919 errdefer allocator .free (b .fields );
2020 for (b .fields ) | * f | {
21- f .* = Field { .unit_id = null , .res_hp = null };
21+ f .* = Field { .unit = null , .res_hp = null };
2222 }
2323 return b ;
2424 }
@@ -41,7 +41,7 @@ pub const Board = struct {
4141 for (0.. self .y ) | yi | {
4242 for (0.. self .x ) | xi | {
4343 const f = self .getField (@intCast (xi ), @intCast (yi ));
44- if (f .res_hp != null and f .unit_id == null ) {
44+ if (f .res_hp != null and f .unit == null ) {
4545 const dist = distance (x , y , @intCast (xi ), @intCast (yi ));
4646 if (dist < minDist ) {
4747 minDist = dist ;
@@ -57,18 +57,18 @@ pub const Board = struct {
5757 for (0.. self .y ) | yi | {
5858 for (0.. self .x ) | xi | {
5959 self .fields [xi * self .y + yi ].res_hp = null ;
60- self .fields [xi * self .y + yi ].unit_id = null ;
60+ self .fields [xi * self .y + yi ].unit = null ;
6161 }
6262 }
6363 }
6464
65- pub fn printUnits (self : * Board , game : * Game ) void {
65+ pub fn printUnits (self : * Board ) void {
6666 print ("units:\n " , .{});
6767 for (0.. self .y ) | yi | {
6868 for (0.. self .x ) | xi | {
6969 const f = self .getField (@intCast (xi ), @intCast (yi ));
70- if (f .unit_id ) | id | {
71- print ("{c}" , .{game . units . get ( id ) .? .owner .? .name .items [0 ]});
70+ if (f .unit ) | u | {
71+ print ("{c}" , .{u .owner .? .name .items [0 ]});
7272 } else print ("-" , .{});
7373 }
7474 print ("\n " , .{});
@@ -183,14 +183,14 @@ pub const Game = struct {
183183 unitPtr .owner = player ;
184184 try player .units .put (unitPtr .id , unitPtr );
185185 try self .units .put (unitPtr .id , unitPtr );
186- self .board .getField (unitPtr .x , unitPtr .y ).unit_id = unitPtr . id ;
186+ self .board .getField (unitPtr .x , unitPtr .y ).unit = unitPtr ;
187187 }
188188
189189 pub fn deleteUnit (self : * Game , id : u32 ) void {
190190 const unit = self .units .get (id ).? ;
191191 const player = unit .owner .? ;
192192
193- self .board .getField (unit .x , unit .y ).unit_id = null ;
193+ self .board .getField (unit .x , unit .y ).unit = null ;
194194 _ = player .units .remove (unit .id );
195195 _ = self .units .remove (id );
196196
@@ -269,5 +269,5 @@ test "clear" {
269269 game .clear ();
270270 try std .testing .expectEqual (0 , game .players .items .len );
271271 try std .testing .expectEqual (false , game .units .contains (0 ));
272- try std .testing .expectEqual (null , game .board .getField (0 , 0 ).unit_id );
272+ try std .testing .expectEqual (null , game .board .getField (0 , 0 ).unit );
273273}
0 commit comments