Must be nop-modified. * Places the number of resources in the group either +1 or -1 in register BX, * wrapping from the top group back to group 1 (skipping 0), * +1 group if the nop register has a positive number * -1 group if the nop register has a negative number. */
| 4479 | * -1 group if the nop register has a negative number. |
| 4480 | */ |
| 4481 | bool cHardwareCPU::Inst_SenseNextResLevel(cAvidaContext& ctx) |
| 4482 | { |
| 4483 | // Check for an opinion. |
| 4484 | if (!m_organism->GetOrgInterface().HasOpinion(m_organism)) return false; |
| 4485 | if (m_world->GetConfig().USE_FORM_GROUPS.Get() != 2) return false; |
| 4486 | int opinion = m_organism->GetOpinion().first; |
| 4487 | |
| 4488 | const int num_groups = m_organism->GetOrgInterface().GetResources(ctx).GetSize(); |
| 4489 | if (num_groups <= 2) return false; |
| 4490 | |
| 4491 | // If not nop-modified, fails to execute. |
| 4492 | if (!(m_inst_set->IsNop(getIP().GetNextInst()))) return false; |
| 4493 | // Retreives the value from the nop-modifying register. |
| 4494 | const int nop_register = FindModifiedRegister(REG_BX); |
| 4495 | int register_value = GetRegister(nop_register); |
| 4496 | if (register_value == 0) return false; |
| 4497 | |
| 4498 | const Apto::Array<double> res_count = m_organism->GetOrgInterface().GetResources(ctx); |
| 4499 | if (opinion == (num_groups - 1)) { |
| 4500 | if (register_value > 0) GetRegister(REG_BX) = (int) (res_count[1] * 100 + 0.5); |
| 4501 | else if (register_value < 0) GetRegister(REG_BX) = (int) (res_count[opinion - 1] * 100 + 0.5); |
| 4502 | } |
| 4503 | else if ((opinion == 1) || (opinion == 0)) { |
| 4504 | if (register_value > 0) GetRegister(REG_BX) = (int) (res_count[opinion + 1] * 100 + 0.5); |
| 4505 | else if (register_value < 0) GetRegister(REG_BX) = (int) (res_count[num_groups - 1] * 100 + 0.5); |
| 4506 | } |
| 4507 | else if ((opinion != (num_groups - 1)) && (opinion != 1) && (opinion != 0)) { |
| 4508 | if (register_value > 0) GetRegister(REG_BX) = (int) (res_count[opinion + 1] * 100 + 0.5); |
| 4509 | else if (register_value < 0) GetRegister(REG_BX) = (int) (res_count[opinion - 1] * 100 + 0.5); |
| 4510 | } |
| 4511 | return true; |
| 4512 | } |
| 4513 | |
| 4514 | bool cHardwareCPU::Inst_SenseDiffFaced(cAvidaContext& ctx) |
| 4515 | { |
nothing calls this directly
no test coverage detected