@@ -24,7 +24,7 @@ int ft_util_distance(t_pos pos1, t_pos pos2)
2424 return ((int )(x + y ));
2525}
2626
27- int nextUnit = 1 ;
27+ int nextUnit = 2 ;
2828
2929void ft_on_tick (unsigned long tick )
3030{
@@ -35,9 +35,9 @@ void ft_on_tick(unsigned long tick)
3535 if (ft_get_core_own () && ft_get_core_own ()-> s_core .balance >= core_get_unitConfig (nextUnit )-> cost )
3636 {
3737 core_action_createUnit (nextUnit );
38- nextUnit ++ ;
39- if (nextUnit > 2 )
40- nextUnit = 0 ;
38+ nextUnit -- ;
39+ if (nextUnit < 0 )
40+ nextUnit = 2 ;
4141 }
4242
4343 for (int i = 0 ; game .objects && game .objects [i ]; i ++ )
@@ -55,6 +55,12 @@ void ft_on_object_ticked(t_obj *unit, unsigned long tick)
5555 if (unit -> s_unit .team_id != ft_get_core_own ()-> s_core .team_id )
5656 return ;
5757
58+ if (unit -> s_unit .balance > 0 && unit -> s_unit .unit_type != UNIT_CARRIER )
59+ {
60+ core_action_transferMoney (unit , (t_pos ){unit -> pos .x + 1 , unit -> pos .y }, unit -> s_unit .balance );
61+ return ;
62+ }
63+
5864 int typeId = unit -> s_unit .unit_type ;
5965 if (typeId == UNIT_WARRIOR )
6066 {
@@ -66,57 +72,27 @@ void ft_on_object_ticked(t_obj *unit, unsigned long tick)
6672 }
6773 else if (typeId == UNIT_MINER )
6874 {
69- // money dropping test - uncomment to test
70- // if (unit->s_unit.balance > 0)
71- // {
72- // core_action_transferMoney(unit, (t_pos){unit->pos.x + 1, unit->pos.y}, unit->s_unit.balance);
73- // return;
74- // }
75-
76- t_obj * nearestResourceOrMoney = ft_get_resource_money_nearest (unit -> pos );
77- if (nearestResourceOrMoney )
78- move_unit_to (unit , nearestResourceOrMoney -> pos );
75+ t_obj * nearestResource = ft_get_resource_nearest (unit -> pos );
76+ if (nearestResource )
77+ move_unit_to (unit , nearestResource -> pos );
7978 else
8079 move_unit_to (unit , ft_get_core_opponent ()-> pos );
8180 }
8281 else if (typeId == UNIT_CARRIER )
8382 {
84- bool isTouchingCore = ft_util_distance (unit -> pos , ft_get_core_own ()-> pos ) <= 1 ;
85- bool isTouchingUnitWithMoney = false;
86- t_obj * closestUnitWithMoney = NULL ;
87-
88- t_obj * * units = game .objects ;
89- double distance = 999999 ;
90- for (int j = 0 ; units && units [j ]; j ++ )
83+ unsigned int balance = unit -> s_unit .balance ;
84+ if (balance > 0 )
9185 {
92- if (units [j ]-> state != STATE_ALIVE || units [j ]-> type != OBJ_UNIT )
93- continue ;
94- if (units [j ]-> id == unit -> id )
95- continue ; // dont transfer money from yourself
96- if (units [j ]-> s_unit .balance > 0 )
97- {
98- if (ft_util_distance (unit -> pos , units [j ]-> pos ) <= 1 )
99- {
100- isTouchingUnitWithMoney = true;
101- closestUnitWithMoney = units [j ];
102- break ;
103- }
104- if (ft_util_distance (unit -> pos , units [j ]-> pos ) < distance )
105- {
106- closestUnitWithMoney = units [j ];
107- distance = ft_util_distance (unit -> pos , units [j ]-> pos );
108- }
109- break ;
110- }
86+ move_unit_to (unit , ft_get_core_own ()-> pos );
87+ core_action_transferMoney (unit , ft_get_core_own ()-> pos , balance );
11188 }
112- if (isTouchingCore && unit -> s_unit .balance > 0 )
113- core_action_transferMoney (unit , ft_get_core_own ()-> pos , unit -> s_unit .balance );
114- else if (isTouchingUnitWithMoney )
115- core_action_transferMoney (closestUnitWithMoney , unit -> pos , closestUnitWithMoney -> s_unit .balance );
116-
117- if (unit -> s_unit .balance <= 0 && closestUnitWithMoney != NULL )
118- move_unit_to (unit , closestUnitWithMoney -> pos );
11989 else
120- move_unit_to (unit , ft_get_core_own ()-> pos );
90+ {
91+ t_obj * nearestMoney = ft_get_money_nearest (unit -> pos );
92+ if (nearestMoney )
93+ move_unit_to (unit , nearestMoney -> pos );
94+ else
95+ move_unit_to (unit , ft_get_core_opponent ()-> pos );
96+ }
12197 }
12298}
0 commit comments