本文整理汇总了C#中Agent.GetAgentNumber方法的典型用法代码示例。如果您正苦于以下问题:C# Agent.GetAgentNumber方法的具体用法?C# Agent.GetAgentNumber怎么用?C# Agent.GetAgentNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Agent
的用法示例。
在下文中一共展示了Agent.GetAgentNumber方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetActionForAgent
//Traverse the leafs of the tree to find a suitable task for this agent
public string GetActionForAgent(Agent agent)
{
//Check if the agent already has a node as its own
foreach(TreeNode leaf in leafs)
{
if(leaf.GetOwner() != null && leaf.GetOwner().GetAgentNumber() == agent.GetAgentNumber()) //if agent already owns a node
{
return leaf.GetActionName();
}
else if(leaf.GetOwner() != null) { //if an agent already is assisting on a node
if(OkayToAssist(agent, leaf, 2))
{
return "AssistingAction";
}
}
}
//not already an assister or owner of node then check if agent can get a new node
foreach(TreeNode leaf in leafs)
{
List<string> agents = ActionManager.Instance.AssistingAgentsToAction(agent.GetAgentType(), leaf.GetActionName());
if(agents.Count > 0 && leaf.GetOwnerNumber() == System.Guid.Empty ) //agent can own the node
{
leaf.SetOwner(agent);
return leaf.GetActionName();
}
else if(agents.Count > 1 && leaf.GetOwnerNumber() != System.Guid.Empty && agent.GetAgentType() != leaf.GetOwner().GetAgentType()) //agent can assist on the node
{
if(OkayToAssist(agent, leaf, 1))
{
leaf.GetAssisters().Add(agent);
return "AssistingAction";
}
}
}
return "IdleAction"; //agent cant to any of the leaf-node-actions
}
示例2: RemoveAgentFromOwnedNode
//Remove the agent from its owned node in the tree
public void RemoveAgentFromOwnedNode(Agent agent)
{
TreeNode ownedNode = GetOwnedNode(agent.GetAgentNumber());
if(ownedNode.GetPosition() != new Vector3(30, 0.5f, 30))
{
if(ownedNode.GetOwner().GetAgentNumber() == agent.GetAgentNumber())
{
ownedNode.SetOwner(null);
} else {
ownedNode.GetAssisters().Remove(agent);
}
}
}
示例3: RemoveNode
//Removes a node in the leafs that this agent owns and adds its parent to the leafs
public void RemoveNode(Agent agent)
{
TreeNode ownedNode = GetOwnedNode(agent.GetAgentNumber());
List<Agent> assisters = ownedNode.GetAssisters();
leafs.Remove(ownedNode); //remove the node from the leafs
//remove the node from the tree
int level = -1;
foreach(List<TreeNode> list in tree)
{
level++;
if(list.Contains(ownedNode))
{
list.Remove(ownedNode);
break;
}
}
if(ownedNode.GetParent() != null) //if node has a parent it might be possible for this agent to take that as its next owned node (more efficient, agents that get resource will also build house)
{
List<string> agents = ActionManager.Instance.AssistingAgentsToAction(agent.GetAgentType(), ownedNode.GetParent().GetActionName());
assisters = ownedNode.GetParent().GetAssisters();
if(HasChild(tree[level], ownedNode.GetParent()) == false )
{
int nrAgentToDoAction = agents.FindAll(item => item == agent.GetAgentType()).Count;
int nrSameColorAssisters = 0;
foreach(Agent assister in assisters)
{
if(assister.GetAgentType() == agent.GetAgentType())
{
nrSameColorAssisters++;
}
}
leafs.Add(ownedNode.GetParent());
if(nrAgentToDoAction - nrSameColorAssisters == 1)
{
ownedNode.GetParent().SetOwner(agent);
} else {
foreach(Agent assister in assisters)
{
if(assister.GetAgentType() == agent.GetAgentType())
{
ownedNode.GetParent().SetOwner(assister);
assisters.Remove(assister);
break;
}
}
}
} else if (HasChild(tree[level], ownedNode.GetParent()) == true)
{
if(agents.Contains(agent.GetAgentType()))
{
if(OkayToAssist(agent, ownedNode.GetParent(), 1))
{
ownedNode.GetParent().GetAssisters().Add(agent);
}
}
}
}
}
示例4: OkayToAssist
//check if its okay of the agent to assist on a node, mode 1 = check based on agentType, mode 2 = check based on agentNumber
public bool OkayToAssist(Agent agent, TreeNode ownedNode, int mode)
{
bool okToAssist;
if(mode == 1)
{
okToAssist = true;
} else {
okToAssist = false;
}
List <Agent> assisters = ownedNode.GetAssisters();
foreach(Agent assister in assisters)
{
if(mode == 1 && assister.GetAgentType() == agent.GetAgentType())
{
okToAssist = false;
} else if(mode == 2 && assister.GetAgentNumber() == agent.GetAgentNumber())
{
okToAssist = true;
}
}
return okToAssist;
}