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

2706 lighthouses and drifting #923

Merged
merged 2 commits into from
Sep 25, 2020
Merged

Conversation

ennorehling
Copy link
Member

No description provided.

do not check for maintenance in update_lighthouse, but when the lighthouse is used.
@ennorehling ennorehling assigned stm2 and ennorehling and unassigned stm2 Sep 24, 2020
@ennorehling ennorehling requested a review from stm2 September 24, 2020 18:13
@stm2
Copy link
Member

stm2 commented Sep 24, 2020

Da ist noch ein Fehler: in new_building muss update_lighthouse aufgerufen werden, nachdem b->size gesetzt ist.

@@ -403,11 +403,8 @@ building *new_building(const struct building_type * btype, region * r,
     while (*bptr)
         bptr = &(*bptr)->next;
     *bptr = b;
 
-    if (is_lighthouse(b->type)) {
-        update_lighthouse(b);
-    }
     bname = LOC(lang, btype->_name);
     if (!bname) {
         bname = LOC(lang, parameters[P_GEBAEUDE]);
         if (!bname) {
@@ -417,8 +414,11 @@ building *new_building(const struct building_type * btype, region * r,
     assert(bname);
     snprintf(buffer, sizeof(buffer), "%s %s", bname, itoa36(b->no));
     b->name = str_strdup(bname);
     b->size = size;
+    if (is_lighthouse(b->type)) {
+        update_lighthouse(b);
+    }
     return b;
 }

Das ganze Konstrukt scheint mir unnötig kompliziert, zerbrechlich und eigentlich auch ineffizient. Falls in Zukunft irgendwo (meinetwegen durch einen Zauber) die Gebäudegröße erhöht wird (verkleinern wäre egal) und man nicht aufpasst, produziert das wieder neue Fehler. Das Attribut at_lighthouse wird nur in sail benutzt. Wäre es nicht robuster, wenn man in movement() nochmal alle Leuchttürme updated?

Mein Test, mit dem ich den Fehler oben gefunden habe, sah übrigens so aus:

function setup()
    eressea.game.reset()
    conf = [[{
    "calendar" : {
        "months" : [
            { "storm" : 20000, "season" : 0 }
        ],
        "weeks" : [
            "firstweek", "secondweek", "thirdweek"
        ]
      }
    }]]
    eressea.config.parse(conf)
end

function test_storm()
    eressea.settings.set("rules.ship.drifting", "1")
    eressea.settings.set("rules.ship.storms", "1")
    local r1 = region.create(1, 0, 'plain')
    r1.peasants = 0
    local r2 = region.create(2, 0, 'ocean')
    local r2 = region.create(3, 0, 'ocean')
    local r2 = region.create(4, 0, 'ocean')
    local r3 = region.create(5, 0, 'plain')
    r3.peasants = 0
    for x = 0,5 do
      region.create(x, 1, 'ocean')
      region.create(x, -1, 'ocean')
    end
    local f = faction.create('human', "[email protected]", "de")
    local b = building.create(r1, "lighthouse", 100)
    local u1 = unit.create(f, r1, 1)
    local u2 = unit.create(f, r1, 1)
--    b.size = 100
    u2:set_skill("perception", 100)
    u2.building = b
    b.owner = u2
    u2:add_item("money", 100 * 100)
    local sh = ship.create(r1, "dragonship")
    u1:set_skill("sailing", 100)
    u1.number=3
    u1.ship = sh
    sh.owner = u1

    local storm = 0
    for r = 1, 10 do
      u1:clear_orders()
      u1:add_order("NACH o o o o")
      process_orders()
      if r3 ~= u1.region then
        storm = r
        break
      end
      assert_equal(r3, u1.region)
      u1:clear_orders()
      u1:add_order("NACH w w w w")
      process_orders()
      if r1 ~= u1.region then
        storm = r
        break
      end
      assert_equal(r1, u1.region)
    end

    print("stormround: " .. storm)

--    init_reports()
--    write_reports()

    eressea.settings.set("rules.ship.drifting", "0")
    eressea.settings.set("rules.ship.storms", "0")
    assert_true(e > 0 and e < 10)
    assert_not_equal(r1, u1.region)
    assert_not_equal(r3, u1.region)
end

@ennorehling ennorehling merged commit c275468 into develop Sep 25, 2020
@ennorehling ennorehling deleted the 2706-lighthouse-drifting branch March 15, 2021 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants