00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <config.h>
00036
00037 #include <math.h>
00038 #include "budg.h"
00039 #include "game.h"
00040 #include "item.h"
00041 #include "update.h"
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 static void share_incr(double *, double *);
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 static float level_easy[4] = { 0.75, 0.75, 5.00, 5.00 };
00070 static float level_log[4] = { 1.75, 2.00, 4.00, 6.00 };
00071
00072 float levels[MAXNOC][4];
00073
00074
00075
00076
00077
00078
00079 double
00080 logx(double d, double base)
00081 {
00082 if (base == 1.0)
00083 return d;
00084 return log10(d) / log10(base);
00085 }
00086
00087 static double
00088 limit_level(double level, int type, int flag)
00089 {
00090 double above_easy;
00091 double above;
00092 double logbase;
00093 double easy;
00094
00095
00096
00097
00098 level_easy[0] = easy_tech;
00099 level_log[0] = tech_log_base;
00100
00101
00102
00103
00104 if (level > level_easy[type]) {
00105 logbase = level_log[type];
00106 easy = level_easy[type];
00107 above_easy = level - easy;
00108 if (flag)
00109 above = above_easy / logx(logbase + above_easy, logbase);
00110 else
00111 above = logx(above_easy + 1.0, logbase);
00112 if (above > 250)
00113 above = 250;
00114 return above < 0 ? easy : easy + above;
00115 } else
00116 return level;
00117 }
00118
00119 void
00120 prod_nat(int etu)
00121 {
00122 struct natstr *np;
00123 float hap;
00124 float edu;
00125 float hap_edu;
00126 long pop;
00127 double rlev;
00128 double tlev;
00129 double tech[MAXNOC];
00130 double res[MAXNOC];
00131 double newvalue;
00132 natid n;
00133 int cn;
00134 struct natstr *cnp;
00135
00136 for (n = 0; NULL != (np = getnatp(n)); n++) {
00137 grant_btus(np, game_reset_tick(&np->nat_access));
00138 if (np->nat_stat < STAT_ACTIVE)
00139 continue;
00140
00141
00142
00143
00144 hap_edu = np->nat_level[NAT_ELEV];
00145 hap_edu = 1.5 - ((hap_edu + 10.0) / (hap_edu + 20.0));
00146 pop = pops[n] + 1;
00147
00148
00149
00150
00151
00152 hap = levels[n][NAT_HLEV] * hap_edu * hap_cons /
00153 ((float)pop * etu);
00154 edu = levels[n][NAT_ELEV] * edu_cons / ((float)pop * etu);
00155 wu((natid)0, n, "%3.0f happiness, %3.0f education produced\n",
00156 levels[n][NAT_HLEV], levels[n][NAT_ELEV]);
00157 hap = limit_level(hap, NAT_HLEV, 1);
00158 edu = limit_level(edu, NAT_ELEV, 1);
00159
00160
00161
00162
00163
00164 newvalue = (np->nat_level[NAT_HLEV] * hap_avg + hap * etu) /
00165 (hap_avg + etu);
00166 np->nat_level[NAT_HLEV] = newvalue;
00167 newvalue = (np->nat_level[NAT_ELEV] * edu_avg + edu * etu) /
00168 (edu_avg + etu);
00169 np->nat_level[NAT_ELEV] = newvalue;
00170
00171
00172
00173 levels[n][NAT_TLEV] =
00174 limit_level(levels[n][NAT_TLEV] / 1, NAT_TLEV, 0) * 1;
00175 levels[n][NAT_RLEV] =
00176 limit_level(levels[n][NAT_RLEV] / 1, NAT_RLEV, 0) * 1;
00177 wu((natid)0, n,
00178 "total pop was %ld, yielding %4.2f hap, %4.2f edu\n",
00179 pop - 1, hap, edu);
00180 }
00181 if (ally_factor > 0.0)
00182 share_incr(res, tech);
00183 else {
00184 memset(res, 0, sizeof(res));
00185 memset(tech, 0, sizeof(tech));
00186 }
00187 for (n = 0; NULL != (np = getnatp(n)); n++) {
00188 if (np->nat_stat < STAT_ACTIVE)
00189 continue;
00190 tlev = levels[n][NAT_TLEV];
00191 rlev = levels[n][NAT_RLEV];
00192 if (tech[n] != 0.0 || res[n] != 0.0) {
00193 wu((natid)0, n,
00194 "%5.4f technology (%5.4f + %5.4f), ",
00195 tlev + tech[n], tlev, tech[n]);
00196 wu((natid)0, n,
00197 "%5.4f research (%5.4f + %5.4f) produced\n",
00198 rlev + res[n], rlev, res[n]);
00199 } else
00200 wu((natid)0, n,
00201 "%5.4f tech, %5.4f research produced\n", tlev, rlev);
00202 rlev += res[n];
00203 tlev += tech[n];
00204 if (rlev != 0.0)
00205 np->nat_level[NAT_RLEV] += rlev;
00206 if (tlev != 0.0)
00207 np->nat_level[NAT_TLEV] += tlev;
00208 if ((sea_money[n] != 0) || (air_money[n] != 0) ||
00209 (lnd_money[n] != 0))
00210 wu((natid)0, n,
00211 "Army delta $%ld, Navy delta $%ld, Air force delta $%ld\n",
00212 lnd_money[n], sea_money[n], air_money[n]);
00213 wu((natid)0, n, "money delta was $%ld for this update\n",
00214 np->nat_money - money[n]);
00215 if (opt_LOSE_CONTACT) {
00216 for (cn = 1; cn < MAXNOC; cn++) {
00217 if ((cnp = getnatp(cn)) != NULL)
00218 agecontact(cnp);
00219 }
00220 }
00221 }
00222 }
00223
00224
00225
00226
00227 static void
00228 share_incr(double *res, double *tech)
00229 {
00230 struct natstr *np;
00231 struct natstr *other;
00232 natid i;
00233 natid j;
00234 int rnc;
00235 int tnc;
00236
00237 for (i = 0; NULL != (np = getnatp(i)); i++) {
00238 res[i] = tech[i] = 0.0;
00239 if (np->nat_stat < STAT_SANCT || np->nat_stat == STAT_GOD)
00240 continue;
00241 rnc = tnc = 0;
00242 for (j = 0; NULL != (other = getnatp(j)); j++) {
00243 if (j == i)
00244 continue;
00245 if (other->nat_stat != STAT_ACTIVE)
00246 continue;
00247 if (opt_HIDDEN) {
00248 if (!getcontact(np, j))
00249 continue;
00250 }
00251 if (!opt_ALL_BLEED) {
00252 if (getrel(np, j) != ALLIED)
00253 continue;
00254 if (getrel(other, i) != ALLIED)
00255 continue;
00256 res[i] += levels[j][NAT_RLEV];
00257 tech[i] += levels[j][NAT_TLEV];
00258 rnc++;
00259 tnc++;
00260 } else {
00261 if (levels[j][NAT_TLEV] > 0.001) {
00262 tech[i] += levels[j][NAT_TLEV];
00263 tnc++;
00264 }
00265 if (levels[j][NAT_RLEV] > 0.001) {
00266 res[i] += levels[j][NAT_RLEV];
00267 rnc++;
00268 }
00269 }
00270 }
00271 if (rnc > 0) {
00272 res[i] /= rnc * ally_factor;
00273 }
00274 if (tnc > 0) {
00275 tech[i] /= tnc * ally_factor;
00276 }
00277
00278 }
00279 }