Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Climate change: Check unit activities on tiles surrounding changed one #2466

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading