| 6189 | } |
| 6190 | |
| 6191 | bool cHardwareExperimental::Inst_AttackPred(cAvidaContext& ctx) |
| 6192 | { |
| 6193 | assert(m_organism != 0); |
| 6194 | if (!TestAttackPred(ctx)) return false; |
| 6195 | |
| 6196 | cOrganism* target = NULL; |
| 6197 | if (!m_use_avatar) target = m_organism->GetOrgInterface().GetNeighbor(); |
| 6198 | else if (m_use_avatar == 2) target = m_organism->GetOrgInterface().GetRandFacedPredAV(); |
| 6199 | |
| 6200 | if (target->IsPreyFT() || m_organism->IsPreyFT()) return false; |
| 6201 | if (target->IsDead()) return false; |
| 6202 | |
| 6203 | sAttackReg reg; |
| 6204 | SetAttackReg(reg); |
| 6205 | |
| 6206 | if (!TestAttackChance(ctx, target, reg)) return false; |
| 6207 | else { |
| 6208 | if (m_world->GetConfig().MERIT_INC_APPLY_IMMEDIATE.Get()) { |
| 6209 | const double target_merit = target->GetPhenotype().GetMerit().GetDouble(); |
| 6210 | double attacker_merit = m_organism->GetPhenotype().GetMerit().GetDouble(); |
| 6211 | attacker_merit += target_merit * m_world->GetConfig().PRED_EFFICIENCY.Get(); |
| 6212 | m_organism->UpdateMerit(ctx, attacker_merit); |
| 6213 | } |
| 6214 | |
| 6215 | Apto::Array<int> target_reactions = target->GetPhenotype().GetLastReactionCount(); |
| 6216 | Apto::Array<int> org_reactions = m_organism->GetPhenotype().GetStolenReactionCount(); |
| 6217 | for (int i = 0; i < org_reactions.GetSize(); i++) { |
| 6218 | m_organism->GetPhenotype().SetStolenReactionCount(i, org_reactions[i] + target_reactions[i]); |
| 6219 | } |
| 6220 | |
| 6221 | const double target_bonus = target->GetPhenotype().GetCurBonus(); |
| 6222 | m_organism->GetPhenotype().SetCurBonus(m_organism->GetPhenotype().GetCurBonus() + (target_bonus * m_world->GetConfig().PRED_EFFICIENCY.Get())); |
| 6223 | |
| 6224 | if (m_world->GetConfig().USE_RESOURCE_BINS.Get()) { |
| 6225 | Apto::Array<double> target_bins = target->GetRBins(); |
| 6226 | for (int i = 0; i < target_bins.GetSize(); i++) { |
| 6227 | m_organism->AddToRBin(i, target_bins[i] * m_world->GetConfig().PRED_EFFICIENCY.Get()); |
| 6228 | target->AddToRBin(i, -1 * (target_bins[i] * m_world->GetConfig().PRED_EFFICIENCY.Get())); |
| 6229 | } |
| 6230 | const int spec_bin = (int) (m_organism->GetRBins()[m_world->GetConfig().COLLECT_SPECIFIC_RESOURCE.Get()]); |
| 6231 | setInternalValue(reg.bin_reg, spec_bin, true); |
| 6232 | } |
| 6233 | |
| 6234 | target->Die(ctx); // kill first -- could end up being killed by MAX_PRED if parent was pred |
| 6235 | MakeTopPred(ctx); |
| 6236 | |
| 6237 | setInternalValue(reg.success_reg, 1, true); |
| 6238 | setInternalValue(reg.bonus_reg, (int) (target_bonus), true); |
| 6239 | } |
| 6240 | return true; |
| 6241 | } |
| 6242 | |
| 6243 | //Kill (don't consume) organism faced by this one if you are both predators. |
| 6244 | bool cHardwareExperimental::Inst_KillPred(cAvidaContext& ctx) |
nothing calls this directly
no test coverage detected