Mercurial > garten
comparison weather.c @ 18:5937504619f2
rename game.h -> modules.h; added some error handling; and more
author | meillo@marmaro.de |
---|---|
date | Wed, 23 Jul 2008 17:40:55 +0200 |
parents | 5e6c9260913a |
children |
comparison
equal
deleted
inserted
replaced
17:5e6c9260913a | 18:5937504619f2 |
---|---|
1 #include <stdio.h> | 1 #include <stdio.h> |
2 #include <stdlib.h> | 2 #include <stdlib.h> |
3 #include <time.h> | 3 #include <time.h> |
4 #include "db.h" | 4 #include "db.h" |
5 #include "game.h" | |
6 | 5 |
7 | 6 |
8 enum { | 7 enum { |
9 Nlast = 2, | 8 Nlast = 2, |
10 }; | 9 }; |
66 w->wind = 0.2 * mean_wind[month] + 0.4 * lastw[0].wind + 0.2 * lastw[1].wind + 0.08 * rand_limit(10); // + 0.02 * rand_limit(100); | 65 w->wind = 0.2 * mean_wind[month] + 0.4 * lastw[0].wind + 0.2 * lastw[1].wind + 0.08 * rand_limit(10); // + 0.02 * rand_limit(100); |
67 w->hum = 0.2 * mean_hum[month] + 0.4 * lastw[0].hum + 0.2 * lastw[1].hum + 0.08 * rand_limit(10); // + 0.02 * rand_limit(100); | 66 w->hum = 0.2 * mean_hum[month] + 0.4 * lastw[0].hum + 0.2 * lastw[1].hum + 0.08 * rand_limit(10); // + 0.02 * rand_limit(100); |
68 } | 67 } |
69 | 68 |
70 | 69 |
71 void setweather(struct weather* w) { | 70 int setweather(struct weather* w) { |
72 char query[512]; | 71 char query[512]; |
73 sprintf(query, | 72 sprintf(query, |
74 " insert into weather " | 73 " insert into weather " |
75 " (tick, temp, sun, rain, wind, hum) " | 74 " (tick, temp, sun, rain, wind, hum) " |
76 " values ('%d', '%f', '%f', '%f', '%f', '%f') " | 75 " values ('%d', '%f', '%f', '%f', '%f', '%f') " |
77 , gametime, w->temp, w->sun, w->rain, w->wind, w->hum | 76 , gametime, w->temp, w->sun, w->rain, w->wind, w->hum |
78 ); | 77 ); |
79 if (!db_update(query)) { | 78 if (!db_update(query)) { |
80 db_error("weather insertion"); | 79 db_error("weather insertion"); |
80 return 0; | |
81 } | 81 } |
82 return 1; | |
82 } | 83 } |
83 | 84 |
84 | 85 |
85 void weather(void) { | 86 int weather(void) { |
86 struct weather w; | 87 struct weather w; |
87 struct weather lastn[Nlast]; | 88 struct weather lastn[Nlast]; |
88 | 89 |
89 getlastweather(lastn, Nlast); | 90 getlastweather(lastn, Nlast); |
90 genweather(&w, lastn, Nlast, May); | 91 genweather(&w, lastn, Nlast, May); |
91 setweather(&w); | 92 return setweather(&w); |
93 /* FIXME: include all functions in return value */ | |
92 } | 94 } |