protected color SolidColor(float player, data data, unit unit) { return(unit.player == player && fake_selected(data) ? SelectedUnitColor.Get(unit.player) : UnitColor.Get(unit.player)); }
color FragmentShader(VertexOut vertex, Field <data> CurrentData, Field <data> PreviousData, Field <unit> CurrentUnits, Field <unit> PreviousUnits, TextureSampler UnitTexture, TextureSampler ShadowTexture, [Player.Vals] float player, float s, float t, float selection_blend, float selection_size, [Vals.Bool] bool solid_blend_flag, float solid_blend) { // Calculate shadow pixel color shadow = color.TransparentBlack; vec2 shadow_subcell_pos = get_subcell_pos(vertex, CurrentData.Size, vec(0f, -.5f)); var shadow_here = Here + new RelativeIndex(0, -.5f); data shadow_cur = CurrentData[shadow_here], shadow_pre = PreviousData[shadow_here]; unit shadow_cur_unit = CurrentUnits[shadow_here], shadow_pre_unit = PreviousUnits[shadow_here]; if (IsUnit(shadow_cur_unit) || IsUnit(shadow_pre_unit)) { if (Something(shadow_cur) && shadow_cur.change == Change.Stayed) { if (s > .5) { shadow_pre = shadow_cur; } shadow += ShadowSprite(player, shadow_pre, shadow_pre_unit, shadow_subcell_pos, ShadowTexture, selection_blend, selection_size, solid_blend_flag, solid_blend); } else { if (IsValid(shadow_cur.direction)) { var prior_dir = prior_direction(shadow_cur); shadow_cur.direction = prior_dir; vec2 offset = (1 - s) * direction_to_vec(prior_dir); shadow += ShadowSprite(player, shadow_cur, shadow_cur_unit, shadow_subcell_pos + offset, ShadowTexture, selection_blend, selection_size, solid_blend_flag, solid_blend); } if (IsValid(shadow_pre.direction) && shadow.a < .025f) { vec2 offset = -s *direction_to_vec(shadow_pre.direction); shadow += ShadowSprite(player, shadow_pre, shadow_pre_unit, shadow_subcell_pos + offset, ShadowTexture, selection_blend, selection_size, solid_blend_flag, solid_blend); } } } // Calculate unit pixel color output = color.TransparentBlack; vec2 subcell_pos = get_subcell_pos(vertex, CurrentData.Size); data cur = CurrentData[Here], pre = PreviousData[Here]; unit cur_unit = CurrentUnits[Here], pre_unit = PreviousUnits[Here]; if (!IsUnit(cur_unit) && !IsUnit(pre_unit)) { return(shadow); } if (Something(cur) && cur.change == Change.Stayed) { if (s > .5) { pre = cur; } float _s = (cur_unit.anim == _0 ? t : s); if (cur_unit.anim == Anim.DoRaise) { cur_unit.anim = Anim.Die; _s = 1f - _s; } float frame = _s * UnitSpriteSheet.AnimLength + Float(cur_unit.anim); output += Sprite(player, pre, pre_unit, subcell_pos, frame, UnitTexture, selection_blend, selection_size, solid_blend_flag, solid_blend); } else { float frame = s * UnitSpriteSheet.AnimLength + Float(Anim.Walk); if (IsValid(cur.direction)) { var prior_dir = prior_direction(cur); cur.direction = prior_dir; vec2 offset = (1 - s) * direction_to_vec(prior_dir); output += Sprite(player, cur, cur_unit, subcell_pos + offset, frame, UnitTexture, selection_blend, selection_size, solid_blend_flag, solid_blend); } if (IsValid(pre.direction) && output.a < .025f) { vec2 offset = -s *direction_to_vec(pre.direction); output += Sprite(player, pre, pre_unit, subcell_pos + offset, frame, UnitTexture, selection_blend, selection_size, solid_blend_flag, solid_blend); } } if (output.a < .025f) { output = shadow; } return(output); }
protected color Presence(float player, data data, unit unit) { return((Something(data) && !IsStationary(data)) ? SolidColor(player, data, unit) : color.TransparentBlack); }
unit FragmentShader(VertexOut vertex, Field <unit> Unit, Field <data> Data, Field <vec4> Random, Field <magic> Magic) { unit unit_here = Unit[Here]; data data_here = Data[Here]; bool DoRaiseAnim = false; if (unit_here.anim == Anim.StartRaise) { DoRaiseAnim = true; } // Reset unit animation to stand/walk if (IsUnit(unit_here)) { unit_here.anim = _0; } if (Stayed(data_here) && unit_here.team != Team.None) // A unit has to be stationary to attack or be attacked. It must also have a team. { if (IsUnit(unit_here) && data_here.action == UnitAction.Attacking) { unit facing = Unit[dir_to_vec(data_here.direction)]; if (facing.team != unit_here.team && facing.team != Team.None) { unit_here.anim = Anim.Attack; } } // Check for being attacked data data_right = Data[RightOne], data_up = Data[UpOne], data_left = Data[LeftOne], data_down = Data[DownOne]; unit unit_right = Unit[RightOne], unit_up = Unit[UpOne], unit_left = Unit[LeftOne], unit_down = Unit[DownOne]; vec4 rnd = Random[Here]; if (unit_here.type != UnitType.DragonLord && rnd.x > .7f || rnd.x > .915f) { if (Something(data_right) && unit_right.team != unit_here.team && unit_right.team != Team.None && data_right.direction == Dir.Left && data_right.action == UnitAction.Attacking && data_right.change == Change.Stayed || Something(data_left) && unit_left.team != unit_here.team && unit_left.team != Team.None && data_left.direction == Dir.Right && data_left.action == UnitAction.Attacking && data_left.change == Change.Stayed || Something(data_up) && unit_up.team != unit_here.team && unit_up.team != Team.None && data_up.direction == Dir.Down && data_up.action == UnitAction.Attacking && data_up.change == Change.Stayed || Something(data_down) && unit_down.team != unit_here.team && unit_down.team != Team.None && data_down.direction == Dir.Up && data_down.action == UnitAction.Attacking && data_down.change == Change.Stayed) { if (IsBuilding(unit_here)) { unit_here.hit_count += _1; } else { unit_here.anim = Anim.Die; } } } } if (IsUnit(unit_here) && Magic[Here].kill == _true && !UnitIsFireImmune(unit_here)) { unit_here.anim = Anim.Die; } if (IsUnit(unit_here) && DoRaiseAnim) { unit_here.anim = Anim.DoRaise; } return(unit_here); }