Ejemplo n.º 1
0
        color FragmentShader(VertexOut vertex, Field <building> Buildings, Field <unit> Units, PointSampler Texture, PointSampler Explosion,
                             [Player.Vals] float player,
                             float s)
        {
            color output = color.TransparentBlack;

            building building_here = Buildings[Here];
            unit     unit_here     = Units[Here];

            if (!IsBuilding(unit_here))
            {
                return(output);
            }

            vec2 subcell_pos = get_subcell_pos(vertex, Buildings.Size);

            if (Something(building_here))
            {
                if (building_here.direction >= Dir.StationaryDead)
                {
                    float frame = ExplosionSpriteSheet.ExplosionFrame(s, building_here);
                    if (frame < ExplosionSpriteSheet.AnimLength)
                    {
                        output += ExplosionSprite(building_here, unit_here, subcell_pos, frame, Explosion);
                    }
                }
                else
                {
                    float frame = 0;
                    output += Sprite(player, building_here, unit_here, subcell_pos, frame, Texture);
                }
            }

            return(output);
        }
Ejemplo n.º 2
0
        data FragmentShader(VertexOut vertex, Field <vec4> TargetData, Field <unit> Unit, Field <extra> Extra, Field <data> Data, Field <data> PrevData, Field <vec4> PathToOtherTeams, Field <vec4> RandomField, Field <magic> Magic,
                            Field <geo> Geo, Field <geo> AntiGeo,
                            Field <dirward> DirwardRight, Field <dirward> DirwardLeft, Field <dirward> DirwardUp, Field <dirward> DirwardDown)
        {
            data  data_here  = Data[Here];
            magic magic_here = Magic[Here];

            if (Something(data_here))
            {
                data path = data.Nothing;

                // Get info for this unit
                unit unit_here = Unit[Here];

                // Remove if dead unit
                if (unit_here.anim == Anim.Die && IsUnit(unit_here))
                {
                    return(data.Nothing);
                }

                // Remove if dead building
                building b = (building)(vec4)data_here;
                if (IsBuilding(unit_here))
                {
                    // If this building is alive
                    if (data_here.direction == Dir.Stationary)
                    {
                        // If this is a building that has been hit enough times to explode
                        if (unit_here.hit_count >= _5)
                        {
                            data_here.direction = Dir.StationaryDying;
                        }
                    }
                    else
                    {
                        // Otherwise remove it if the explosion animation is done
                        float frame = ExplosionSpriteSheet.ExplosionFrame(0, b);

                        if (frame >= ExplosionSpriteSheet.AnimLength)
                        {
                            return(data.Nothing);
                        }
                    }
                }

                // Units that are done being raised should switch to attacking.
                if (IsUnit(unit_here) && unit_here.anim == Anim.DoRaise)
                {
                    data_here.action = UnitAction.Attacking;
                }

                // Units that are about to be incinerated or are being raised can't move.
                if (IsUnit(unit_here) && (magic_here.kill == _true || unit_here.anim == Anim.StartRaise))
                {
                    data_here.action = UnitAction.Stopped;
                    return(data_here);
                }

                // Buildings can't move.
                if (IsBuilding(unit_here))
                {
                    if (IsCenter((building)(vec4)data_here))
                    {
                        // Set the building direction toward its "target".
                        set_prior_direction(ref data_here, BuildingDirection(vertex, TargetData, (building)(vec4)data_here));
                    }
                    return(data_here);
                }

                // Get nearby paths to other teams
                vec4
                    _value_right = PathToOtherTeams[RightOne],
                    _value_up    = PathToOtherTeams[UpOne],
                    _value_left  = PathToOtherTeams[LeftOne],
                    _value_down  = PathToOtherTeams[DownOne];

                // Get specific paths to enemies of this particular unit
                float value_right = 1, value_left = 1, value_up = 1, value_down = 1;
                if (unit_here.team == Team.One)
                {
                    value_right = _value_right.x;
                    value_left  = _value_left.x;
                    value_up    = _value_up.x;
                    value_down  = _value_down.x;
                }
                else if (unit_here.team == Team.Two)
                {
                    value_right = _value_right.y;
                    value_left  = _value_left.y;
                    value_up    = _value_up.y;
                    value_down  = _value_down.y;
                }
                else if (unit_here.team == Team.Three)
                {
                    value_right = _value_right.z;
                    value_left  = _value_left.z;
                    value_up    = _value_up.z;
                    value_down  = _value_down.z;
                }
                else if (unit_here.team == Team.Four)
                {
                    value_right = _value_right.w;
                    value_left  = _value_left.w;
                    value_up    = _value_up.w;
                    value_down  = _value_down.w;
                }

                float auto_attack_cutoff = _12;
                if (unit_here.type == UnitType.DragonLord)
                {
                    auto_attack_cutoff = _2;
                }
                if (unit_here.type == UnitType.Necromancer)
                {
                    auto_attack_cutoff = _2;
                }

                float min      = 256;
                float hold_dir = data_here.direction;
                if (data_here.action == UnitAction.Attacking || data_here.action == UnitAction.Guard)
                {
                    if (value_right < min)
                    {
                        data_here.direction = Dir.Right; min = value_right;
                    }
                    if (value_up < min)
                    {
                        data_here.direction = Dir.Up; min = value_up;
                    }
                    if (value_left < min)
                    {
                        data_here.direction = Dir.Left; min = value_left;
                    }
                    if (value_down < min)
                    {
                        data_here.direction = Dir.Down; min = value_down;
                    }
                }

                if (min > auto_attack_cutoff)
                {
                    // Not within auto attack range, so fallback to previous direction.
                    data_here.direction = hold_dir;
                }
                else
                {
                    // If we're within auto attack range and we're a necromancer, we should run away.
                    // Necromancers are cowards.
                    if (unit_here.type == UnitType.Necromancer)
                    {
                        TurnAround(ref data_here);
                    }
                }

                // If we are guarding and a unit is close, switch to attacking
                if (min < auto_attack_cutoff && data_here.action == UnitAction.Guard)
                {
                    data_here.action = UnitAction.Attacking;
                }

                // If we aren't attacking, or if a unit is too far away
                if (min > auto_attack_cutoff && data_here.action == UnitAction.Attacking || data_here.action == UnitAction.Moving)
                {
                    NaivePathfind(vertex, Data, PrevData, TargetData, Extra, RandomField,
                                  Geo, AntiGeo,
                                  DirwardRight, DirwardLeft, DirwardUp, DirwardDown,
                                  unit_here, ref data_here);
                }
            }

            return(data_here);
        }