Skip to content

Commit

Permalink
Climate change: Check unit activities on tiles surrounding changed one
Browse files Browse the repository at this point in the history
See osdn #44155
Closes #1064.

Signed-off-by: Marko Lindqvist <[email protected]>
  • Loading branch information
cazfi authored and jwrober committed Dec 24, 2024
1 parent 5304f6f commit f50a634
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 34 deletions.
8 changes: 1 addition & 7 deletions server/maphand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,7 @@ void climate_change(bool warming, int effect)
update_tile_knowledge(ptile);

// Check the unit activities.
unit_list_iterate(ptile->units, punit)
{
if (!can_unit_continue_current_activity(punit)) {
unit_activity_handling(punit, ACTIVITY_IDLE);
}
}
unit_list_iterate_end;
unit_activities_cancel_all_illegal_area(ptile);
} else if (old == tnew) {
// This counts toward a climate change although nothing is changed.
effect--;
Expand Down
14 changes: 2 additions & 12 deletions server/srv_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1712,12 +1712,7 @@ void end_turn()

/* Unit activities at the target tile and its neighbors may now
* be illegal because of present reqs. */
unit_activities_cancel_all_illegal(ptile);
adjc_iterate(&(wld.map), ptile, n_tile)
{
unit_activities_cancel_all_illegal(n_tile);
}
adjc_iterate_end;
unit_activities_cancel_all_illegal_area(ptile);
}
}
whole_map_iterate_end;
Expand Down Expand Up @@ -1747,12 +1742,7 @@ void end_turn()

/* Unit activities at the target tile and its neighbors may now
* be illegal because of !present reqs. */
unit_activities_cancel_all_illegal(ptile);
adjc_iterate(&(wld.map), ptile, n_tile)
{
unit_activities_cancel_all_illegal(n_tile);
}
adjc_iterate_end;
unit_activities_cancel_all_illegal_area(ptile);
}
}
whole_map_iterate_end;
Expand Down
35 changes: 20 additions & 15 deletions server/unittools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,22 @@ void unit_activities_cancel_all_illegal(const struct tile *ptile)
unit_list_iterate_end;
}

/**
* Cancel all illegal activities done by units at the specified tile,
* and surrounding tiles. For most rulesets this is for cancelling
* irrigation on surrounding tiles when the central tile was the only
* source of water, but does not provide water any more.
*/
void unit_activities_cancel_all_illegal_area(const struct tile *ptile)
{
unit_activities_cancel_all_illegal(ptile);
adjc_iterate(&wld.map, ptile, ptile2)
{
unit_activities_cancel_all_illegal(ptile2);
}
adjc_iterate_end;
}

/**
Progress settlers in their current tasks,
and units that is pillaging.
Expand Down Expand Up @@ -934,21 +950,10 @@ static void unit_activity_complete(struct unit *punit)
unit_list_iterate_end;
}

tile_changing_activities_iterate(act)
{
if (act == activity) {
/* Some units nearby may not be able to continue their action,
* such as building irrigation if we removed the only source
* of water from them. */
adjc_iterate(&(wld.map), ptile, ptile2)
{
unit_activities_cancel_all_illegal(ptile2);
}
adjc_iterate_end;
break;
}
}
tile_changing_activities_iterate_end;
// Some units nearby may not be able to continue their action,
// such as building irrigation if we removed the only source
// of water from them.
unit_activities_cancel_all_illegal_area(ptile);
}

if (activity == ACTIVITY_FORTIFYING) {
Expand Down
1 change: 1 addition & 0 deletions server/unittools.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ void unit_did_action(struct unit *punit);
bool unit_can_be_retired(struct unit *punit);

void unit_activities_cancel_all_illegal(const struct tile *ptile);
void unit_activities_cancel_all_illegal_area(const struct tile *ptile);

void unit_get_goods(struct unit *punit);

Expand Down

0 comments on commit f50a634

Please sign in to comment.