Entity * clone_kitten(KittenManager * litter, float x, float y) { Entity * body = clone_entity(litter->mother); Kitten * mam = (Kitten *) entity_user_data(body); Kitten * kitty = (Kitten *) zone(sizeof(Kitten)); kitty->player = mam->player; kitty->world = mam->world; kitty->time = mam->time; kitty->others = mam->others; kitty->body = body; kitty->attack_timer = new_expirer(ATTACK_FREQUENCY); kitty->claw_timer = new_expirer(CLAW_FREQUENCY); kitty->claw = mam->claw; kitty->count_ptr = &(litter->kitten_count); litter->kitten_count ++; entity_set_user_data(body, kitty); entity_set_position(body, x, y); register_entity(mam->others, body); return body; }
bool MatchPool::get_entity_rand(int need_size, MatchEntity *dst) { int size = 0; for (int i = need_size;i >= 1; i--) { std::map<int, MatchQueue*>::iterator itr = _queues.find(i); if (itr == _queues.end()) { continue; } MatchQueue *que = itr->second; if (que == NULL || que->size_type > need_size - size) { continue; } // rand std::deque<oid_t>::iterator itr_c = que->candidates.begin(); std::vector<oid_t> candidates; for (;itr_c != que->candidates.end(); ++itr_c) { MatchEntity *curr = get_entity(*itr_c); if (curr != NULL && curr->status == MATCH_PENDING) { candidates.push_back(*itr_c); } } int size_type = que->size_type; if (candidates.size() == 0 || candidates.size() < size_t((need_size - size) / size_type)) { continue; } int total = candidates.size(); while (size + size_type <= need_size) { int idx = rand(0, total - 1); MatchEntity *curr = get_entity(candidates[idx]); if (curr != NULL && curr->status == MATCH_PENDING) { curr->status = MATCH_DONE; dst->members.push_back(clone_entity(curr)); size += size_type; } } if (size == need_size) { break; } } return size == need_size; }
bool MatchPool::top(MatchEntity &ent, int size_type) { std::map<int, MatchQueue*>::iterator itr = _queues.find(size_type); if (itr == _queues.end()) { return false; } MatchQueue *que = itr->second; if (que->candidates.empty()) { return false; } std::deque<oid_t>::iterator i_que = que->candidates.begin(); for (;i_que != que->candidates.end(); ++i_que) { MatchEntity *curr = get_entity(*i_que); if (curr && curr->status == MATCH_PENDING) { curr->status = MATCH_DONE; //ent = clone_entity(curr); ent.members.push_back(clone_entity(curr)); ent.size = size_type; return true; } } return false; }