Example #1
0
/**
**  Show unit animation.
**
**  @param unit  Unit of the animation.
**  @param anim  Animation script to handle.
**  @param scale scaling factor of the wait times in animation (8 means no scaling).
**
**  @return      The flags of the current script step.
*/
    public int UnitShowAnimationScaled(Unit unit, AnimationFram anim, int scale)
    {
        int move;

        // Changing animations
        if (unit.anim.CurrAnim != anim)
        {
            // Assert fails when transforming unit (upgrade-to).
            //  Assert(!unit->Anim.Unbreakable);
            unit.anim.Anim = unit.anim.CurrAnim = anim;
            unit.anim.Wait = 0;
        }

        // Currently waiting
        if (unit.anim.Wait > 0)
        {
            --unit.anim.Wait;
            if (unit.anim.Wait == 0)
            {
                // Advance to next frame
                unit.anim.Anim = unit.anim.Anim.next;
                if (unit.anim.Anim == null)
                {
                    unit.anim.Anim = unit.anim.CurrAnim;
                }
                else
                {
                    unit.anim.Wait = unit.anim.Anim.wait << scale >> 8;
                }
            }
            return(0);
        }

        move = 0;

        /*while (unit.anim.Wait==0)
         * {
         *  switch (unit->Anim.Anim->Type)
         *  {
         *      case AnimationFrame:
         *          unit->Frame = unit->Anim.Anim->D.Frame.Frame;
         *          UnitUpdateHeading(unit);
         *          break;
         *      case AnimationExactFrame:
         *          unit->Frame = unit->Anim.Anim->D.Frame.Frame;
         *          break;
         *
         *      case AnimationWait:
         *          unit->Anim.Wait = unit->Anim.Anim->D.Wait.Wait << scale >> 8;
         *          if (unit->Variable[SLOW_INDEX].Value)
         *          { // unit is slowed down
         *              unit->Anim.Wait <<= 1;
         *          }
         *          if (unit->Variable[HASTE_INDEX].Value && unit->Anim.Wait > 1)
         *          { // unit is accelerated
         *              unit->Anim.Wait >>= 1;
         *          }
         *          if (unit->Anim.Wait <= 0)
         *              unit->Anim.Wait = 1;
         *          break;
         *      case AnimationRandomWait:
         *          unit->Anim.Wait = unit->Anim.Anim->D.RandomWait.MinWait +
         *              SyncRand() % (unit->Anim.Anim->D.RandomWait.MaxWait - unit->Anim.Anim->D.RandomWait.MinWait + 1);
         *          break;
         *
         *      case AnimationSound:
         *          if (unit->IsVisible(ThisPlayer) || ReplayRevealMap)
         *          {
         *              PlayUnitSound(unit, unit->Anim.Anim->D.Sound.Sound);
         *          }
         *          break;
         *      case AnimationRandomSound:
         *          if (unit->IsVisible(ThisPlayer) || ReplayRevealMap)
         *          {
         *              int sound;
         *              sound = SyncRand() % unit->Anim.Anim->D.RandomSound.NumSounds;
         *              PlayUnitSound(unit, unit->Anim.Anim->D.RandomSound.Sound[sound]);
         *          }
         *          break;
         *
         *      case AnimationAttack:
         *          if (unit->Orders[0]->Action == UnitActionSpellCast)
         *          {
         *              if (unit->Orders[0]->Goal &&
         *                      !unit->Orders[0]->Goal->IsVisibleAsGoal(unit->Player))
         *              {
         *                  unit->ReCast = 0;
         *              }
         *              else
         *              {
         *                  unit->ReCast = SpellCast(unit, unit->Orders[0]->Arg1.Spell,
         *                      unit->Orders[0]->Goal, unit->Orders[0]->X, unit->Orders[0]->Y);
         *              }
         *          }
         *          else
         *          {
         *              FireMissile(unit);
         *          }
         *          unit->Variable[INVISIBLE_INDEX].Value = 0; // unit is invisible until attacks
         *          break;
         *
         *      case AnimationRotate:
         *          UnitRotate(unit, unit->Anim.Anim->D.Rotate.Rotate);
         *          break;
         *      case AnimationRandomRotate:
         *          if ((SyncRand() >> 8) & 1)
         *          {
         *              UnitRotate(unit, -unit->Anim.Anim->D.Rotate.Rotate);
         *          }
         *          else
         *          {
         *              UnitRotate(unit, unit->Anim.Anim->D.Rotate.Rotate);
         *          }
         *          break;
         *
         *      case AnimationMove:
         *          Assert(!move);
         *          move = unit->Anim.Anim->D.Move.Move;
         *          break;
         *
         *      case AnimationUnbreakable:
         *          Assert(unit->Anim.Unbreakable ^ unit->Anim.Anim->D.Unbreakable.Begin);
         *          unit->Anim.Unbreakable = unit->Anim.Anim->D.Unbreakable.Begin;
         *          break;
         *
         *      case AnimationNone:
         *      case AnimationLabel:
         *          break;
         *
         *      case AnimationGoto:
         *          unit->Anim.Anim = unit->Anim.Anim->D.Goto.Goto;
         *          break;
         *      case AnimationRandomGoto:
         *          if (SyncRand() % 100 < unit->Anim.Anim->D.RandomGoto.Random)
         *          {
         *              unit->Anim.Anim = unit->Anim.Anim->D.RandomGoto.Goto;
         *          }
         *          break;
         *  }
         *
         *  if (!unit->Anim.Wait)
         *  {
         *      // Advance to next frame
         *      unit->Anim.Anim = unit->Anim.Anim->Next;
         *      if (!unit->Anim.Anim)
         *      {
         *          unit->Anim.Anim = unit->Anim.CurrAnim;
         *      }
         *  }
         * }*/

        /* --unit->Anim.Wait;
         * if (!unit->Anim.Wait)
         * {
         *   // Advance to next frame
         *   unit->Anim.Anim = unit->Anim.Anim->Next;
         *   if (!unit->Anim.Anim)
         *   {
         *       unit->Anim.Anim = unit->Anim.CurrAnim;
         *   }
         * }*/
        return(move);
    }
