From 075432e75fcde8ef4e9677077d03f2b3704d1220 Mon Sep 17 00:00:00 2001 From: Mark de Wever Date: Sat, 18 Nov 2006 15:25:14 +0000 Subject: [PATCH] Added a modulo for set_variable wml, ...it uses the new itoa function of my previous commit. Also the int(atof(string)) which other similar code uses is not required so didn't use that either. Might be nice to convert the existing code as well. --- changelog | 2 +- src/game_events.cpp | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/changelog b/changelog index 5478ee1b53c..025410c5f07 100644 --- a/changelog +++ b/changelog @@ -69,7 +69,7 @@ Version 1.3-svn: * units can now have victory animations, usable with the WML tag 'victory_anim' * [event]s can now be written also inside [era]s (the [event]s are included in every scenario played using that era) - * new operation for set_variable : divide + * new operations for set_variable : divide and modulo * Animations now use duration= tag instead of begin= and end= (backward * Animations now have a frequency= filter to allow to tweak realtive rarety compatible) diff --git a/src/game_events.cpp b/src/game_events.cpp index aa99ac80d2c..eb4b1035007 100644 --- a/src/game_events.cpp +++ b/src/game_events.cpp @@ -1,5 +1,4 @@ /* $Id$ */ -/* $Id$ */ /* Copyright (C) 2003 by David White Part of the Battle for Wesnoth Project http://www.wesnoth.org/ @@ -887,6 +886,19 @@ bool event_handler::handle_event_command(const queued_event& event_info, } } + const std::string& modulo = cfg["modulo"]; + if(modulo.empty() == false) { + int value = atoi(var.c_str()); + int divider = atoi(modulo.c_str()); + if (divider == 0) { + ERR_NG << "division by zero on variable " << name << "\n"; + return rval; + } else { + value %= divider; + var = utils::itoa(value); + } + } + // random generation works as follows: // random=[comma delimited list] // Each element in the list will be considered a separate choice,