aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Blot <loic.blot@unix-experience.fr>2015-01-26 16:47:03 +0100
committerLoic Blot <loic.blot@unix-experience.fr>2015-02-10 14:16:28 +0100
commit368496b612931323b589abc1cb07fdc4c8c02a6c (patch)
tree42cb27510946c5d554c5e3dcd1f0163a5563d7d6
parentdd2bb950be36c3ae34caacfe62df391612364f8a (diff)
downloadminetest-368496b612931323b589abc1cb07fdc4c8c02a6c.tar.gz
minetest-368496b612931323b589abc1cb07fdc4c8c02a6c.tar.bz2
minetest-368496b612931323b589abc1cb07fdc4c8c02a6c.zip
Craftdef.cpp: Improve loop and mathematics for CraftDefinitionShaped::check
-rw-r--r--src/craftdef.cpp33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/craftdef.cpp b/src/craftdef.cpp
index afc41303f..80937ccb7 100644
--- a/src/craftdef.cpp
+++ b/src/craftdef.cpp
@@ -418,27 +418,28 @@ bool CraftDefinitionShaped::check(const CraftInput &input, IGameDef *gamedef) co
return false; // it was empty
// Different sizes?
- if(inp_max_x - inp_min_x != rec_max_x - rec_min_x)
- return false;
- if(inp_max_y - inp_min_y != rec_max_y - rec_min_y)
+ if(inp_max_x - inp_min_x != rec_max_x - rec_min_x ||
+ inp_max_y - inp_min_y != rec_max_y - rec_min_y)
return false;
// Verify that all item names in the bounding box are equal
unsigned int w = inp_max_x - inp_min_x + 1;
unsigned int h = inp_max_y - inp_min_y + 1;
- for(unsigned int y=0; y<h; y++)
- for(unsigned int x=0; x<w; x++)
- {
- unsigned int inp_x = inp_min_x + x;
- unsigned int inp_y = inp_min_y + y;
- unsigned int rec_x = rec_min_x + x;
- unsigned int rec_y = rec_min_y + y;
-
- if(!inputItemMatchesRecipe(
- inp_names[inp_y * inp_width + inp_x],
- rec_names[rec_y * rec_width + rec_x], gamedef->idef())
- ){
- return false;
+
+ for(unsigned int y=0; y < h; y++) {
+ unsigned int inp_y = (inp_min_y + y) * inp_width;
+ unsigned int rec_y = (rec_min_y + y) * rec_width;
+
+ for(unsigned int x=0; x < w; x++) {
+ unsigned int inp_x = inp_min_x + x;
+ unsigned int rec_x = rec_min_x + x;
+
+ if(!inputItemMatchesRecipe(
+ inp_names[inp_y + inp_x],
+ rec_names[rec_y + rec_x], gamedef->idef())
+ ) {
+ return false;
+ }
}
}