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

Basic multiturn irrigation #555

Draft
wants to merge 7 commits into
base: Development
Choose a base branch
from

Conversation

KulkoBSW
Copy link
Contributor

@KulkoBSW KulkoBSW commented Feb 14, 2025

@TomWerner
I have created a first version and am looking for a bit of feedback before diving deeper in,

What it does for now:

  • Make irrigation take 4 turns
  • Set the worker busy while working
    • Multiple workers working on the same project

What it does not for now:

  • animations
  • use values from Terraform (instead every number is hardcoded variable)
  • Difference between workers and slaves.
  • Different update rules for Multiplayer
  • Saving and loading

What I am not sure about:
I update the progress on the end of the current turn (Which seems to fit with the functionality described in the doc). But you handle other similar things (healing) in OnBeginTurn.
How would I even begin to make a different behavior Multiplayer (update each Worker individually) vs. Singleplayer (Update all workers at one point and then check if the Job is done)

@KulkoBSW KulkoBSW marked this pull request as draft February 14, 2025 17:47
@TomWerner
Copy link
Contributor

How would I even begin to make a different behavior Multiplayer (update each Worker individually) vs. Singleplayer (Update all workers at one point and then check if the Job is done)

I wouldn't worry too much about multiplayer yet, just single player to start seems very reasonable.


Overall I think this looks good!

One other code pointer, I think we can set the button TooltipText field here which would be a nice eventual improvement.

@@ -251,6 +251,7 @@ public static Tuple<int, int> NeighborCoordinate(int X, int Y, TileDirection dir
}
return Tuple.Create(X, Y);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you revert this extra line?

@@ -69,6 +70,7 @@ internal static void AdvanceTurn() {
}
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you revert this extra line?

if (currentWorkerJob.Equals(unit.WorkerJob)) {
totalProgress += unit.WorkerProgressTowardsJob;
} else {
// reset Unit working on other jobs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be reset if the worker is selected/moved while doing the work - otherwise you can start irrigating on a legal tile, then move to a different tile and let the irrigation finish.

Here I managed to irrigate a hill

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, I knew that but forgot to add under things not yet working.

C7Engine/TileExtensions.cs Show resolved Hide resolved
if (currentWorkerJob == null) {
Log.Error($"can't call method FinishWorkerJob without WorkerJob");
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave out this null check - there's already a null check in the caller.

continue;
}

if (currentWorkerJob.Equals(unit.WorkerJob)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to use .Equals instead of ==? (Genuine question, I'm not super well versed in the nuances of C#)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I checked, you are right these are just my habits from other programming languages.

if (currentWorkerJob == null) {
Log.Error($"can't call method FinishWorkerJob without WorkerJob");
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly I'm not sure this null check is necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method is designed to be reusable, which is why I added the line. Right now a nullpointer would be thrown when I compare with a nullvalue, but that won't be the case anymore once I use ==. But still if somebody would call the function with null it would behave rather unintuitive and might create hard to find bugs which is why I thought it better to add the line. If we are concerned Efficiency/Performance I can also take it back out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a question of efficiency or performance, but more a question of why this method is special compared to all other methods - most other methods don't have explicit checks that the arguments are non-null.

You could probably get away with a comment like // REQUIRED: currentWorkerJob != null

C7Engine/MapUnitExtensions.cs Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants