[Freeciv-Dev] (PR#20668) Patch: add tech_cost_style=3
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=20668 >
This is a patch (for trunk 12312) which adds a new
tech_cost_style - number 3. It does *not* change the default
tech_cost_style; that remains 1.
The new tech_cost_style=3 implements the formula:
cost of a tech = (1 + num_parents) * baseresearchcost
It produces tech costs which are all integer multiples of
baseresearchcost. I like it and use it. I hope you will add it to
freeciv as an option.
In addition to the code, I added comments describing
tech_cost_style=3 and made minor corrections to comments regarding
other tech_cost_styles. Based on what I saw, tech_cost_style=3 used
to signify "tech costs are defined in the ruleset"; tech_cost_style=2
now serves that purpose.
I also rewrote the comments describing tech_cost_style=0 (CivI /
II compatible) in two different ways (once in game.ruleset and once
in tech.c). I hope you like at least one of them.
This is my first patch using SVN. As such, it is partly a test
to see if I've got the procedure right.
I've used this code for several weeks (on 2.1.0.b2 and later on
trunk) without any problems. I also tested with tech_cost_style
set to 0 and 1 and didn't see any problems there. I didn't know how
to do a meaningful test of tech_cost_style=2; AFAIK I don't have a
ruleset that contains predefined tech costs.
I also ran autogames (using the default of tech_cost_style=1).
Not surprisingly, the savegames were identical with and without the
patch.
I hope this patch meets with your approval.
-Eddie
Index: server/ruleset.c
===================================================================
--- server/ruleset.c (revision 12312)
+++ server/ruleset.c (working copy)
@@ -2655,7 +2655,7 @@
game.info.tech_cost_style =
secfile_lookup_int(&file, "civstyle.tech_cost_style");
- if (game.info.tech_cost_style < 0 || game.info.tech_cost_style > 2) {
+ if (game.info.tech_cost_style < 0 || game.info.tech_cost_style > 3) {
freelog(LOG_ERROR, "Bad value %i for tech_cost_style. Using 0.",
game.info.tech_cost_style);
game.info.tech_cost_style = 0;
Index: data/default/techs.ruleset
===================================================================
--- data/default/techs.ruleset (revision 12312)
+++ data/default/techs.ruleset (working copy)
@@ -32,7 +32,7 @@
; helptext = optional help text string (set units ruleset for examples)
; bonus_message = text seen when a player is the first to
; discover an bonus tech.
-; cost = if tech_cost_style is set to 3, this field is read for
+; cost = if tech_cost_style is set to 2, this field is read for
; information on how much a tech costs
;
; Special values for req1 and req2 are "None" (first section below)
Index: data/default/game.ruleset
===================================================================
--- data/default/game.ruleset (revision 12312)
+++ data/default/game.ruleset (working copy)
@@ -34,7 +34,7 @@
; Barbarian leader ransom in gold
ransom_gold = 100
-; Base research cost for tech styles 1 & 2
+; Base research cost (used by tech_cost_styles 0, 1, & 3)
base_tech_cost = 20
; City center minimum outputs
@@ -75,13 +75,20 @@
granary_food_inc = 10
; Method of calculating technology costs
-; 0 - Civ (I|II) style. Every new tech add researchcost to cost of next tech.
+; 0 - Civ (I|II) style. The Nth tech that you research costs
+; (N * baseresearchcost). E.g. if baseresearchcost = 20, then the
+; 1st tech costs 20, 2nd tech costs 40, 15th tech costs 300, etc.
; 1 - Cost of technology is
-; MAX((1+parents) * (researchcost/2) * sqrt(1+parents), researchcost)
-; where num_parents == number of requirement for tech, counted
+; MAX((1+num_parents) * (researchcost/2) * sqrt(1+num_parents),
+; researchcost)
+; where num_parents == number of requirements for the tech, counted
; recursively.
-; 2 - Cost are read from tech.ruleset. Missing costs are generated by
+; 2 - Costs are read from techs.ruleset. Missing costs are generated by
; style 1.
+; 3 - Cost of technology is
+; (1+num_parents) * researchcost
+; where num_parents == number of requirements for the tech, counted
+; recursively.
tech_cost_style = 1
; Technology leak from other civilizations
===================================================================
Index: common/tech.c
===================================================================
--- common/tech.c (revision 12312)
+++ common/tech.c (working copy)
@@ -35,9 +35,10 @@
server/ruleset.c (for the server)
client/packhand.c (for the client) */
-/* Precalculated costs according to techcost style 1. These do not include
- * the sciencebox multiplier. */
+/* Precalculated costs according to techcost style 1 or 3. These do not
+ * include the sciencebox multiplier. */
static double techcoststyle1[A_LAST];
+static double techcoststyle3[A_LAST];
static const char *flag_names[] = {
"Bonus_Tech", "Bridge", "Railroad", "Fortress",
@@ -392,12 +393,19 @@
from game.info.tech_cost_style and game.info.tech_leakage.
tech_cost_style:
- 0 - Civ (I|II) style. Every new tech adds N to the cost of the next tech.
- 1 - Cost of technology is
- (1 + parents) * 10 * sqrt(1 + parents)
- where num_parents == number of requirement for tech (recursive).
- 2 - Cost are read from tech.ruleset. Missing costs are generated by
+ 0 - Civ (I|II) style. Every new tech costs baseresearchcost more than
+ the cost of the preceding tech. So the Nth tech that you research
+ costs (N * baseresearchcost). It doesn't matter if a tech is high
+ or low on the tech tree. All that matters is that it is the Nth
+ tech that *you* are researching.
+ 1 - Cost of a technology is
+ (1 + num_parents) * (baseresearchcost/2) * sqrt(1 + num_parents)
+ where num_parents == number of prerequisites for that tech (recursive).
+ 2 - Costs are read from techs.ruleset. Missing costs are generated by
style 1.
+ 3 - Cost of a technology is
+ (1 + num_parents) * baseresearchcost
+ where num_parents == number of prerequisites for that tech (recursive).
tech_leakage:
0 - No reduction of the technology cost.
@@ -452,6 +460,9 @@
case 2:
base_cost = advances[tech].preset_cost;
break;
+ case 3:
+ base_cost = techcoststyle3[tech];
+ break;
default:
die("Invalid tech_cost_style %d %d", game.info.tech_cost_style,
tech_cost_style);
@@ -608,6 +619,7 @@
const double cost = base * reqs * sqrt(reqs);
techcoststyle1[tech] = MAX(cost, game.info.base_tech_cost);
+ techcoststyle3[tech] = (reqs - 1) * game.info.base_tech_cost;
} tech_type_iterate_end;
}
@@ -693,13 +705,12 @@
**************************************************************************/
bool techs_have_fixed_costs()
{
- return ((game.info.tech_cost_style == 1
- || game.info.tech_cost_style == 2)
+ return (game.info.tech_cost_style != 0
&& game.info.tech_leakage == 0);
}
/****************************************************************************
- Inialize tech structures.
+ Initialize tech structures.
****************************************************************************/
void techs_init(void)
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#20668) Patch: add tech_cost_style=3,
(Eddie Anderson) <=
|
|