An organism joins a group by setting it opinion to the group id.
| 5201 | |
| 5202 | //! An organism joins a group by setting it opinion to the group id. |
| 5203 | bool cHardwareExperimental::Inst_JoinGroup(cAvidaContext& ctx) |
| 5204 | { |
| 5205 | int opinion = m_world->GetConfig().DEFAULT_GROUP.Get(); |
| 5206 | // Check if the org is currently part of a group |
| 5207 | assert(m_organism != 0); |
| 5208 | |
| 5209 | int prop_group_id = GetRegister(FindModifiedRegister(rBX)); |
| 5210 | |
| 5211 | // check if this is a valid group |
| 5212 | if (m_world->GetConfig().USE_FORM_GROUPS.Get() == 2 && |
| 5213 | !(m_world->GetEnvironment().IsGroupID(prop_group_id))) { |
| 5214 | return false; |
| 5215 | } |
| 5216 | // injected orgs might not have an opinion |
| 5217 | if (m_organism->GetOrgInterface().HasOpinion(m_organism)) { |
| 5218 | opinion = m_organism->GetOpinion().first; |
| 5219 | |
| 5220 | //return false if org setting opinion to current one (avoid paying costs for not switching) |
| 5221 | if (opinion == prop_group_id) return false; |
| 5222 | |
| 5223 | // A random chance for failure to join group based on config, if failed return true for resource cost. |
| 5224 | if (m_world->GetConfig().JOIN_GROUP_FAILURE.Get() > 0) { |
| 5225 | int percent_failure = m_world->GetConfig().JOIN_GROUP_FAILURE.Get(); |
| 5226 | double prob_failure = (double) percent_failure / 100.0; |
| 5227 | double rand = ctx.GetRandom().GetDouble(); |
| 5228 | if (rand <= prob_failure) return true; |
| 5229 | } |
| 5230 | |
| 5231 | // If tolerances are on the org must pass immigration chance |
| 5232 | if (m_world->GetConfig().TOLERANCE_WINDOW.Get() > 0) { |
| 5233 | m_organism->GetOrgInterface().AttemptImmigrateGroup(ctx,prop_group_id, m_organism); |
| 5234 | return true; |
| 5235 | } |
| 5236 | else { |
| 5237 | // otherwise, subtract org from current group |
| 5238 | m_organism->LeaveGroup(opinion); |
| 5239 | } |
| 5240 | } |
| 5241 | |
| 5242 | // Set the opinion |
| 5243 | m_organism->GetOrgInterface().SetOpinion(prop_group_id, m_organism); |
| 5244 | |
| 5245 | // Add org to group count |
| 5246 | if (m_organism->GetOrgInterface().HasOpinion(m_organism)) { |
| 5247 | opinion = m_organism->GetOpinion().first; |
| 5248 | m_organism->JoinGroup(opinion); |
| 5249 | } |
| 5250 | |
| 5251 | return true; |
| 5252 | } |
| 5253 | |
| 5254 | // A predator can establish a new group, attempt to immigrate into the group that marked the cell in front of them, or become a nomad. |
| 5255 | bool cHardwareExperimental::Inst_ChangePredGroup(cAvidaContext& ctx) |
nothing calls this directly
no test coverage detected