[Freeciv-Dev] (PR#35866) avoid sprite placement crash
http://bugs.freeciv.org/Ticket/Display.html?id=35866 > If no sprite is available (possible in some tilesets) nothing should be drawn. Instead the code in question here crashes (because of doing mod-0 math). This simple patch fixes it. For 2.1 and development branches - I will commit immediately. -jason Index: client/tilespec.c === --- client/tilespec.c (revision 12631) +++ client/tilespec.c (working copy) @@ -3575,18 +3575,21 @@ int count = sprite_vector_size(&draw->layer[l].base); int ox = draw->layer[l].offset_x, oy = draw->layer[l].offset_y; -/* Pseudo-random reproducable algorithm to pick a sprite. */ -#define LARGE_PRIME 10007 -#define SMALL_PRIME 1009 -assert(count < SMALL_PRIME); -assert((int)(LARGE_PRIME * MAP_INDEX_SIZE) > 0); -count = ((ptile->index - * LARGE_PRIME) % SMALL_PRIME) % count; -if (draw->layer[l].is_tall) { - ox += FULL_TILE_X_OFFSET; - oy += FULL_TILE_Y_OFFSET; +if (count > 0) { + /* Pseudo-random reproducable algorithm to pick a sprite. */ + const int LARGE_PRIME = 10007; + const int SMALL_PRIME = 1009; + + assert(count < SMALL_PRIME); + assert((int)(LARGE_PRIME * MAP_INDEX_SIZE) > 0); + count = ((ptile->index + * LARGE_PRIME) % SMALL_PRIME) % count; + if (draw->layer[l].is_tall) { + ox += FULL_TILE_X_OFFSET; + oy += FULL_TILE_Y_OFFSET; + } + ADD_SPRITE(draw->layer[l].base.p[count], TRUE, ox, oy); } -ADD_SPRITE(draw->layer[l].base.p[count], TRUE, ox, oy); } else { int match_type = draw->layer[l].match_type; ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
[Freeciv-Dev] (PR#9887) AI defense code
http://bugs.freeciv.org/Ticket/Display.html?id=9887 > This patch implements Greg's brilliant defense calculation algorithm which is explained in this ticket. Unlike the current code, it takes into account unit cost, firepower and hitpoints. The downside is that it is more CPU intensive. The biggest problem is still, I see, that it builds way too many city walls and coastal defenses. The next biggest problem is that it builds too many defenders, and not enough (counter-)attackers. But this patch should improve matters anyway, I think. - Per Index: ai/aitools.c === --- ai/aitools.c (revision 12634) +++ ai/aitools.c (working copy) @@ -236,7 +236,7 @@ dcity = tile_get_city(dest_tile); if (dcity && HOSTILE_PLAYER(pplayer, ai, city_owner(dcity))) { /* Assume enemy will build another defender, add it's attack strength */ -struct unit_type *d_type = ai_choose_defender_versus(dcity, punit->type); +struct unit_type *d_type = ai_choose_defender_versus(dcity, punit); danger += unittype_att_rating(d_type, do_make_unit_veteran(dcity, d_type), Index: ai/advmilitary.c === --- ai/advmilitary.c (revision 12634) +++ ai/advmilitary.c (working copy) @@ -52,27 +52,47 @@ Choose the best unit the city can build to defend against attacker v. **/ struct unit_type *ai_choose_defender_versus(struct city *pcity, - const struct unit_type *v) + struct unit *attacker) { struct unit_type *bestunit = NULL; - int best = 0; + double best = 0; + int best_cost = FC_INFINITY; + struct player *pplayer = city_owner(pcity); simple_ai_unit_type_iterate(punittype) { const int move_type = get_unit_move_type(punittype); if (can_build_unit(pcity, punittype) && (move_type == LAND_MOVING || move_type == SEA_MOVING)) { - const int defense = get_virtual_defense_power(v, punittype, - pcity->owner, - pcity->tile, - FALSE, FALSE); + int fpatt, fpdef, defense, attack; + double want, loss, cost = unit_build_shield_cost(punittype); + struct unit *defender; + int veteran = get_unittype_bonus(pcity->owner, pcity->tile, punittype, + EFT_VETERAN_BUILD); - if (defense > best || (defense == best - && unit_build_shield_cost(punittype) <= - unit_build_shield_cost(bestunit))) { -best = defense; + defender = create_unit_virtual(pplayer, pcity, punittype, veteran); + defense = get_total_defense_power(attacker, defender); + attack = get_total_attack_power(attacker, defender); + get_modified_firepower(attacker, defender, &fpatt, &fpdef); + + /* Greg's algorithm. loss is the average number of health lost by + * defender. If loss > attacker's hp then we should win the fight, + * which is always a good thing, since we avoid shield loss. */ + loss = (double) defense * punittype->hp * fpdef / (attack * fpatt); + want = (loss + MAX(0, loss - attacker->hp)) / cost; + +#ifdef NEVER + CITY_LOG(LOG_DEBUG, pcity, "desire for %s against %s(%d,%d) is %.2f", + unit_name_orig(punittype), unit_name_orig(attacker->type), + TILE_XY(attacker->tile), want); +#endif + + if (want > best || (want == best && cost <= best_cost)) { +best = want; bestunit = punittype; +best_cost = cost; } + destroy_unit_virtual(defender); } } simple_ai_unit_type_iterate_end; @@ -1114,7 +1134,7 @@ move_time = turns_to_enemy_city(myunit->type, acity, move_rate, go_by_boat, ferryboat, boattype); -def_type = ai_choose_defender_versus(acity, myunit->type); +def_type = ai_choose_defender_versus(acity, myunit); def_owner = acity->owner; if (move_time > 1) { def_vet = do_make_unit_veteran(acity, def_type); Index: ai/advmilitary.h === --- ai/advmilitary.h (revision 12634) +++ ai/advmilitary.h (working copy) @@ -19,7 +19,7 @@ struct ai_choice; struct unit_type *ai_choose_defender_versus(struct city *pcity, - const struct unit_type *versus); +struct unit *attacker); void military_advisor_choose_tech(struct player *pplayer, struct ai_choice *choice); void military_advisor_choose_build(struct player *pplayer, struct city *pcity, Index: ai/aiunit.c === --- ai/aiunit.c (revision 12634) +++ ai/aiunit.c (working copy) @@ -1403,7 +1403,8 @@ if (move_time > 1) { struct unit_type *def_type - = ai_choose_defender_versus(acity, punit->type); + = ai_choose_defender_versus(acity, punit); + int v = unittype_def_rating_sq(p
Re: [Freeciv-Dev] 2.0.9
PR#19204 should be committed, too. The first patch introduced the problem that you don't get back to the main page when disconnecting on the start page. ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
Re: (PR#14490) Re: [Freeciv-Dev] (PR#33914) Bug Report
http://bugs.freeciv.org/Ticket/Display.html?id=14490 > On 2/11/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote: > > On 1/18/07, Marko Lindqvist <[EMAIL PROTECTED]> wrote: > > > > I think problem is that worklist length varies between cities. > > Untested patch attached. > > This version saves as many worklist items as longest worklist > contains (previous version saved MAX_LEN_WORKLIST). S2_1 version - ML diff -Nurd -X.diff_ignore freeciv/client/options.c freeciv/client/options.c --- freeciv/client/options.c 2006-07-17 14:28:41.0 +0300 +++ freeciv/client/options.c 2007-02-12 15:32:11.0 +0200 @@ -624,6 +624,7 @@ for(i = 0; i < MAX_NUM_WORKLISTS; i++){ if (game.player_ptr->worklists[i].is_valid) { worklist_save(&sf, &(game.player_ptr->worklists[i]), + game.player_ptr->worklists[i].length, "worklists.worklist%d", i); } } diff -Nurd -X.diff_ignore freeciv/common/worklist.c freeciv/common/worklist.c --- freeciv/common/worklist.c 2007-01-19 16:20:14.0 +0200 +++ freeciv/common/worklist.c 2007-02-12 15:31:10.0 +0200 @@ -272,7 +272,7 @@ path and ... give the prefix to load from, printf-style. / void worklist_save(struct section_file *file, struct worklist *pwl, - const char *path, ...) + int max_length, const char *path, ...) { char path_str[1024]; int i; @@ -299,4 +299,13 @@ secfile_insert_str(file, name, "%s.wl_value%d", path_str, i); } + + assert(max_length <= MAX_LEN_WORKLIST); + + /* We want to keep savegame in tabular format, so each line has to be + * of equal length. Fill table up to maximum worklist size. */ + for (i = pwl->length ; i < max_length; i++) { +secfile_insert_bool(file, false, "%s.wl_is_unit%d", path_str, i); +secfile_insert_str(file, "", "%s.wl_value%d", path_str, i); + } } diff -Nurd -X.diff_ignore freeciv/common/worklist.h freeciv/common/worklist.h --- freeciv/common/worklist.h 2006-07-17 14:28:35.0 +0300 +++ freeciv/common/worklist.h 2007-02-12 15:31:10.0 +0200 @@ -53,8 +53,8 @@ const char *path, ...) fc__attribute((__format__ (__printf__, 3, 4))); void worklist_save(struct section_file *file, struct worklist *pwl, - const char *path, ...) - fc__attribute((__format__ (__printf__, 3, 4))); + int max_length, const char *path, ...) + fc__attribute((__format__ (__printf__, 4, 5))); /* Iterate over all entries in the worklist. */ #define worklist_iterate(worklist, prod)\ diff -Nurd -X.diff_ignore freeciv/server/savegame.c freeciv/server/savegame.c --- freeciv/server/savegame.c 2006-07-17 14:28:07.0 +0300 +++ freeciv/server/savegame.c 2007-02-12 15:31:10.0 +0200 @@ -2691,6 +2691,7 @@ char invs[A_LAST+1]; struct player_spaceship *ship = &plr->spaceship; struct ai_data *ai = ai_data_get(plr); + int wlist_max_length = 0; secfile_insert_str(file, plr->name, "player%d.name", plrno); secfile_insert_str(file, plr->username, "player%d.username", plrno); @@ -3007,6 +3008,14 @@ unit_list_iterate_end; i = -1; + + /* First determine lenght of longest worklist */ + city_list_iterate(plr->cities, pcity) { +if (pcity->worklist.length > wlist_max_length) { + wlist_max_length = pcity->worklist.length; +} + } city_list_iterate_end; + city_list_iterate(plr->cities, pcity) { int j, x, y; char citymap_buf[CITY_MAP_SIZE * CITY_MAP_SIZE + 1]; @@ -3147,7 +3156,8 @@ secfile_insert_str(file, impr_buf, "player%d.c%d.improvements_new", plrno, i); -worklist_save(file, &pcity->worklist, "player%d.c%d", plrno, i); +worklist_save(file, &pcity->worklist, wlist_max_length, + "player%d.c%d", plrno, i); /* FIXME: remove this when the urgency is properly recalculated. */ secfile_insert_int(file, pcity->ai.urgency, ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
[Freeciv-Dev] (PR#35785) CPPFLAGS ignored in 2.0.9
http://bugs.freeciv.org/Ticket/Display.html?id=35785 > CPPFLAGS in environment is noticed by configure, but not included in CPPFLAGS it passes on to makefiles. Therefore, freeciv has difficulty using headers in /usr/local/include. This started in 2.0.9. ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
Re: [Freeciv-Dev] 2.0.9
On Sun, 11 Feb 2007, Jason Short wrote: I'm going to wait until tomorrow for beta3. There may be some other patches that can be committed to S2_1 in the meantime. I think PR#12232 should go in first. This is your patch, which I have updated for the new treaty system, BTW. - Per ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
Re: [Freeciv-Dev] Freeciv 2.0.9 released
Windows installer packages are ready now. ___ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev
[Freeciv-Dev] (PR#34265) [Patch] Deep ocean
http://bugs.freeciv.org/Ticket/Display.html?id=34265 > This patch 'fixes' the drawing problems for amplio with deep ocean. These problems were several. First, as the comment says in amplio.tilespec, drawing it like this is a hack. We basically overlay coast on top of the actual ocean drawing, so that in the bottom layer ocean and deep-ocean are drawn (with an appropriate border tile) and in the next layer up coast and deep-ocean are drawn (with an appropriate border tile). Two bugs kept this from working. The first is that there is no way to have 2 layers use the same match style for the same terrain, because the layer number isn't a part of the sprite name. This patch fixes that by adding the layer number (only for these boolean-matched corner cells though). The second is that the layers were being reversed! The coast has to be drawn on *top* of the deep-ocean graphics or we always get ocean overwriting the pretty coastlines. To work around this (and it too is UGLY) I added a new terrain parameter, is_reversed. If this is set then the 2 (or however many) layers are simply drawn in reverse order for that terrain. This patch has to be used with Daniel's terrain2.png (attached earlier in the patch). Even so there are still problems. Because the ocean encroaches onto the deep-ocean tiles (since ocean is only matched against coastline, NOT against deep ocean), narrow areas of deep ocean (often seen along the poles) look VERY bad. Also, as a final comment, I think that ocean isn't deep enough on average. With a trireme in an average map you can go pretty much anywhere. -jason Index: data/amplio/terrain2.spec === --- data/amplio/terrain2.spec (revision 12631) +++ data/amplio/terrain2.spec (working copy) @@ -144,76 +144,113 @@ tiles = { "row", "column","tag" ; ocean cell sprites. See doc/README.graphics - 0, 0, "t.ocean_cell_u000" - 0, 2, "t.ocean_cell_u100" - 0, 4, "t.ocean_cell_u010" - 0, 6, "t.ocean_cell_u110" - 0, 8, "t.ocean_cell_u001" - 0, 10, "t.ocean_cell_u101" - 0, 12, "t.ocean_cell_u011" - 0, 14, "t.ocean_cell_u111" + 0, 0, "t.l0.ocean_cell_u000" + 0, 2, "t.l0.ocean_cell_u100" + 0, 4, "t.l0.ocean_cell_u010" + 0, 6, "t.l0.ocean_cell_u110" + 0, 8, "t.l0.ocean_cell_u001" + 0, 10, "t.l0.ocean_cell_u101" + 0, 12, "t.l0.ocean_cell_u011" + 0, 14, "t.l0.ocean_cell_u111" - 1, 0, "t.ocean_cell_d000" - 1, 2, "t.ocean_cell_d100" - 1, 4, "t.ocean_cell_d010" - 1, 6, "t.ocean_cell_d110" - 1, 8, "t.ocean_cell_d001" - 1, 10, "t.ocean_cell_d101" - 1, 12, "t.ocean_cell_d011" - 1, 14, "t.ocean_cell_d111" + 1, 0, "t.l0.ocean_cell_d000" + 1, 2, "t.l0.ocean_cell_d100" + 1, 4, "t.l0.ocean_cell_d010" + 1, 6, "t.l0.ocean_cell_d110" + 1, 8, "t.l0.ocean_cell_d001" + 1, 10, "t.l0.ocean_cell_d101" + 1, 12, "t.l0.ocean_cell_d011" + 1, 14, "t.l0.ocean_cell_d111" - 2, 0, "t.ocean_cell_l000" - 2, 2, "t.ocean_cell_l100" - 2, 4, "t.ocean_cell_l010" - 2, 6, "t.ocean_cell_l110" - 2, 8, "t.ocean_cell_l001" - 2, 10, "t.ocean_cell_l101" - 2, 12, "t.ocean_cell_l011" - 2, 14, "t.ocean_cell_l111" + 2, 0, "t.l0.ocean_cell_l000" + 2, 2, "t.l0.ocean_cell_l100" + 2, 4, "t.l0.ocean_cell_l010" + 2, 6, "t.l0.ocean_cell_l110" + 2, 8, "t.l0.ocean_cell_l001" + 2, 10, "t.l0.ocean_cell_l101" + 2, 12, "t.l0.ocean_cell_l011" + 2, 14, "t.l0.ocean_cell_l111" - 2, 1, "t.ocean_cell_r000" - 2, 3, "t.ocean_cell_r100" - 2, 5, "t.ocean_cell_r010" - 2, 7, "t.ocean_cell_r110" - 2, 9, "t.ocean_cell_r001" - 2, 11, "t.ocean_cell_r101" - 2, 13, "t.ocean_cell_r011" - 2, 15, "t.ocean_cell_r111" + 2, 1, "t.l0.ocean_cell_r000" + 2, 3, "t.l0.ocean_cell_r100" + 2, 5, "t.l0.ocean_cell_r010" + 2, 7, "t.l0.ocean_cell_r110" + 2, 9, "t.l0.ocean_cell_r001" + 2, 11, "t.l0.ocean_cell_r101" + 2, 13, "t.l0.ocean_cell_r011" + 2, 15, "t.l0.ocean_cell_r111" +; deep ocean coasts. + 0, 1, "t.l0.deep_cell_u000" + 6, 2, "t.l0.deep_cell_u100" + 6, 4, "t.l0.deep_cell_u010" + 6, 6, "t.l0.deep_cell_u110" + 6, 8, "t.l0.deep_cell_u001" + 6, 10, "t.l0.deep_cell_u101" + 6, 12, "t.l0.deep_cell_u011" + 6, 14, "t.l0.deep_cell_u111" + + 0, 1, "t.l0.deep_cell_d000" + 7, 2, "t.l0.deep_cell_d100" + 7, 4, "t.l0.deep_cell_d010" + 7, 6, "t.l0.deep_cell_d110" + 7, 8, "t.l0.deep_cell_d001" + 7, 10, "t.l0.deep_cell_d101" + 7, 12, "t.l0.deep_cell_d011" + 7, 14, "t.l0.deep_cell_d111" + + 0, 1, "t.l0.deep_cell_l000" + 8, 2, "t.l0.deep_cell_l100" + 8, 4, "t.l0.deep_cell_l010" + 8, 6, "t.l0.deep_cell_l110" + 8, 8, "t.l0.deep_cell_l001" + 8, 10, "t.l0.deep_cell_l101" + 8, 12, "t.l0.deep_cell_l011" + 8, 14, "t.l0.deep_cell_l111" + + 0, 1, "t.l0.deep_cell_r000" + 8, 3, "t.l0.deep_cell_r100" + 8, 5, "t.l0.deep_cell_r010" + 8, 7, "t.l0.deep_cell_r110" + 8, 9, "t.l0.deep_cell_r001" + 8, 11, "t.l0.deep_cell_r101" + 8, 13, "t.l0.deep_cell_r011" + 8, 15, "t.l0.deep_cell_r111" + ; Deep Ocean sprites. - 3, 0, "t.deep_cell_u000" - 3, 2, "t.deep_cell_u100" - 3, 4, "t.deep_cel