void Game::create_new_tower(towers::TowerType tower_type, GridPosition position) { Tile* tile = grid->get_tile(position); if (!grid->is_placeable_tile(tile)) return; for (iter_enemy = enemy_list.begin(); iter_enemy != enemy_list.end(); iter_enemy++) { if ((*iter_enemy)->is_on_tile(tile)) { return; } } Tower* new_tower = new Tower(this, tower_type, tile); if (money < new_tower->get_cost_buy()) { delete new_tower; new_tower = NULL; return; } new_tower->set_tile(tile); tile->set_tower(new_tower); grid->clear_paths(); if (grid->get_path(grid->get_start_tile(), grid->get_portal_tile())->size() == 0) { tile->set_tower(NULL); grid->clear_paths(); grid->get_path(grid->get_start_tile(), grid->get_portal_tile()); delete new_tower; new_tower = NULL; return; } // loop through all enemies and update their path for (iter_enemy = enemy_list.begin(); iter_enemy != enemy_list.end(); iter_enemy++) { if ( !(*iter_enemy)->try_update_path()) { // couldn't update path, don't place tower tile->set_tower(NULL); grid->clear_paths(); grid->get_path(grid->get_start_tile(), grid->get_portal_tile()); delete new_tower; return; } } //New tower CAN be placed. SFX_build->play(); set_boost_update(true); update_enemy_path = true; money -= new_tower->get_cost_buy(); update_money(); tower_list.push_back(new_tower); if (option_box_visible) { hide_option_box(); select(tile); } }
void NoximNoC::moc_mapping(){ idle_core_price_sort(); update_running_app(); update_money(); int time = (int)sc_time_stamp().to_double() / 1000; //if (time % 1000 == 0){ for (int r = 0; r < running_app.size(); r++){ int arrival = running_app[r]; if (app_queue[arrival].money_used < app_queue[arrival].money_allowed){ app_queue[arrival].expand(t); } else { app_queue[arrival].shrink(t); } } //} }
void Game::upgrade_tower(towers::TowerType tower_type) { if (tile_selection != NULL) { Tower* tower = tile_selection->get_tower(); if (tower == NULL) return; int cost = tower->get_cost_upgrade(); if (money < cost) return; if (!tower->upgrade(tower_type)) return; money -= cost; set_boost_update(true); update_money(); SFX_upgrade->play(); if (tower_type > towers::WALL) hide_option_box(); else update_option_box(); } }
void* client_thread(void *arg) { struct user *__user = (struct user *)arg; struct user user; int sockfd = *(__user->sockfd), ret; size_t n; int nready; char buf[MSG_MAXLEN + 1]; char horse_buf[(HORSE_NAME + 13) * (HORSE_RUN + 1)]; char *resp; unsigned int _money; byte send_win = 0; fd_set rset, active; struct timeval tv, active_tv = { 0, 100 }; FD_ZERO(&active); FD_SET(sockfd, &active); init_client(&user, __user); _pthread_detach(pthread_self()); while (work || run) { if (!run) { send_win = 0; rset = active; tv = active_tv; nready = select(sockfd + 1, &rset, NULL, NULL, &tv); if ((nready < 0 && errno == EINTR) || !nready) continue; // someone wants to write // write on client terminal if (!(n = read(sockfd, buf, MSG_MAXLEN))) { if (errno == EINTR) continue; break; } else { buf[n < MSG_MAXLEN ? n : MSG_MAXLEN] = 0; if (buf[0] == '\r' || buf[0] == '\n') continue; ret = parse_request(buf, n, &resp, &user); // send response _write(sockfd, (void *)resp, strlen(resp)); if (!ret) free(resp); } } // send current state of run, and money after else { if (send_win) continue; _pthread_mutex_lock(user.service->mfinished); if (!user.service->finished) send_horse_cur_info(sockfd, horse_buf, &user); else { _money = 0; update_money(&user, &_money); snprintf(buf, MSG_MAXLEN * 2, "Winner: %s; you won %u; your current accout: %u\n", user.service->win->name, _money, user.money); _write(sockfd, (void *)buf, strlen(buf)); send_win = 1; user.horse = NULL; user.bet = 0; } _pthread_mutex_unlock(user.service->mfinished); _sleep(1, 0); } } _close(sockfd); return NULL; }