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 #include <config.h>
00035
00036 #include <time.h>
00037 #include "file.h"
00038 #include "game.h"
00039 #include "misc.h"
00040 #include "nat.h"
00041 #include "optlist.h"
00042 #include "prototypes.h"
00043
00044 static int
00045 demand_update_time(time_t *now)
00046 {
00047 struct tm *tm;
00048
00049 tm = localtime(now);
00050 return is_daytime_allowed(60 * tm->tm_hour + tm->tm_min,
00051 update_demandtimes);
00052 }
00053
00054 int
00055 demand_update_want(int *want, int *pop, int which)
00056 {
00057 natid cn;
00058 struct natstr *natp;
00059 int totpop;
00060 int totwant;
00061 int whichwants;
00062
00063 whichwants = totpop = totwant = 0;
00064 for (cn = 1; 0 != (natp = getnatp(cn)); cn++) {
00065
00066
00067 if (natp->nat_stat == STAT_ACTIVE) {
00068 totpop++;
00069 if (natp->nat_update) {
00070 totwant++;
00071 if (which == cn)
00072 whichwants++;
00073 }
00074 }
00075 }
00076 *want = totwant;
00077 *pop = totpop;
00078 return whichwants;
00079 }
00080
00081
00082
00083
00084 int
00085 demand_check(void)
00086 {
00087 int want, pop;
00088
00089 demand_update_want(&want, &pop, 0);
00090 if (want < update_wantmin) {
00091 logerror("no demand update, want = %d, min = %d",
00092 want, update_wantmin);
00093 return 0;
00094 }
00095
00096 return 1;
00097 }
00098
00099
00100
00101
00102 int
00103 demandupdatecheck(void)
00104 {
00105 time_t now = time(NULL);
00106
00107 return update_demand == UPD_DEMAND_ASYNC
00108 && !updates_disabled()
00109 && demand_update_time(&now)
00110 && demand_check();
00111 }