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

Fix how AI handles an unexpected EndBattle event #341

Merged
merged 1 commit into from Sep 13, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+7 −5
Diff settings

Always

Just for now

Copy path View file
@@ -320,6 +320,10 @@ impl Ai {
}

pub fn command(&mut self, state: &State) -> Option<Command> {
if state.battle_result().is_some() {
info!("AI: The battle has ended, can't create new commands.");
return None;
}
let mut ids = state::players_agent_ids(state, self.id);
state::sort_agent_ids_by_distance_to_enemies(state, &mut ids);
for agent_id in ids {
@@ -7,6 +7,7 @@ use core::tactical_map::{
};

pub fn check(state: &State, command: &Command) -> Result<(), Error> {
trace!("check: {:?}", command);
if state.battle_result().is_some() {
return Err(Error::BattleEnded);
}
Copy path View file
@@ -247,17 +247,14 @@ impl Battle {
fn do_ai(&mut self, context: &mut Context) -> Box<dyn Action> {
debug!("AI: <");
let mut actions = Vec::new();
loop {
let command = self.ai.command(&self.state).unwrap();
while let Some(command) = self.ai.command(&self.state) {
debug!("AI: command = {:?}", command);
actions.push(self.do_command_inner(context, &command));
actions.push(action::Sleep::new(time_s(0.3)).boxed());
if let command::Command::EndTurn(_) = command {
break;
}
if self.state.battle_result().is_some() {
break;
}
assert!(self.state.battle_result().is_none());
}
debug!("AI: >");
action::Sequence::new(actions).boxed()
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.