static void process_function_actual(int job_type){ struct Job_Queue private_jobs; private_jobs.front = 0; private_jobs.rear = 0; get_jobs(job_type,&private_jobs); struct Job current_job; time_t nowtime; struct tcp_stream *a_tcp; while(!jobqueue_isEmpty(&private_jobs)){ jobqueue_delete(&private_jobs,¤t_job); hash_index = current_job.hash_index; get_user_pass(current_job.promisc->head->length, current_job.promisc->head->data); analysis(current_job.promisc->head->length, current_job.promisc->head->data); if(current_job.server_rev!=NULL){ wireless_list_free(current_job.server_rev); free(current_job.server_rev); } if(current_job.client_rev !=NULL){ wireless_list_free(current_job.client_rev); free(current_job.client_rev); } if(current_job.promisc != NULL){ wireless_list_free(current_job.promisc); free(current_job.promisc); } }//while }
t_jobs *get_jobs(t_get *words, t_jobs *prev, char **bad_sintax) { t_jobs *link; if (!words) return (prev); if ((link = xmalloc(sizeof(*link))) == NULL) return (word_nullify(words)); link->tmp = words; if (!(link->type = match_end(&words, bad_sintax))) return (word_nullify(words)); if (words) if (words->prev) words->prev->next = NULL; if (words) if (words->next) words->next->prev = NULL; if (prev) prev->next = link; link->next = NULL; if (!words) return (link); if (get_jobs(words->next, link, bad_sintax) == NULL) return (nullify(link)); rm_words(words); return (link); }
void do_school (int x, int y) { /* // int_1 contains the job pool // int_2 contains the goods at the school // int_3 has the tech points made // int_4 is the tech count so far this 100 days // int_5 is the tech count last 100 days to give a % of max production */ if (MP_INFO(x,y).int_1 < (MAX_JOBS_AT_SCHOOL - SCHOOL_JOBS)) if (get_jobs (x, y, SCHOOL_JOBS) != 0) MP_INFO(x,y).int_1 += SCHOOL_JOBS; if (MP_INFO(x,y).int_2 < (MAX_GOODS_AT_SCHOOL - SCHOOL_GOODS)) if (get_goods (x, y, SCHOOL_GOODS) != 0) MP_INFO(x,y).int_2 += SCHOOL_GOODS; if (MP_INFO(x,y).int_1 >= JOBS_MAKE_TECH_SCHOOL && MP_INFO(x,y).int_2 >= GOODS_MAKE_TECH_SCHOOL) { MP_INFO(x,y).int_1 -= JOBS_MAKE_TECH_SCHOOL; MP_INFO(x,y).int_2 -= GOODS_MAKE_TECH_SCHOOL; MP_INFO(x,y).int_3 += TECH_MADE_BY_SCHOOL; MP_INFO(x,y).int_4++; tech_level += TECH_MADE_BY_SCHOOL; } school_cost += SCHOOL_RUNNING_COST; if ((total_time % 100) == 0) { MP_INFO(x,y).int_5 = MP_INFO(x,y).int_4; MP_INFO(x,y).int_4 = 0; } }
gcc -g -o tests/t_dispatch tests/t_dispatch.c lib/dispatch.c lib/task.c urlencode.c urldecode.c header-parse.c lib/nv_pair.c crypt/base64/base64.c lib/proto.c lib/fileman.c net-modules/http.c net-modules/dns.c io.c io/syslog.c io/filelog.c options.c -Wall -lnsl -I./ lib/libares/*.c -Ilib/libares -pipe p_time.c -lssl -lcrypto url-parse.c limits.c */ #endif #include "lib/nv_pair.h" #include "net-modules/dns.h" #include "net-modules/http.h" #include <string.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <netinet/in.h> #include <arpa/inet.h> #include <openssl/ssl.h> #include "util.h" #include "options.h" #include "lib/proto.h" #include "lib/fileman.h" #include "lib/dispatch.h" #include "p_types.h" #include "urlencode.h" int main (int argc, char ** argv) { fm_init_base(); get_jobs("dev.petta-tech.com"); return 0; }
static void process_function_actual(int job_type){ struct Job_Queue private_jobs; private_jobs.front = 0; private_jobs.rear = 0; get_jobs(job_type,&private_jobs); struct Job current_job; struct tcp_stream *a_tcp; char tcp_information_dir[100]; char server[100],client[100],promisc[100]; while(!jobqueue_isEmpty(&private_jobs)){ jobqueue_delete(&private_jobs,¤t_job); memset(tcp_information_dir,0,sizeof(tcp_information_dir)); sprintf(tcp_information_dir,"%s/%hu_%hu_%u_%u_%d/",current_dictionary,current_job.ip_and_port.dest,\ current_job.ip_and_port.source,current_job.ip_and_port.daddr,\ current_job.ip_and_port.saddr,current_job.hash_index); create_dirctionary(tcp_information_dir); if(current_job.server_rev != NULL && current_job.server_rev->head != NULL && current_job.server_rev->head->data != NULL){ memset(server,0,100*sizeof(char)); sprintf(server,"%s/log_server",tcp_information_dir); write_data_to_file(server,current_job.server_rev->head->data, current_job.server_rev->head->length); } if(current_job.client_rev != NULL && current_job.client_rev->head != NULL && current_job.client_rev->head->data != NULL){ memset(client,0,100*sizeof(char)); sprintf(client,"%s/log_client",tcp_information_dir); write_data_to_file(client,current_job.client_rev->head->data, current_job.client_rev->head->length); } if(current_job.promisc != NULL && current_job.promisc->head != NULL && current_job.promisc->head->data != NULL){ memset(promisc,0,100*sizeof(char)); sprintf(promisc,"%s/log_promisc",tcp_information_dir); write_data_to_file(promisc,current_job.promisc->head->data, current_job.promisc->head->length); } if(current_job.server_rev!=NULL){ wireless_list_free(current_job.server_rev); free(current_job.server_rev); } if(current_job.client_rev !=NULL){ wireless_list_free(current_job.client_rev); free(current_job.client_rev); } if(current_job.promisc != NULL){ wireless_list_free(current_job.promisc); free(current_job.promisc); } }//while }
drmaa2_j_list drmaa2_jsession_get_jobs (const drmaa2_jsession js, const drmaa2_jinfo filter) { if (!jsession_is_valid(js)) { drmaa2_lasterror_v = DRMAA2_INVALID_SESSION; drmaa2_lasterror_text_v = "Job session is invalid."; return NULL; } drmaa2_j_list jobs = drmaa2_list_create(DRMAA2_JOBLIST, (drmaa2_list_entryfree)drmaa2_j_free); jobs = get_jobs(jobs, js, filter); return jobs; }
static void process_function_actual(int job_type){ struct Job_Queue private_jobs; private_jobs.front = 0; private_jobs.rear = 0; get_jobs(job_type,&private_jobs); struct Job current_job; time_t nowtime; struct tcp_stream *a_tcp; while(!jobqueue_isEmpty(&private_jobs)){ }//while }
const std::vector<disque_job*>* disque::getjob(const std::vector<string>& names, size_t timeout, size_t count) { size_t argc = 2 + names.size() + 4; const char** argv = (const char**) pool_->dbuf_alloc(argc * sizeof(char*)); size_t* lens = (size_t*) pool_->dbuf_alloc(argc * sizeof(size_t)); argv[0] = "GETJOB"; lens[0] = sizeof("GETJOB") - 1; size_t i = 1; if (timeout > 0) { argv[i] = "TIMEOUT"; lens[i] = sizeof("TIMEOUT") - 1; i++; char* tmp = (char*) pool_->dbuf_alloc(INT_LEN); safe_snprintf(tmp, INT_LEN, "%d", (int) timeout); argv[i] = tmp; lens[i] = strlen(tmp); i++; } if (count > 0) { argv[i] = "COUNT"; lens[i] = sizeof("COUNT") - 1; i++; char* tmp = (char*) pool_->dbuf_alloc(INT_LEN); safe_snprintf(tmp, INT_LEN, "%d", (int) count); argv[i] = tmp; lens[i] = strlen(tmp); i++; } argv[i] = "FROM"; lens[i] = sizeof("FROM") - 1; i++; for (std::vector<string>::const_iterator cit = names.begin(); cit != names.end(); ++cit) { argv[i] = (*cit).c_str(); lens[i] = (*cit).length(); i++; } build_request(i, argv, lens); return get_jobs(NULL); }
static void process_function_actual(int job_type){ struct Job_Queue private_jobs; private_jobs.front = 0; private_jobs.rear = 0; get_jobs(job_type,&private_jobs); struct Job current_job; while(!jobqueue_isEmpty(&private_jobs)){ jobqueue_delete(&private_jobs,¤t_job); hash_index = current_job.hash_index; analysis_userpassword_from_job(¤t_job); if(current_job.http_rr != NULL) free_http_rr(current_job.http_rr); }//while }
void do_health_centre(int x, int y) { /* // int_1 is the jobs stored at the health centre // int_2 is the goods stored at the health centre */ if (MP_INFO(x, y).int_1 < (MAX_JOBS_AT_HEALTH_CENTRE - HEALTH_CENTRE_GET_JOBS)) if (get_jobs(x, y, HEALTH_CENTRE_GET_JOBS) != 0) MP_INFO(x, y).int_1 += HEALTH_CENTRE_GET_JOBS; if (MP_INFO(x, y).int_2 < (MAX_GOODS_AT_HEALTH_CENTRE - HEALTH_CENTRE_GET_GOODS)) if (get_goods(x, y, HEALTH_CENTRE_GET_GOODS) != 0) MP_INFO(x, y).int_2 += HEALTH_CENTRE_GET_GOODS; /* That's all. Cover is done by different functions every 3 months or so. */ health_cost += HEALTH_RUNNING_COST; }
/* // int_1 is the rated capacity // int_2 is the tech level when built // int_3 is the sail count - to choose the right sail. // int_4 is the last real time that a sail was turned // int_5 is the power produced (basically _if_ power produced) // int_6 is the grid it's on // int_7 is a timestamp for mapping */ void do_windmill (int x, int y) { int anim_tile; if (get_jobs (x, y, WINDMILL_JOBS) != 0) { MP_INFO(x,y).int_5 = MP_INFO(x,y).int_1; grid[MP_INFO(x,y).int_6]->avail_power += MP_INFO(x,y).int_1; } else { MP_INFO(x,y).int_4 = real_time + MODERN_WINDMILL_ANIM_SPEED; return; } /* update animation */ if (real_time > MP_INFO(x,y).int_4) { MP_INFO(x,y).int_3++; if (MP_INFO(x,y).int_2 < MODERN_WINDMILL_TECH) { MP_INFO(x,y).int_4 = real_time + ANTIQUE_WINDMILL_ANIM_SPEED; } else { MP_INFO(x,y).int_4 = real_time + MODERN_WINDMILL_ANIM_SPEED; } } /* figure out which tile to use */ anim_tile = (MP_INFO(x,y).int_3 % 3); if (MP_INFO(x,y).int_2 < MODERN_WINDMILL_TECH) MP_TYPE(x,y) = CST_WINDMILL_1_W + anim_tile; else switch(grid[MP_INFO(x,y).int_6]->powered) { case -1: MP_TYPE(x,y) = CST_WINDMILL_1_R + anim_tile; break; case 0 : MP_TYPE(x,y) = CST_WINDMILL_1_RG + anim_tile; break; case 1 : MP_TYPE(x,y) = CST_WINDMILL_1_G + anim_tile; break; default : printf("Default case in do_power_substation\n"); break; } }
void reset() { // get job list std::list<job_statust> jobs; get_jobs(jobs); // reset jobs that need to be for(std::list<job_statust>::iterator j_it=jobs.begin(); j_it!=jobs.end(); j_it++) { if(j_it->status==job_statust::FAILURE) { std::cout << "Resetting job " << j_it->id << "\n"; j_it->status=job_statust::WAITING; j_it->write(); } } }
const std::vector<disque_job*>* disque::qpeek(const char* name, int count) { size_t argc = 3; const char* argv[3]; size_t lens[3]; argv[0] = "QPEEK"; lens[0] = sizeof("QPEEK") - 1; argv[1] = name; lens[1] = strlen(name); char tmp[INT_LEN]; safe_snprintf(tmp, sizeof(tmp), "%d", count); argv[2] = tmp; lens[2] = strlen(tmp); build_request(argc, argv, lens); return get_jobs(name); }
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 show_jobs(std::ostream &out) { std::list<job_statust> jobs; get_jobs(jobs); for(std::list<job_statust>::const_iterator j_it=jobs.begin(); j_it!=jobs.end(); j_it++) { out << j_it->id; out << " " << as_string(j_it->stage) << " " << as_string(j_it->status); if(j_it->hostname!="") out << " on " << j_it->hostname; out << "\n"; } }
void do_recycle (int x, int y) { int i; /* // int_1 is the ore made and waiting to go out // int_2 is the used goods in store // int_3 is the used steel in store NOT USED at this time // int_4 is the tech level when built // int_5 is the recycling done so far this month // int_6 is the percent of max recycling last month // int_7 is the waste in store // cost */ recycle_cost += RECYCLE_RUNNING_COST; /* // let these go through, even if we're full of waste. It's a waste of time // checking. */ if (x > 0 && (MP_INFO(x - 1,y).flags & FLAG_IS_TRANSPORT) != 0) { i = MP_INFO(x - 1,y).int_7; if (i > MAX_WASTE_AT_RECYCLE - MP_INFO(x,y).int_2) i = MAX_WASTE_AT_RECYCLE - MP_INFO(x,y).int_2; MP_INFO(x,y).int_2 += i; MP_INFO(x - 1,y).int_7 -= i; } if (y > 0 && (MP_INFO(x,y - 1).flags & FLAG_IS_TRANSPORT) != 0) { i = MP_INFO(x,y - 1).int_7; if (i > MAX_WASTE_AT_RECYCLE - MP_INFO(x,y).int_2) i = MAX_WASTE_AT_RECYCLE - MP_INFO(x,y).int_2; MP_INFO(x,y).int_2 += i; MP_INFO(x,y - 1).int_7 -= i; } /* get some startup power if not powered yet */ if ((MP_INFO(x,y).flags & FLAG_POWERED) == 0) if (get_power (x, y, GOODS_RECYCLED, 1) != 0) MP_INFO(x,y).flags |= FLAG_POWERED; /* no steel recycling yet - no point, it's only used to make goods. // recycle to ore. */ if (MP_INFO(x,y).int_1 < MAX_ORE_AT_RECYCLE && MP_INFO(x,y).int_2 > GOODS_RECYCLED && (MP_INFO(x,y).flags & FLAG_POWERED) != 0) if (get_jobs (x, y, RECYCLE_GOODS_JOBS) != 0) { if (get_power (x, y, GOODS_RECYCLED / 2, 1) == 0) MP_INFO(x,y).flags &= (0xffffffff - FLAG_POWERED); else MP_INFO(x,y).flags |= FLAG_POWERED; MP_INFO(x,y).int_2 -= GOODS_RECYCLED; i = (GOODS_RECYCLED * (10 + ((50 * MP_INFO(x,y).int_4) / MAX_TECH_LEVEL))) / 100; if (i > (GOODS_RECYCLED * 8) / 10) i = (GOODS_RECYCLED * 8) / 10; MP_INFO(x,y).int_1 += i; ore_made += i; MP_INFO(x,y).int_5++; } if (total_time % 100 == 0) { MP_INFO(x,y).int_6 = MP_INFO(x,y).int_5; MP_INFO(x,y).int_5 = 0; } /* now bung the ore out */ /* put it on the railway */ if (x > 0 && MP_GROUP(x-1,y) == GROUP_RAIL && MP_INFO(x - 1,y).int_5 < MAX_ORE_ON_RAIL && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_RAIL - MP_INFO(x - 1,y).int_5)) { if (get_jobs (x, y, JOBS_LOAD_ORE) != 0) { MP_INFO(x,y).int_1 -= (MAX_ORE_ON_RAIL - MP_INFO(x - 1,y).int_5); MP_INFO(x - 1,y).int_5 = MAX_ORE_ON_RAIL; } } if (y > 0 && MP_GROUP(x,y-1) == GROUP_RAIL && MP_INFO(x,y - 1).int_5 < MAX_ORE_ON_RAIL && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_RAIL - MP_INFO(x,y - 1).int_5)) { if (get_jobs (x, y, JOBS_LOAD_ORE) != 0) { MP_INFO(x,y).int_1 -= (MAX_ORE_ON_RAIL - MP_INFO(x,y - 1).int_5); MP_INFO(x,y - 1).int_5 = MAX_ORE_ON_RAIL; } } /* put it on the road */ if (x > 0 && MP_GROUP(x-1,y) == GROUP_ROAD && MP_INFO(x - 1,y).int_5 < MAX_ORE_ON_ROAD && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_ROAD - MP_INFO(x - 1,y).int_5)) { if (get_jobs (x, y, JOBS_LOAD_ORE) != 0) { MP_INFO(x,y).int_1 -= (MAX_ORE_ON_ROAD - MP_INFO(x - 1,y).int_5); MP_INFO(x - 1,y).int_5 = MAX_ORE_ON_ROAD; } } if (y > 0 && MP_GROUP(x,y-1) == GROUP_ROAD && MP_INFO(x,y - 1).int_5 < MAX_ORE_ON_ROAD && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_ROAD - MP_INFO(x,y - 1).int_5)) { if (get_jobs (x, y, JOBS_LOAD_ORE) != 0) { MP_INFO(x,y).int_1 -= (MAX_ORE_ON_ROAD - MP_INFO(x,y - 1).int_5); MP_INFO(x,y - 1).int_5 = MAX_ORE_ON_ROAD; } } /* put it on the tracks */ if (x > 0 && MP_GROUP(x-1,y) == GROUP_TRACK && MP_INFO(x - 1,y).int_5 < MAX_ORE_ON_TRACK && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_TRACK - MP_INFO(x - 1,y).int_5)) { if (get_jobs (x, y, JOBS_LOAD_ORE) != 0) { MP_INFO(x,y).int_1 -= (MAX_ORE_ON_TRACK - MP_INFO(x - 1,y).int_5); MP_INFO(x - 1,y).int_5 = MAX_ORE_ON_TRACK; } } if (y > 0 && MP_GROUP(x,y-1) == GROUP_TRACK && MP_INFO(x,y - 1).int_5 < MAX_ORE_ON_TRACK && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_TRACK - MP_INFO(x,y - 1).int_5)) { if (get_jobs (x, y, JOBS_LOAD_ORE) != 0) { MP_INFO(x,y).int_1 -= (MAX_ORE_ON_TRACK - MP_INFO(x,y - 1).int_5); MP_INFO(x,y - 1).int_5 = MAX_ORE_ON_TRACK; } } /* if we've still got >90% ore and waste in stock, burn some waste cleanly. */ if (MP_INFO(x,y).int_1 > (MAX_ORE_AT_RECYCLE * 9 / 10) && MP_INFO(x,y).int_2 > (MAX_WASTE_AT_RECYCLE * 9 / 10)) MP_INFO(x,y).int_2 -= BURN_WASTE_AT_RECYCLE; }
/*****************************************************************************\ * Parse, process and respond to a request \*****************************************************************************/ static void _proc_msg(slurm_fd_t new_fd, char *msg) { DEF_TIMERS; char *req, *cmd_ptr, *msg_type = NULL; char response[128]; if (new_fd < 0) return; START_TIMER; if (!msg) { err_code = -300; err_msg = "NULL request message"; error("wiki: NULL request message"); goto resp_msg; } if (_parse_msg(msg, &req) != 0) goto resp_msg; cmd_ptr = strstr(req, "CMD="); if (cmd_ptr == NULL) { err_code = -300; err_msg = "request lacks CMD"; error("wiki: request lacks CMD"); goto resp_msg; } cmd_ptr +=4; err_code = 0; if (strncmp(cmd_ptr, "GETJOBS", 7) == 0) { msg_type = "wiki:GETJOBS"; if (!get_jobs(cmd_ptr, &err_code, &err_msg)) goto free_resp_msg; } else if (strncmp(cmd_ptr, "GETNODES", 8) == 0) { msg_type = "wiki:GETNODES"; if (!get_nodes(cmd_ptr, &err_code, &err_msg)) goto free_resp_msg; } else if (strncmp(cmd_ptr, "STARTJOB", 8) == 0) { msg_type = "wiki:STARTJOB"; start_job(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "CANCELJOB", 9) == 0) { msg_type = "wiki:CANCELJOB"; cancel_job(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "SUSPENDJOB", 10) == 0) { msg_type = "wiki:SUSPENDJOB"; suspend_job(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "RESUMEJOB", 9) == 0) { msg_type = "wiki:RESUMEJOB"; resume_job(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "MODIFYJOB", 9) == 0) { msg_type = "wiki:MODIFYJOB"; job_modify_wiki(cmd_ptr, &err_code, &err_msg); } else { err_code = -300; err_msg = "unsupported request type"; error("wiki: unrecognized request type: %s", req); } END_TIMER2(msg_type); resp_msg: snprintf(response, sizeof(response), "SC=%d RESPONSE=%s", err_code, err_msg); _send_reply(new_fd, response); return; free_resp_msg: /* Message is pre-formatted by get_jobs and get_nodes * ONLY if no error. Send message and xfree the buffer. */ _send_reply(new_fd, err_msg); xfree(err_msg); return; }
void do_organic_farm(int x, int y) { /* // MP_INFO(x,y) // int_1 unused // int_2 unused // int_3 is the food sold count so far this year. // int_4 is the food made last year. // int_5 is the random crop rotation key. // int_6 is the random month stagger, so they don't all flash at once // int_7 is the jobs stored at the farm * * MP_INFO(x+1,y) stores additional info * int_1 reserved (=x) * int_2 reserved (=y) * int_3 max possible production (assuming 100% water and power) * int_4 number of 1x1 tiles with underground water inside the farm * int_5 current production * // MP_TECH is the tech level of the farm when built // MP_ANIM FIXME, this is unused */ int i; int has_power = false; int used_jobs = 0; int tech_bonus = (int)(((double)MP_TECH(x, y) * ORGANIC_FARM_FOOD_OUTPUT) / MAX_TECH_LEVEL); MP_INFO(x + 1, y).int_3 = ORGANIC_FARM_FOOD_OUTPUT + tech_bonus; /* Animation */ if (MP_INFO(x, y).int_5 == 0) { /* this should be done when we create the area! */ MP_INFO(x, y).int_5 = (rand() % 4) + 1; MP_INFO(x, y).int_6 = rand() % 300; /* AL1 will be sooner or later redefined as %100. see below */ } /* check jobs */ if (MP_INFO(x, y).int_7 < FARM_JOBS_USED) { if (get_jobs(x, y, FARM_JOBS_USED) != 0) MP_INFO(x, y).int_7 += FARM_JOBS_USED; /* adding if (get_jobs ... /2) would allow to have some jobs stored at farm, * so would smooth the behavior and make farms more resistant to job penury. * Currently keep previous behavior. */ else if (get_jobs(x, y, FARM_JOBS_USED / 4) != 0) MP_INFO(x, y).int_7 += FARM_JOBS_USED / 4; else if (get_jobs(x, y, 1) != 0) MP_INFO(x, y).int_7 += 1; } /* check power */ MP_INFO(x, y).flags &= (0xffffffff - FLAG_POWERED); if (MP_INFO(x, y).int_7 >= 1) { /* There are jobs to do some production, so check for power */ if (get_power(x, y, ORG_FARM_POWER_REC, 0) != 0) { MP_INFO(x, y).flags |= FLAG_POWERED; has_power = true; } } /* Produce some food */ int prod = 0; if (MP_INFO(x, y).int_7 >= FARM_JOBS_USED) { used_jobs = FARM_JOBS_USED; if (has_power) { prod = ORGANIC_FARM_FOOD_OUTPUT + tech_bonus; } else { prod = ORGANIC_FARM_FOOD_OUTPUT / 4; } } else if (MP_INFO(x, y).int_7 >= FARM_JOBS_USED / 4) { used_jobs = FARM_JOBS_USED / 4; if (has_power) { prod = ORGANIC_FARM_FOOD_OUTPUT + tech_bonus / 4; } else { prod = ORGANIC_FARM_FOOD_OUTPUT / (4 * 4); } } else if (MP_INFO(x, y).int_7 >= 1) { /* got 1 job */ used_jobs = 1; if (has_power) { prod = ORGANIC_FARM_FOOD_OUTPUT + tech_bonus / 8; } else { /* AL1 "small ouch": * without power output with 1 job is bigger than output with 3 ! * 3 = FARMS_JOBS_USED / 4 * ORGANIC_FARM_FOOD_OUTPUT = 550 currently (ng_1.1) */ prod = 30 + ORGANIC_FARM_FOOD_OUTPUT / (4 * 8); } } else { /* AL1 : the farm gives very small amount of food without job. * ? Probably needed for start ? * ? Useful to prevent starvation when no jobs ? * The various buildings are "done" in random order, * so it should be ok without this. */ put_food(x, y, 30); /* note that this does not generate revenu int_3) */ } /* Check underground water, and reduce production accordingly */ if (use_waterwell) { // TODO No need to count each time. Should be done at build time, and stored int w = 0; int n = 0; for (int i = 0; i < MP_SIZE(x, y); i++) { for (int j = 0; j < MP_SIZE(x, y); j++) { n++; if (HAS_UGWATER(x + i, y + j)) w++; } } prod = (prod * w) / n; MP_INFO(x + 1, y).int_4 = w; } MP_INFO(x + 1, y).int_5 = prod; if (prod != 0) { if (put_food(x, y, prod) != 0) { MP_INFO(x, y).int_3++; MP_INFO(x, y).int_7 -= used_jobs; } } if ((total_time & 0x7f) == 0) if ((MP_INFO(x, y).flags & FLAG_POWERED) != 0) get_waste(x, y, 0x80 * ORG_FARM_WASTE_GET); if ((total_time % 1200) == 0) { MP_INFO(x, y).int_4 = MP_INFO(x, y).int_3; MP_INFO(x, y).int_3 = 0; } i = (total_time + MP_INFO(x, y).int_5 * 1200 + MP_INFO(x, y).int_6) % 4800; if (i % 300 == 0) { i /= 300; if ( MP_INFO(x, y).int_4 > MIN_FOOD_SOLD_FOR_ANIM) { if (i % 4 == 0) { MP_INFO(x, y).int_6 = rand() % 100; /* AL1: initially defined as %300 */ } switch (i) { case (0): MP_TYPE(x, y) = CST_FARM_O3; break; case (1): MP_TYPE(x, y) = CST_FARM_O3; break; case (2): MP_TYPE(x, y) = CST_FARM_O3; break; case (3): MP_TYPE(x, y) = CST_FARM_O3; break; case (4): MP_TYPE(x, y) = CST_FARM_O7; break; case (5): MP_TYPE(x, y) = CST_FARM_O7; break; case (6): MP_TYPE(x, y) = CST_FARM_O7; break; case (7): MP_TYPE(x, y) = CST_FARM_O7; break; case (8): MP_TYPE(x, y) = CST_FARM_O11; break; case (9): MP_TYPE(x, y) = CST_FARM_O11; break; case (10): MP_TYPE(x, y) = CST_FARM_O11; break; case (11): MP_TYPE(x, y) = CST_FARM_O11; break; case (12): MP_TYPE(x, y) = CST_FARM_O15; break; case (13): MP_TYPE(x, y) = CST_FARM_O15; break; case (14): MP_TYPE(x, y) = CST_FARM_O15; break; case (15): MP_TYPE(x, y) = CST_FARM_O15; break; } } else { MP_TYPE(x, y) = CST_FARM_O0; } } }
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; } } }
drmaa2_j_list drmaa2_msession_get_all_jobs(const drmaa2_msession ms, const drmaa2_jinfo filter) { drmaa2_j_list jobs = drmaa2_list_create(DRMAA2_JOBLIST, (drmaa2_list_entryfree)drmaa2_j_free); jobs = get_jobs(jobs, NULL, filter); return jobs; }
int work(void) { static int retcnt = 0; int i = 0; static pid_t ID[100]; static int workcnt = 0; int runid = 0; int jobs[max_running * 2 + 1]; pid_t tmp_pid = 0; /* get the database info */ //获取判题任务 if (!get_jobs(jobs)) { retcnt = 0; } /* exec the submit */ int j = 0; for (j = 0; jobs[j] > 0; j++) { runid = jobs[j]; if (runid % oj_tot != oj_mod) { continue; } write_log("judging solution %d.\n", runid); if (workcnt >= max_running) { // if no more client can running //总共有4个判题的进程,等待任何一个退出,可以在配置 //文件中设置个数 tmp_pid = waitpid(-1, NULL, 0); // wait 4 one child exit workcnt--; retcnt++; for (i = 0; i < max_running; i++) { // get the client id if (ID[i] == tmp_pid) { break; // got the client id } } ID[i] = 0; } else { // have free client for (i = 0; i < max_running; i++) // find the client id if (ID[i] == 0) { break; // got the client id } } if (workcnt < max_running && check_out(runid, OJ_CI)) { workcnt++; ID[i] = fork(); // start to fork if (ID[i] == 0) { write_log("judge solution %d in client%d.\n", runid, i); // 子进程运行判题客户端 run_client(runid, i); // if the process is the son, run it exit(EXIT_SUCCESS); } } else { ID[i] = 0; } } while ((tmp_pid = waitpid(-1, NULL, WNOHANG)) > 0) { workcnt--; retcnt++; for (i = 0; i < max_running; i++) { // get the client id if (ID[i] == tmp_pid) { break; // got the client id } } ID[i] = 0; write_log("client%d judge done.\n", i); } mysql_free_result(res); // free the memory executesql("commit"); write_log("total %d solution judge done.\n", retcnt); return retcnt; }
void do_market (int x, int y) { /* // int_1 contains the food it holds // int_2 contains the jobs // int_3 contains the coal // int_4 contains the goods // int_5 contains the ore // int_6 contains the steel // int_7 contains the waste */ int extra_jobs = 0; shuffle_markets (); if (x > 0 && (MP_INFO(x - 1,y).flags & FLAG_IS_TRANSPORT) != 0) extra_jobs += deal_with_transport (x, y, x - 1, y); if (x > 0 && (MP_INFO(x - 1,y + 1).flags & FLAG_IS_TRANSPORT) != 0) extra_jobs += deal_with_transport (x, y, x - 1, y + 1); if (y > 0 && (MP_INFO(x,y - 1).flags & FLAG_IS_TRANSPORT) != 0) extra_jobs += deal_with_transport (x, y, x, y - 1); if (y > 0 && (MP_INFO(x + 1,y - 1).flags & FLAG_IS_TRANSPORT) != 0) extra_jobs += deal_with_transport (x, y, x + 1, y - 1); if (x < WORLD_SIDE_LEN - 2 && (MP_INFO(x + 2,y).flags & FLAG_IS_TRANSPORT) != 0) extra_jobs += deal_with_transport (x, y, x + 2, y); if (x < WORLD_SIDE_LEN - 2 && (MP_INFO(x + 2,y + 1).flags & FLAG_IS_TRANSPORT) != 0) extra_jobs += deal_with_transport (x, y, x + 2, y + 1); if (y < WORLD_SIDE_LEN - 2 && (MP_INFO(x,y + 2).flags & FLAG_IS_TRANSPORT) != 0) extra_jobs += deal_with_transport (x, y, x, y + 2); if (y < WORLD_SIDE_LEN - 2 && (MP_INFO(x + 1,y + 2).flags & FLAG_IS_TRANSPORT) != 0) extra_jobs += deal_with_transport (x, y, x + 1, y + 2); if (MP_INFO(x,y).int_1 > MAX_FOOD_IN_MARKET) MP_INFO(x,y).int_1 = MAX_FOOD_IN_MARKET; if (MP_INFO(x,y).int_2 > MAX_JOBS_IN_MARKET) MP_INFO(x,y).int_2 = MAX_JOBS_IN_MARKET; if (MP_INFO(x,y).int_4 > MAX_GOODS_IN_MARKET) MP_INFO(x,y).int_4 = MAX_GOODS_IN_MARKET; /* now choose a graphic only dependent on food (for now anyway) */ if (total_time % 25 == 17) { if (MP_INFO(x,y).int_1 <= 0) { if (MP_INFO(x,y).int_2 > 0) MP_TYPE(x,y) = CST_MARKET_LOW; else MP_TYPE(x,y) = CST_MARKET_EMPTY; } else if (MP_INFO(x,y).int_1 < (MARKET_FOOD_SEARCH_TRIGGER / 2)) MP_TYPE(x,y) = CST_MARKET_LOW; else if (MP_INFO(x,y).int_1 < (MAX_FOOD_IN_MARKET - MAX_FOOD_IN_MARKET / 4)) MP_TYPE(x,y) = CST_MARKET_MED; else MP_TYPE(x,y) = CST_MARKET_FULL; } /* now employ some people */ get_jobs (x, y, 1 + (extra_jobs / 5)); /* keep the pbars accurate */ inventory(x,y); }
/*****************************************************************************\ * Parse, process and respond to a request \*****************************************************************************/ static void _proc_msg(slurm_fd_t new_fd, char *msg) { DEF_TIMERS; char *req, *cmd_ptr, *msg_type = NULL; char response[128]; if (new_fd < 0) return; START_TIMER; if (!msg) { err_code = -300; err_msg = "NULL request message"; error("wiki: NULL request message"); goto resp_msg; } if (_parse_msg(msg, &req) != 0) goto resp_msg; cmd_ptr = strstr(req, "CMD="); if (cmd_ptr == NULL) { err_code = -300; err_msg = "request lacks CMD"; error("wiki: request lacks CMD"); goto resp_msg; } cmd_ptr +=4; err_code = 0; if (strncmp(cmd_ptr, "GETJOBS", 7) == 0) { msg_type = "wiki:GETJOBS"; if (!get_jobs(cmd_ptr, &err_code, &err_msg)) goto free_resp_msg; } else if (strncmp(cmd_ptr, "GETNODES", 8) == 0) { msg_type = "wiki:GETNODES"; if (!get_nodes(cmd_ptr, &err_code, &err_msg)) goto free_resp_msg; } else if (strncmp(cmd_ptr, "STARTJOB", 8) == 0) { msg_type = "wiki:STARTJOB"; start_job(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "CANCELJOB", 9) == 0) { msg_type = "wiki:CANCELJOB"; cancel_job(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "REQUEUEJOB", 10) == 0) { msg_type = "wiki:REQUEUEJOB"; job_requeue_wiki(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "SUSPENDJOB", 10) == 0) { msg_type = "wiki:SUSPENDJOB"; suspend_job(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "RESUMEJOB", 9) == 0) { msg_type = "wiki:RESUMEJOB"; resume_job(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "JOBADDTASK", 10) == 0) { msg_type = "wiki:JOBADDTASK"; job_add_task(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "JOBRELEASETASK", 14) == 0) { msg_type = "wiki:JOBRELEASETASK"; job_release_task(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "JOBWILLRUN", 10) == 0) { msg_type = "wiki:JOBWILLRUN"; if (strstr(cmd_ptr, "NODES=")) { /* Updated format input and output */ if (!job_will_run2(cmd_ptr, &err_code, &err_msg)) goto free_resp_msg; } else { if (!job_will_run(cmd_ptr, &err_code, &err_msg)) goto free_resp_msg; } } else if (strncmp(cmd_ptr, "MODIFYJOB", 9) == 0) { msg_type = "wiki:MODIFYJOB"; job_modify_wiki(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "NOTIFYJOB", 9) == 0) { msg_type = "wiki:NOTIFYJOB"; job_notify_wiki(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "SIGNALJOB", 9) == 0) { msg_type = "wiki:SIGNALJOB"; job_signal_wiki(cmd_ptr, &err_code, &err_msg); } else if (strncmp(cmd_ptr, "INITIALIZE", 10) == 0) { msg_type = "wiki:INITIALIZE"; initialize_wiki(cmd_ptr, &err_code, &err_msg); } else { err_code = -300; err_msg = "unsupported request type"; error("wiki: unrecognized request type: %s", req); } END_TIMER2(msg_type); resp_msg: snprintf(response, sizeof(response), "SC=%d RESPONSE=%s", err_code, err_msg); _send_reply(new_fd, response); return; free_resp_msg: /* Message is pre-formatted by get_jobs and get_nodes * ONLY if no error. Send message and xfree the buffer. */ _send_reply(new_fd, err_msg); xfree(err_msg); return; }
void do_organic_farm (int x, int y) { /* // int_1 is the tech level of the farm when built // int_2 is a flag so we don't create a farm with nearly ripe crops. // int_3 is the food sold count so far this year. // int_4 is the food made last year. // int_5 is the random crop rotation key. // int_6 is the random month stagger, so they don't all flash at once // int_7 is the tech-level dependent output of a powered farm with a full // workforce. */ int i; if (MP_INFO(x,y).int_5 == 0) /* this should be done when we create */ { /* the area! */ MP_INFO(x,y).int_5 = (rand () % 4) + 1; MP_INFO(x,y).int_6 = rand () % 300; } MP_INFO(x,y).flags &= (0xffffffff - FLAG_POWERED); if (get_jobs (x, y, 1) == 0) put_food (x, y, 30); else if (get_jobs (x, y, FARM_JOBS_USED) != 0) { if (get_power (x, y, ORG_FARM_POWER_REC, 0) != 0) { if (put_food (x, y, (ORGANIC_FARM_FOOD_OUTPUT + MP_INFO(x,y).int_7)) == 0) put_jobs (x, y, FARM_JOBS_USED); else MP_INFO(x,y).int_3++; MP_INFO(x,y).flags |= FLAG_POWERED; } else { if (put_food (x, y, (ORGANIC_FARM_FOOD_OUTPUT / 4)) == 0) put_jobs (x, y, FARM_JOBS_USED); else MP_INFO(x,y).int_3++; } } else if (get_jobs (x, y, FARM_JOBS_USED / 4) != 0) { if (get_power (x, y, ORG_FARM_POWER_REC, 0) != 0) { if (put_food (x, y, (ORGANIC_FARM_FOOD_OUTPUT + (MP_INFO(x,y).int_7 / 4))) == 0) put_jobs (x, y, FARM_JOBS_USED / 4); else MP_INFO(x,y).int_3++; MP_INFO(x,y).flags |= FLAG_POWERED; } else { if (put_food (x, y, (ORGANIC_FARM_FOOD_OUTPUT / (4 * 4))) == 0) put_jobs (x, y, FARM_JOBS_USED / 4); else MP_INFO(x,y).int_3++; } } else { if (get_power (x, y, ORG_FARM_POWER_REC, 0) != 0) { if (put_food (x, y, (ORGANIC_FARM_FOOD_OUTPUT + (MP_INFO(x,y).int_7 / 8))) != 0) MP_INFO(x,y).int_3++; MP_INFO(x,y).flags |= FLAG_POWERED; } else if (put_food (x, y, 30 + (ORGANIC_FARM_FOOD_OUTPUT / (4 * 8))) != 0) MP_INFO(x,y).int_3++; } if ((total_time & 0x7f) == 0) if ((MP_INFO(x,y).flags & FLAG_POWERED) != 0) get_waste (x, y, 0x80 * ORG_FARM_WASTE_GET); if ((total_time % 1200) == 0) { MP_INFO(x,y).int_4 = MP_INFO(x,y).int_3; MP_INFO(x,y).int_3 = 0; } i = ((total_time + (MP_INFO(x,y).int_5 * 1200) + MP_INFO(x,y).int_6) % 4800); if (i % 300 == 0) { i /= 300; if ( /* MP_INFO(x,y).int_2!=0 && */ MP_INFO(x,y).int_4 > MIN_FOOD_SOLD_FOR_ANIM) { if (i % 4 == 0) { MP_INFO(x,y).int_6 = rand () % 100; } switch (i) { case (0): MP_TYPE(x,y) = CST_FARM_O3; break; case (1): MP_TYPE(x,y) = CST_FARM_O3; break; case (2): MP_TYPE(x,y) = CST_FARM_O3; break; case (3): MP_TYPE(x,y) = CST_FARM_O3; break; case (4): MP_TYPE(x,y) = CST_FARM_O7; break; case (5): MP_TYPE(x,y) = CST_FARM_O7; break; case (6): MP_TYPE(x,y) = CST_FARM_O7; break; case (7): MP_TYPE(x,y) = CST_FARM_O7; break; case (8): MP_TYPE(x,y) = CST_FARM_O11; break; case (9): MP_TYPE(x,y) = CST_FARM_O11; break; case (10): MP_TYPE(x,y) = CST_FARM_O11; break; case (11): MP_TYPE(x,y) = CST_FARM_O11; break; case (12): MP_TYPE(x,y) = CST_FARM_O15; break; case (13): MP_TYPE(x,y) = CST_FARM_O15; break; case (14): MP_TYPE(x,y) = CST_FARM_O15; break; case (15): MP_TYPE(x,y) = CST_FARM_O15; break; } } else { MP_TYPE(x,y) = CST_FARM_O0; } } }
void do_rocket_pad(int x, int y) { /* // You need ROCKET_PAD_JOBS, ROCKET_PAD_GOODS and ROCKET_PAD_STEEL // to add 1 to % of ready to fire. // int_1 is the stored jobs // int_2 is the stored goods // int_3 is the stored steel // int_4 is the count which gets to ROCKET_PAD_LAUNCH to fire. // int_5 unused // MP_ANIM is the time of the next animation frame, when waiting for launch. since 1.91 */ if (MP_TYPE(x, y) == CST_ROCKET_FLOWN) return; /* The rocket has been launched. */ /* get some jobs */ if (MP_INFO(x, y).int_1 < ROCKET_PAD_JOBS_STORE) { if (get_jobs(x, y, ROCKET_PAD_JOBS + 10) != 0) MP_INFO(x, y).int_1 += ROCKET_PAD_JOBS; } /* get goods */ if (MP_INFO(x, y).int_2 < ROCKET_PAD_GOODS_STORE) { if (get_goods(x, y, ROCKET_PAD_GOODS + 10) != 0) MP_INFO(x, y).int_2 += ROCKET_PAD_GOODS; else if (get_goods(x, y, ROCKET_PAD_GOODS / 10) != 0) MP_INFO(x, y).int_2 += ROCKET_PAD_GOODS / 5; else if (get_goods(x, y, ROCKET_PAD_GOODS / 50) != 0) MP_INFO(x, y).int_2 += ROCKET_PAD_GOODS / 20; } /* get steel */ if (MP_INFO(x, y).int_3 < ROCKET_PAD_STEEL_STORE) { if (get_steel(x, y, ROCKET_PAD_STEEL + 10) != 0) MP_INFO(x, y).int_3 += ROCKET_PAD_STEEL + 10; else if (get_steel(x, y, ROCKET_PAD_STEEL / 5) != 0) MP_INFO(x, y).int_3 += ROCKET_PAD_STEEL / 5; else if (get_steel(x, y, ROCKET_PAD_STEEL / 20) != 0) MP_INFO(x, y).int_3 += ROCKET_PAD_STEEL / 20; } #ifdef DEBUG_ROCKETS MP_INFO(x, y).int_4++; #else /* now build the rocket. Unlike uni's need a full store to make +1% */ if (MP_TYPE(x, y) < CST_ROCKET_5 && MP_INFO(x, y).int_1 >= ROCKET_PAD_JOBS_STORE && MP_INFO(x, y).int_2 >= ROCKET_PAD_GOODS_STORE && MP_INFO(x, y).int_3 >= ROCKET_PAD_STEEL_STORE) { MP_INFO(x, y).int_1 -= ROCKET_PAD_JOBS_STORE; MP_INFO(x, y).int_2 -= ROCKET_PAD_GOODS_STORE; MP_INFO(x, y).int_3 -= ROCKET_PAD_STEEL_STORE; MP_INFO(x, y).int_4++; goods_used += ROCKET_PAD_GOODS_STORE; } #endif rocket_pad_cost += ROCKET_PAD_RUNNING_COST; /* animate and return if already said no to launch */ if (MP_TYPE(x, y) >= CST_ROCKET_5 && MP_INFO(x, y).int_4 >= (100 * ROCKET_PAD_LAUNCH) / 100) { if (real_time >= MP_ANIM(x, y)) { MP_ANIM(x, y) = real_time + ROCKET_ANIMATION_SPEED; switch (MP_TYPE(x, y)) { case (CST_ROCKET_5): MP_TYPE(x, y) = CST_ROCKET_6; break; case (CST_ROCKET_6): MP_TYPE(x, y) = CST_ROCKET_7; break; case (CST_ROCKET_7): MP_TYPE(x, y) = CST_ROCKET_5; break; } } return; } /* now choose a graphic */ if (MP_INFO(x, y).int_4 < (25 * ROCKET_PAD_LAUNCH) / 100) MP_TYPE(x, y) = CST_ROCKET_1; else if (MP_INFO(x, y).int_4 < (60 * ROCKET_PAD_LAUNCH) / 100) MP_TYPE(x, y) = CST_ROCKET_2; else if (MP_INFO(x, y).int_4 < (90 * ROCKET_PAD_LAUNCH) / 100) MP_TYPE(x, y) = CST_ROCKET_3; else if (MP_INFO(x, y).int_4 < (100 * ROCKET_PAD_LAUNCH) / 100) MP_TYPE(x, y) = CST_ROCKET_4; else if (MP_INFO(x, y).int_4 >= (100 * ROCKET_PAD_LAUNCH) / 100) { MP_TYPE(x, y) = CST_ROCKET_5; update_main_screen(0); if (ask_launch_rocket_now(x, y)) { /* ? FIXME ? AL1: in NG 1.1 it seems we are never here ? * ? ask_launch_rocket_now manages everything and call launch_rocket ? */ launch_rocket(x, y); } } }
void do_blacksmith (int x, int y) { /* // int_1 contains the goods at the blacksmith // int_2 contains the goods made - for the animation // int_3 contains the coal store // int_4 is the animation trigger time // int_5 is the % made so far this month // int_6 is the % capacity last month */ if (MP_INFO(x,y).int_3 < MAX_COAL_AT_BLACKSMITH) if (get_coal (x, y, BLACKSMITH_GET_COAL) != 0) MP_INFO(x,y).int_3 += BLACKSMITH_GET_COAL; if (MP_INFO(x,y).int_1 < MAX_GOODS_AT_BLACKSMITH && MP_INFO(x,y).int_3 >= BLACKSMITH_COAL_USED) { if (get_steel (x, y, BLACKSMITH_STEEL_USED) != 0) { MP_INFO(x,y).int_1 += GOODS_MADE_BY_BLACKSMITH; MP_INFO(x,y).int_3 -= BLACKSMITH_COAL_USED; } } if (get_jobs (x, y, BLACKSMITH_JOBS) != 0) { if (MP_INFO(x,y).int_1 > GOODS_MADE_BY_BLACKSMITH) { if (put_goods (x, y, GOODS_MADE_BY_BLACKSMITH - 1) != 0) { MP_INFO(x,y).int_1 -= (GOODS_MADE_BY_BLACKSMITH - 1); MP_INFO(x,y).int_2 += (GOODS_MADE_BY_BLACKSMITH - 1); MP_INFO(x,y).int_5++; } else put_jobs (x, y, BLACKSMITH_JOBS); } else put_jobs (x, y, BLACKSMITH_JOBS); } else MP_TYPE(x,y) = CST_BLACKSMITH_0; if (MP_INFO(x,y).int_2 > BLACKSMITH_BATCH && real_time >= MP_INFO(x,y).int_4) { MP_INFO(x,y).int_4 = real_time + BLACKSMITH_ANIM_SPEED; switch (MP_TYPE(x,y)) { case (CST_BLACKSMITH_0): MP_TYPE(x,y) = CST_BLACKSMITH_1; break; case (CST_BLACKSMITH_1): MP_TYPE(x,y) = CST_BLACKSMITH_2; break; case (CST_BLACKSMITH_2): MP_TYPE(x,y) = CST_BLACKSMITH_3; break; case (CST_BLACKSMITH_3): MP_TYPE(x,y) = CST_BLACKSMITH_4; break; case (CST_BLACKSMITH_4): MP_TYPE(x,y) = CST_BLACKSMITH_5; break; case (CST_BLACKSMITH_5): MP_TYPE(x,y) = CST_BLACKSMITH_6; break; case (CST_BLACKSMITH_6): MP_TYPE(x,y) = CST_BLACKSMITH_1; MP_INFO(x,y).int_2 = 0; MP_POL(x,y)++; break; } } if (total_time % 100 == 0) { MP_INFO(x,y).int_6 = MP_INFO(x,y).int_5; MP_INFO(x,y).int_5 = 0; } }
void do_oremine (int x, int y) { /* // int_1 is the ore at in stock // int_2 is the ore reserve under the ground or at the surface really. */ int xx, yy, xs, ys, xe, ye, cr; if (MP_INFO(x,y).int_1 < DIG_MORE_ORE_TRIGGER - 5000) { xs = x; ys = y; xe = x + 4; ye = y + 4; cr = 0; for (yy = ys; yy < ye; yy++) for (xx = xs; xx < xe; xx++) cr += MP_INFO(xx,yy).ore_reserve; MP_INFO(x,y).int_2 = cr; if (cr > 0) if (get_jobs (x, y, JOBS_DIG_ORE) != 0) for (yy = ys; yy < ye; yy++) for (xx = xs; xx < xe; xx++) if (MP_INFO(xx,yy).ore_reserve > 0) { MP_INFO(xx,yy).ore_reserve--; MP_INFO(x,y).int_1 += 5000; ore_made += 5000; sust_dig_ore_coal_tip_flag = 0; /* maybe want an ore tax? */ yy = ye; xx = xe; /* break out */ } } if ((MP_INFO(x - 1,y).flags & FLAG_IS_TRANSPORT) != 0) { if (MP_GROUP(x-1,y) == GROUP_RAIL && MP_INFO(x - 1,y).int_5 < MAX_ORE_ON_RAIL && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_RAIL - MP_INFO(x - 1,y).int_5)) { if (get_jobs (x, y, JOBS_LOAD_ORE) != 0) { MP_INFO(x,y).int_1 -= (MAX_ORE_ON_RAIL - MP_INFO(x - 1,y).int_5); MP_INFO(x - 1,y).int_5 = MAX_ORE_ON_RAIL; } } else if (MP_GROUP(x-1,y) == GROUP_ROAD && MP_INFO(x - 1,y).int_5 < MAX_ORE_ON_ROAD && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_ROAD - MP_INFO(x - 1,y).int_5)) { if (get_jobs (x, y, JOBS_LOAD_ORE) != 0) { MP_INFO(x,y).int_1 -= (MAX_ORE_ON_ROAD - MP_INFO(x - 1,y).int_5); MP_INFO(x - 1,y).int_5 = MAX_ORE_ON_ROAD; } } else if (MP_GROUP(x - 1,y) == GROUP_TRACK && MP_INFO(x - 1,y).int_5 < MAX_ORE_ON_TRACK && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_TRACK - MP_INFO(x - 1,y).int_5)) { if (get_jobs (x, y, JOBS_LOAD_ORE) != 0) { MP_INFO(x,y).int_1 -= (MAX_ORE_ON_TRACK - MP_INFO(x - 1,y).int_5); MP_INFO(x - 1,y).int_5 = MAX_ORE_ON_TRACK; } } } if ((MP_INFO(x,y - 1).flags & FLAG_IS_TRANSPORT) != 0) { if (MP_GROUP(x,y-1) == GROUP_RAIL && MP_INFO(x,y - 1).int_5 < MAX_ORE_ON_RAIL && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_RAIL - MP_INFO(x,y - 1).int_5)) { if (get_jobs (x, y, JOBS_LOAD_ORE) != 0) { MP_INFO(x,y).int_1 -= (MAX_ORE_ON_RAIL - MP_INFO(x,y - 1).int_5); MP_INFO(x,y - 1).int_5 = MAX_ORE_ON_RAIL; } } else if (MP_GROUP(x,y-1) == GROUP_ROAD && MP_INFO(x,y - 1).int_5 < MAX_ORE_ON_ROAD && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_ROAD - MP_INFO(x,y - 1).int_5)) { if (get_jobs (x, y, JOBS_LOAD_ORE) != 0) { MP_INFO(x,y).int_1 -= (MAX_ORE_ON_ROAD - MP_INFO(x,y - 1).int_5); MP_INFO(x,y - 1).int_5 = MAX_ORE_ON_ROAD; } } else if (MP_GROUP(x,y-1) == GROUP_TRACK && MP_INFO(x,y - 1).int_5 < MAX_ORE_ON_TRACK && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_TRACK - MP_INFO(x,y - 1).int_5)) { if (get_jobs (x, y, JOBS_LOAD_ORE) != 0) { MP_INFO(x,y).int_1 -= (MAX_ORE_ON_TRACK - MP_INFO(x,y - 1).int_5); MP_INFO(x,y - 1).int_5 = MAX_ORE_ON_TRACK; } } } /* choose a graphic */ if ((total_time & 0x7f) == 0) { xx = 7 * (MP_INFO(x,y).int_2 + (3 * ORE_RESERVE / 2)) / (16 * ORE_RESERVE); switch (xx) { case (0): MP_TYPE(x,y) = CST_OREMINE_8; break; case (1): MP_TYPE(x,y) = CST_OREMINE_7; break; case (2): MP_TYPE(x,y) = CST_OREMINE_6; break; case (3): MP_TYPE(x,y) = CST_OREMINE_5; break; case (4): MP_TYPE(x,y) = CST_OREMINE_4; break; case (5): MP_TYPE(x,y) = CST_OREMINE_3; break; case (6): MP_TYPE(x,y) = CST_OREMINE_2; break; case (7): MP_TYPE(x,y) = CST_OREMINE_1; break; } if (MP_INFO(x,y).int_2 <= 0) { #if defined (commentout) do_bulldoze_area (CST_GREEN, x, y); place_item(x,y,CST_TIP_0); #endif int i,j; for (j = 0; j < 4; j++) { for (i = 0; i < 4; i++) { do_bulldoze_area (CST_WATER, x+i, y+j); } } connect_rivers (); refresh_main_screen (); } } }