]> git.pond.sub.org Git - empserver/commitdiff
fairland: Check first two continent sectors properly
authorMarkus Armbruster <armbru@pond.sub.org>
Tue, 11 Aug 2020 05:52:45 +0000 (07:52 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Tue, 5 Jan 2021 09:41:36 +0000 (10:41 +0100)
grow_continents() places the first two continent sectors without
checking for collisions or minimum distance.  Unlikely to be an issue
in practice, as growing such a continent will almost certainly fail.
Fix it anyway.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/util/fairland.c

index 644412c5cc515a5f38c9ab668073a15255c05e12..3025f86e85846775295475fa521e961ecf608513 100644 (file)
@@ -791,13 +791,17 @@ grow_continents(void)
     int c, secs;
 
     for (c = 0; c < nc; ++c) {
-       sectx[c][0] = capx[c];
-       secty[c][0] = capy[c];
-       own[sectx[c][0]][secty[c][0]] = c;
-       sectx[c][1] = new_x(capx[c] + 2);
-       secty[c][1] = capy[c];
-       own[sectx[c][1]][secty[c][1]] = c;
-       isecs[c] = 2;
+       isecs[c] = 0;
+       if (!try_to_grow(c, capx[c], capy[c], di)
+           || !try_to_grow(c, new_x(capx[c] + 2), capy[c], di)) {
+           done = 0;
+           continue;
+       }
+    }
+
+    if (!done) {
+       qprint("No room for continents\n");
+       return 0;
     }
 
     for (secs = 2; secs < sc && done; secs++) {