static void test_fishing_feeds_2_people(CuTest * tc) { const resource_type *rtype; region *r; faction *f; unit *u; ship *sh; test_cleanup(); test_create_world(); r = findregion(-1, 0); CuAssertStrEquals(tc, "ocean", r->terrain->_name); /* test_create_world needs coverage */ f = test_create_faction(rc_find("human")); u = test_create_unit(f, r); sh = new_ship(st_find("boat"), r, 0); u_set_ship(u, sh); rtype = get_resourcetype(R_SILVER); i_change(&u->items, rtype->itype, 42); scale_number(u, 1); sh->flags |= SF_FISHING; get_food(r); CuAssertIntEquals(tc, 42, i_get(u->items, rtype->itype)); scale_number(u, 2); sh->flags |= SF_FISHING; get_food(r); CuAssertIntEquals(tc, 42, i_get(u->items, rtype->itype)); scale_number(u, 3); sh->flags |= SF_FISHING; get_food(r); CuAssertIntEquals(tc, 32, i_get(u->items, rtype->itype)); }
void test_upkeep_from_pool(CuTest * tc) { region *r; unit *u1, *u2; const item_type *i_silver; test_cleanup(); test_create_world(); i_silver = it_find("money"); assert(i_silver); r = findregion(0, 0); u1 = test_create_unit(test_create_faction(test_create_race("human")), r); assert(u1); u2 = test_create_unit(u1->faction, r); assert(r && u1 && u2); set_param(&global.parameters, "rules.food.flags", "0"); i_change(&u1->items, i_silver, 30); get_food(r); CuAssertIntEquals(tc, 10, i_get(u1->items, i_silver)); CuAssertIntEquals(tc, 0, fval(u1, UFL_HUNGER)); CuAssertIntEquals(tc, 0, fval(u2, UFL_HUNGER)); get_food(r); CuAssertIntEquals(tc, 0, i_get(u1->items, i_silver)); CuAssertIntEquals(tc, 0, fval(u1, UFL_HUNGER)); CuAssertIntEquals(tc, UFL_HUNGER, fval(u2, UFL_HUNGER)); test_cleanup(); }
void test_upkeep_hunger_damage(CuTest * tc) { region *r; unit *u1; faction *f1; const item_type *i_silver; test_cleanup(); test_create_world(); i_silver = it_find("money"); assert(i_silver); r = findregion(0, 0); f1 = test_create_faction(test_create_race("human")); u1 = test_create_unit(f1, r); assert(r && u1); set_param(&global.parameters, "rules.food.flags", "0"); u1->hp = 100; get_food(r); // since u1 and u2 are not allied, u1 should not help u2 with upkeep CuAssertTrue(tc, u1->hp < 100); test_cleanup(); }
void test_upkeep_default(CuTest * tc) { region *r; unit *u1, *u2; faction *f1, *f2; const item_type *i_silver; test_cleanup(); test_create_world(); i_silver = it_find("money"); assert(i_silver); r = findregion(0, 0); f1 = test_create_faction(test_create_race("human")); f2 = test_create_faction(test_create_race("human")); assert(f1 && f2); u1 = test_create_unit(f1, r); u2 = test_create_unit(f2, r); assert(r && u1 && u2); set_param(&global.parameters, "rules.food.flags", "0"); i_change(&u1->items, i_silver, 20); get_food(r); // since u1 and u2 are not allied, u1 should not help u2 with upkeep CuAssertIntEquals(tc, 10, i_get(u1->items, i_silver)); CuAssertIntEquals(tc, 0, fval(u1, UFL_HUNGER)); CuAssertIntEquals(tc, UFL_HUNGER, fval(u2, UFL_HUNGER)); test_cleanup(); }
int setTimer(t_data *d) { int req_timeout; int food_out; req_timeout = request_timeout(d); food_out = get_food(d); if (req_timeout != -1 && req_timeout < food_out) return req_timeout; else if (food_out != 0) return food_out; else return -1; }
char *as_bct(t_server *serv, t_player *tmp, t_list_stone *list_stone, char *pdr) { char *str; asprintf(&str, "%sbct %d %d %d %d %d %d %d %d %d", pdr, tmp->pos->x, tmp->pos->y, get_food(&(serv->map), tmp->pos->x, tmp->pos->y), count_stone(LINEMATE, list_stone), count_stone(DERAUMERE, list_stone), count_stone(SIBUR, list_stone), count_stone(MENDIANE, list_stone), count_stone(PHIRAS, list_stone), count_stone(THYSTAME, list_stone)); return (str); }
void do_shanty (int x, int y) { /* just steal some stuff and make pollution. */ get_food (x, y, SHANTY_GET_FOOD); if (get_goods (x, y, SHANTY_GET_GOODS) != 0) if ((goods_tax -= SHANTY_GET_GOODS * 2) < 0) goods_tax = 0; get_ore (x, y, SHANTY_GET_ORE); get_steel (x, y, SHANTY_GET_STEEL); if (get_jobs (x, y, SHANTY_GET_JOBS) != 0) if ((income_tax -= SHANTY_GET_JOBS * 2) < 0) income_tax = 0; if (get_coal (x, y, SHANTY_GET_COAL) != 0) if ((coal_tax -= SHANTY_GET_COAL * 2) < 0) coal_tax = 0; if ((total_time & 1) == 0) MP_POL(x,y)++; else MP_POL(x+1,y+1)++; }
void ret_food(int fd, int x, int y) { struct timeval *end; struct timeval *res; float add; if ((end = get_timeval_planning(fd)) == NULL || get_food(fd, 1) == 0) { printf("\033[0;31mSending message to %d :\033[0;0m ko\n", fd); fd_puts(fd, "ko\n"); return ; } res = xmalloc(sizeof(struct timeval)); add = ((float) NEW_FOOD / (float) parse.t) * 1000000.; res->tv_sec = end->tv_sec - (long) add / 1000000; res->tv_usec = end->tv_usec - (long) add % 1000000; remove_death(planning, fd); map[x][y].spot[FOOD]++; insert_tlist(planning, strdup("mort\n"), fd, res); printf("\033[0;31mSending message to %d :\033[0;0m ok\n", fd); fd_puts(fd, "ok\n"); }
void test_upkeep_free(CuTest * tc) { region *r; unit *u; const item_type *i_silver; test_cleanup(); test_create_world(); i_silver = it_find("money"); assert(i_silver); r = findregion(0, 0); u = test_create_unit(test_create_faction(test_create_race("human")), r); assert(r && u); set_param(&global.parameters, "rules.food.flags", "4"); // FOOD_IS_FREE get_food(r); CuAssertIntEquals(tc, 0, i_get(u->items, i_silver)); CuAssertIntEquals(tc, 0, fval(u, UFL_HUNGER)); test_cleanup(); }
int main(void){ char c[20]; struct food f; struct food g; int arr1[4]; putchar('a' + one_two_array[0]); putchar('a' + one_two_array[1]); f.a = 'a'; f.b = 'b'; f.c = 'c'; f.d = 'd'; f.e = 'e'; g = get_food(f); putchar((int)f.a); putchar((int)f.b); putchar((int)f.c); putchar((int)f.d); putchar((int)f.e); putchar((int)g.a); putchar((int)g.b); putchar((int)g.c); putchar((int)g.d); putchar((int)g.e); output(); arr1[0] = 'a'; arr1[1] = 'b'; arr1[2] = 'c'; arr1[3] = 'd'; inc_array(arr1); putchar(arr1[0]); putchar(arr1[1]); putchar(arr1[2]); putchar(arr1[3]); putchar('a' + (int)(&arr1[1] - &arr1[0])); (void)c; { char d[20]; (void)d; { char e[40]; (void)e; } } { char try1[12]; char *result1 = &try1[0]; unsigned int chars_required = 99; unsigned int i; for(i = 0; i < 12; i++){ try1[i] = 'a' + (char)i; } { char try2[200]; unsigned int chars_required2 = chars_required; for(i = 0; i < 200; i++){ try2[i] = 'a' + (char)(i%26); } try2[199] = '\0'; result1 = &try2[0]; if(chars_required2 < 200){ while(*result1){ putchar(*result1); result1++; } } } for(i = 0; i < 12; i++){ putchar(try1[i]); } } test_data(); return 0; }
void do_residence (int x, int y) { /* // int_1 is a job swingometer to choose +/- JOB_SWING% of normal // int_2 is the date of the last starve // int 3 is the real time for the next icon update // int_4 is the birth rate modifier. // int_5 is the death rate modifier. */ int p; /* population */ int bad = 35, good = 30; /* (un)desirability of living here */ int r, po, swing; int hc = 0; /* have health cover ? */ int brm = 0, drm = 0; /* birth/death rate modifier */ int cc = 0; p = MP_INFO(x,y).population; if ((MP_INFO(x,y).flags & FLAG_HEALTH_COVER) != 0) { brm += RESIDENCE_BRM_HEALTH; good += 15; hc = 1; } if ((MP_INFO(x,y).flags & FLAG_FIRE_COVER) == 0) bad += 5; else good += 15; if ((MP_INFO(x,y).flags & FLAG_CRICKET_COVER) != 0) { good += 20; cc = CRICKET_JOB_SWING; } /* normal deaths + pollution deaths */ po = ((MP_POL(x,y) / 50) + 1); if ((RESIDENCE_BASE_DR - MP_INFO(x,y).int_5 - po) > 1) r = rand () % (RESIDENCE_BASE_DR - MP_INFO(x,y).int_5 - po); else r = 2; if (p > 0 && (r < po)) { if (r == 0 || hc == 0) p--; else if (hc != 0 && po > 10 && rand () % 4 == 0) { p--; unnat_deaths++; total_pollution_deaths++; pollution_deaths_history += 1.0; bad += 100; } if (r > 0 && hc == 0) { unnat_deaths++; total_pollution_deaths++; pollution_deaths_history += 1.0; bad += 100; } } /* normal births - must have food and jobs... and people */ if ((MP_INFO(x,y).flags & (FLAG_FED + FLAG_EMPLOYED)) == (FLAG_FED + FLAG_EMPLOYED) && (rand () % (RESIDENCE_BASE_BR + MP_INFO(x,y).int_4) == 1) && p > 0) { p++; total_births++; good += 50; } /* are people starving. */ if ((MP_INFO(x,y).flags & FLAG_FED) == 0 && p > 0) { if (rand () % DAYS_PER_STARVE == 1) { p--; unnat_deaths++; total_starve_deaths++; starve_deaths_history += 1.0; } starving_population += p; bad += 250; drm += 100; MP_INFO(x,y).int_2 = total_time; /* for the starve screen */ } /* kick one out if overpopulated */ if (MP_TYPE(x,y) == CST_RESIDENCE_LL) { brm += RESIDENCE1_BRM; drm += p * 8; if (p > 50) { p--; people_pool++; brm += 20; } } else if (MP_TYPE(x,y) == CST_RESIDENCE_ML) { brm += RESIDENCE2_BRM; drm += p * 3; if (p > 100) { p--; people_pool++; brm += 10; } } else if (MP_TYPE(x,y) == CST_RESIDENCE_HL) { brm += RESIDENCE3_BRM; drm += p; good += 40; if (p > 200) { p--; people_pool++; brm += 10; } } else if (MP_TYPE(x,y) == CST_RESIDENCE_LH) { brm += RESIDENCE4_BRM; drm += p * 5; if (p > 100) { p--; people_pool++; brm += 20; } } else if (MP_TYPE(x,y) == CST_RESIDENCE_MH) { brm += RESIDENCE5_BRM; drm += p / 2; if (p > 200) { p--; people_pool++; brm += 10; } } else if (MP_TYPE(x,y) == CST_RESIDENCE_HH) { good += 100; brm += RESIDENCE6_BRM; drm += p; if (p > 400) { p--; people_pool++; brm += 10; } } population += p; /* now get power */ if (get_power (x, y, POWER_RES_OVERHEAD + (POWER_USE_PER_PERSON * p), 0) != 0) { MP_INFO(x,y).flags |= FLAG_POWERED; MP_INFO(x,y).flags |= FLAG_HAD_POWER; good += 10; } else { MP_INFO(x,y).flags &= (0xffffffff - FLAG_POWERED); bad += 15; if ((MP_INFO(x,y).flags & FLAG_HAD_POWER) != 0) bad += 50; } /* now get fed */ if (get_food (x, y, p) != 0) { MP_INFO(x,y).flags |= FLAG_FED; good += 10; } else MP_INFO(x,y).flags &= (0xffffffff - FLAG_FED); /* now supply jobs and buy goods if employed */ if (MP_INFO(x,y).int_1 > 0) swing = JOB_SWING + (hc * HC_JOB_SWING) + cc; else swing = -(JOB_SWING + (hc * HC_JOB_SWING) + cc); if (put_jobs (x, y, ((p * (WORKING_POP_PERCENT + swing)) / 100)) != 0) { MP_INFO(x,y).flags |= FLAG_EMPLOYED; MP_INFO(x,y).int_1++; if (MP_INFO(x,y).int_1 > 10) MP_INFO(x,y).int_1 = 10; good += 20; if (get_goods (x, y, p / 4) != 0) { good += 10; if (get_power (x, y, p / 2, 0) != 0) /* goods use power */ { good += 5; brm += 10; /* buy more goods if got power for them */ if (get_goods (x, y, p / 4) != 0) good += 5; } else bad += 5; } } else if (MP_INFO(x,y).int_1 < 10) { MP_INFO(x,y).flags &= (0xffffffff - FLAG_EMPLOYED); MP_INFO(x,y).int_1 -= 11; if (MP_INFO(x,y).int_1 < -300) MP_INFO(x,y).int_1 = -300; unemployed_population += p; total_unemployed_days += p; if (total_unemployed_days >= NUMOF_DAYS_IN_YEAR) { total_unemployed_years++; /* think we're ok doing this, max of about 120 added each time. */ total_unemployed_days -= NUMOF_DAYS_IN_YEAR; unemployed_history += 1.0; } unemployment_cost += p; /* hmmm */ bad += 70; } else { MP_INFO(x,y).int_1 -= 20; bad += 50; } drm += p / 4; /* people_pool stuff */ bad += p / 2; bad += MP_POL(x,y) / 20; good += people_pool / 27; r = rand () % ((good + bad) * RESIDENCE_PPM); if (r < bad) { if (p > MIN_RES_POPULATION) { p--; people_pool++; } } else if (people_pool > 0 && r > ((good + bad) * (RESIDENCE_PPM - 1) + bad)) { p++; people_pool--; } MP_INFO(x,y).population = p; MP_INFO(x,y).int_4 = brm; MP_INFO(x,y).int_5 = drm; }
void do_mill (int x, int y) { /* // int_1 contains the goods at the mill // int_2 contains the food store // int_3 contains the coal store // int_4 contains the animation trigger time // int_5 is the % count so far this month // int_6 is the % capacity last month */ /* get food */ int block_anim = 0; if (MP_INFO(x,y).int_2 < MAX_FOOD_AT_MILL) if (get_food (x, y, MILL_GET_FOOD) != 0) MP_INFO(x,y).int_2 += MILL_GET_FOOD; /* get coal */ if (MP_INFO(x,y).int_3 < MAX_COAL_AT_MILL) { if (get_coal (x, y, MILL_GET_COAL) != 0) MP_INFO(x,y).int_3 += MILL_GET_COAL; else if (get_power (x, y, MILL_GET_COAL * MILL_POWER_PER_COAL, 0) != 0) MP_INFO(x,y).int_3 += MILL_GET_COAL; } if (MP_INFO(x,y).int_1 < MAX_GOODS_AT_MILL) { if (MP_INFO(x,y).int_2 > FOOD_USED_BY_MILL && MP_INFO(x,y).int_3 > COAL_USED_BY_MILL) { if (get_jobs (x, y, MILL_JOBS) != 0) { MP_INFO(x,y).int_2 -= FOOD_USED_BY_MILL; MP_INFO(x,y).int_3 -= COAL_USED_BY_MILL; MP_INFO(x,y).int_1 += GOODS_MADE_BY_MILL; MP_INFO(x,y).int_5++; } else { MP_TYPE(x,y) = CST_MILL_0; block_anim = 1; } } else block_anim = 1; } if (MP_INFO(x,y).int_1 > 0) if (put_goods (x, y, MP_INFO(x,y).int_1) != 0) MP_INFO(x,y).int_1 = 0; if (total_time % 100 == 0) { MP_INFO(x,y).int_6 = MP_INFO(x,y).int_5; MP_INFO(x,y).int_5 = 0; } if (real_time >= MP_INFO(x,y).int_4 && block_anim == 0) { MP_INFO(x,y).int_4 = real_time + MILL_ANIM_SPEED; switch (MP_TYPE(x,y)) { case (CST_MILL_0): MP_TYPE(x,y) = CST_MILL_1; break; case (CST_MILL_1): MP_TYPE(x,y) = CST_MILL_2; break; case (CST_MILL_2): MP_TYPE(x,y) = CST_MILL_3; break; case (CST_MILL_3): MP_TYPE(x,y) = CST_MILL_4; break; case (CST_MILL_4): MP_TYPE(x,y) = CST_MILL_5; break; case (CST_MILL_5): MP_TYPE(x,y) = CST_MILL_6; break; case (CST_MILL_6): MP_TYPE(x,y) = CST_MILL_1; MP_POL(x,y)++; break; } } }