Esempio n. 1
0
    //public override void doAction(ProcessContext context)
    //{
    //    int[] paramIndices = getParameterIndices(currentIndex, instructions);
    //    if (testCondition(bc, currentIndex, instructions))
    //    {
    //        int param3 = paramIndices[2];
    //        instructions[param3]
    //           .doAction(bc, param3, instructions);
    //    }
    //    else
    //    {
    //        int param4 = paramIndices[3];
    //        instructions[param4]
    //            .doAction(bc, param4, instructions);
    //    }
    //}

    public override bool testCondition(ProcessContext context)
    {
        int[] paramIndices = getParameterIndices(context);
        //Process the comparator
        int   param1 = paramIndices[0];
        float and1   = context.instruction(param1)
                       .instructionToNumber(context.context(param1));
        int   param2 = paramIndices[1];
        float and2   = context.instruction(param2)
                       .instructionToNumber(context.context(param2));

        if (lessThan)
        {
            if (and1 < and2)
            {
                return(true);
            }
        }
        if (greaterThan)
        {
            if (and1 > and2)
            {
                return(true);
            }
        }
        if (equalTo)
        {
            if (and1 == and2)
            {
                return(true);
            }
        }
        return(false);
    }
Esempio n. 2
0
    public override void doAction(ProcessContext context)
    {
        int[] paramIndices   = getParameterIndices(context);
        int   param1         = paramIndices[0];
        int   memoryLocation = (int)context.instruction(param1)
                               .instructionToNumber(context.context(param1));
        BotController bc = context.botController;

        switch (option)
        {
        case Option.STORE:
            int    param2      = paramIndices[1];
            object storeObject = context.instruction(param2)
                                 .getReturnObject(context.context(param2));
            if (!bc.memory.ContainsKey(memoryLocation))
            {
                bc.memory.Add(memoryLocation, storeObject);
            }
            else
            {
                bc.memory[memoryLocation] = storeObject;
            }
            Debug.Log("Stored[" + memoryLocation + "]: " + bc.memory[memoryLocation]);
            break;

        case Option.ERASE:
            bc.memory.Remove(memoryLocation);
            break;
        }
    }
Esempio n. 3
0
    public override float instructionToNumber(ProcessContext context)
    {
        int[] paramIndices = getParameterIndices(context);
        int   param1       = paramIndices[0];
        int   param2       = paramIndices[1];

        return(Vector3.Distance(
                   context.instruction(param1).
                   instructionToPosition(context.context(param1)),
                   context.instruction(param2).
                   instructionToPosition(context.context(param2))
                   ));
    }
Esempio n. 4
0
    public override void doAction(ProcessContext context)
    {
        BotController bc = context.botController;

        int[]   paramIndices = getParameterIndices(context);
        int     param1       = paramIndices[0];
        Vector2 direction    = context.instruction(param1)
                               .instructionToDirection(context.context(param1));

        direction = bc.transform.TransformDirection(direction);
        Entity entity = GridManager.nextObjectInDirection(
            bc.transform.position,
            direction,
            true
            );

        if (!entity)
        {
            return;
        }
        //If object is within range,
        if (Vector2.Distance(bc.transform.position, entity.transform.position) <= 1)
        {
            //Push it
            Vector2 newPos = GridManager.moveObject(entity.gameObject, (Vector2)entity.transform.position + direction);
            if (entity is BotController)
            {
                entity.transform.position = newPos;
            }
        }
    }
Esempio n. 5
0
 public override void doAction(ProcessContext context)
 {
     int[] paramIndices = getParameterIndices(context);
     if (testCondition(context))
     {
         int param2 = paramIndices[1];
         context.instruction(param2)
         .doAction(context.context(param2));
     }
     else
     {
         int param3 = paramIndices[2];
         context.instruction(param3)
         .doAction(context.context(param3));
     }
 }
Esempio n. 6
0
    public override bool testCondition(ProcessContext context)
    {
        int[] paramIndices = getParameterIndices(context);
        int   param1       = paramIndices[0];

        return(context.instruction(param1)
               .testCondition(context.context(param1)));
    }
Esempio n. 7
0
    private int getMemoryLocation(ProcessContext context)
    {
        int[] paramIndices   = getParameterIndices(context);
        int   param1         = paramIndices[0];
        int   memoryLocation = (int)context.instruction(param1)
                               .instructionToNumber(context.context(param1));

        Debug.Log("Getting memory location[" + memoryLocation + "]");
        return(memoryLocation);
    }
    public override Vector2 instructionToPosition(ProcessContext context)
    {
        int[]  paramIndices = getParameterIndices(context);
        int    param1       = paramIndices[0];
        Entity entity       = context.instruction(param1)
                              .instructionToEntity(context.context(param1));

        if (entity)
        {
            return(entity.transform.position);
        }
        return(base.instructionToPosition(context));
    }
Esempio n. 9
0
    public override void doAction(ProcessContext context)
    {
        int[]   paramIndices = getParameterIndices(context);
        int     param1       = paramIndices[0];
        Vector3 position     = context.instruction(param1).
                               instructionToPosition(context.context(param1));
        Vector2       moveDir = Vector2.zero;
        BotController bc      = context.botController;

        switch (option)
        {
        case Option.TOWARDS:
            moveDir = (position - bc.transform.position).normalized;
            break;

        case Option.AWAY:
            moveDir = (bc.transform.position - position).normalized;
            break;
        }
        bc.moveDirection += bc.transform.InverseTransformDirection(moveDir);
    }
Esempio n. 10
0
    public override Entity instructionToEntity(ProcessContext context)
    {
        if (option == Option.SELF)
        {
            return(context.botController);
        }
        if (option == Option.IN_DIRECTION)
        {
            int[]   paramIndices = getParameterIndices(context);
            int     param1       = paramIndices[0];
            Vector2 direction    = context.instruction(param1)
                                   .instructionToDirection(context.context(param1));
            Entity entity = GridManager.nextObjectInDirection(
                context.botController.transform.position,
                context.botController.transform.TransformDirection(direction),
                true
                );
            return(entity);
        }
        //Get the target type string
        string targetTypeString = typeof(BotController).Name;

        if (entityType != EntityType.BOT)
        {
            targetTypeString = typeof(AreaTile).Name + "." + entityType;
        }
        //
        float  extreme = (option == Option.CLOSEST) ? float.MaxValue : 0;
        Entity target  = null;

        foreach (Entity fbc in FindObjectsOfType <Entity>())
        {
            if (fbc != context.botController &&
                fbc.getTypeString() == targetTypeString)
            {
                float distance = Vector3.Distance(
                    context.botController.transform.position,
                    fbc.transform.position
                    );
                switch (option)
                {
                case Option.CLOSEST:
                    if (distance < extreme)
                    {
                        extreme = distance;
                        target  = fbc;
                    }
                    break;

                case Option.FURTHEST:
                    if (distance > extreme)
                    {
                        extreme = distance;
                        target  = fbc;
                    }
                    break;
                }
            }
        }
        return(target);
    }