Example #2
0
        public static void ControlableEntityAni(int Position, int ActualEndPos, List <String> Animation, int speed = 120)//240?
        {
            speed = Convert.ToInt32(speed * Globals.GameSpeed);
            //FIX CHANGE
            //meant for player and enemy
            if (Globals.AnimationRunning == false)
            {
                if (!(Position > 6 || Position < 1))
                {
                    Globals.AnimationRunning = true;

                    //note the animtaion starts from the ground
                    //all animations are square

                    //Work out Max area animation happens so you can just render that area
                    //Max row above the surface of the ground
                    int RowFinal = Globals.GroundInGameY - 1;
                    //Starting row of animation
                    int RowInitial = RowFinal;
                    //Starting Column of animation
                    int ColumnInitial = ((Position - 1) * 5);
                    //Max Column
                    int ColumnFinal = ColumnInitial;
                    foreach (var AnimationFrames in Animation)
                    {
                        //checks for the max height of animation
                        RowInitial = Math.Min(RowInitial, Globals.GroundInGameY - AnimationFrames.Count(f => f == '%'));
                        //checks for the max width of animation
                        ColumnFinal = Math.Max(ColumnFinal, ColumnInitial + ((AnimationFrames.Length - AnimationFrames.Count(f => f == '%')) / AnimationFrames.Count(f => f == '%')));
                    }
                    //IDK why probs 0 index
                    ColumnFinal--;
                    if (ColumnFinal >= Globals.GSW)
                    {
                        ColumnFinal = Globals.GSW - 1;
                    }
                    //System.Diagnostics.Debug.WriteLine($"{RowInitial},{ColumnInitial},{RowFinal},{ColumnFinal}");

                    //set up the Location of the Animation to change the screen list
                    List <List <int> > Location = new List <List <int> >()
                    {
                    };
                    foreach (var AnimationFram in Animation)
                    {
                        List <int> FrameCoords = new List <int>()
                        {
                        };
                        //row
                        FrameCoords.Add(Globals.GroundInGameY - AnimationFram.Count(f => f == '%'));
                        //Column
                        FrameCoords.Add((Position - 1) * 5);
                        Location.Add(FrameCoords);
                    }


                    //Runs for each Frame of animation ------------add time for each animation
                    for (int Frame = 0; Frame < Animation.Count; Frame++)
                    {
                        //Layer on animation
                        ChangeScreen(Convert.ToInt32(Location[Frame][0]), Convert.ToInt32(Location[Frame][1]), Animation[Frame]);

                        //Render animation
                        RenderScreen($"{RowInitial},{ColumnInitial},{RowFinal},{ColumnFinal}");
                        //RenderScreen("all");
                        //wait to next frame
                        //System.Diagnostics.Debug.WriteLine($"Completed Frame {Frame}");
                        Thread.Sleep(speed);
                    }
                    ResetArea(Position, ActualEndPos, RowInitial, ColumnInitial, RowFinal, ColumnFinal);
                    RenderScreen($"{RowInitial},{ColumnInitial},{RowFinal},{ColumnFinal}");
                    EndAni();
                }
                else
                {
                    //catches bugs
                    MakeErrorMessage("Position should be from 1-6 on screen");
                    //maybe check for next positon on map??????????????????????
                }
            }
            else
            {
                //catches bugs
                MakeErrorMessage("Couldn't run animation as one already runnign");
            }
        }
Example #3
0
 /**
 **  Show unit animation.
 **
 **  @param unit  Unit of the animation.
 **  @param anim  Animation script to handle.
 **
 **  @return      The flags of the current script step.
 */
 public int UnitShowAnimation(Unit unit, AnimationFram anim)
 {
     return(UnitShowAnimationScaled(unit, anim, 8));
 }