三国群英2吧 关注:45,920贴子:1,015,475

回复:【脚本基础教程】第六章:异步与回调(武将技:毒箭)

只看楼主收藏回复

问个问题,缩放这个数值是怎么回事啊,你的文件拆分出单个原版技能中这些数值会出错,不明白。能给个答案不。


31楼2020-03-23 23:15
收起回复
    #define OAF_WAIT 1
    #define OAF_WALK 2
    #define OAF_ATTACK 4
    #define OAF_DEFENSE 8
    #define OAF_PAIN 0x10
    #define OAF_DEATH 0x20
    #define OAF_WIN 0x40
    #define OAF_ATTACK2 0x800
    #define OAF_ATTACK3 0x1000
    #define OAF_ATTACK4 0x2000
    #define OAF_ATTACK5 0x4000
    #define OAF_SPELL1 0x8000
    #define OAF_SPELL2 0x10000
    #define OAF_SHOT1 0x20000
    #define OAF_SHOT2 0x40000
    #define OAF_SHOT3 0x80000
    #define OAF_ATTACK6 0x100000
    #define OAF_ATTACK7 0x200000
    #define OAF_ATTACK8 0x400000
    #define OF_MAN 0x00000001
    #define OF_MISSILE 0x00000002
    #define OF_BACKGROUND 0x00000004
    #define OF_CAVALRY 0x00000008
    #define OF_BLOCKMAN 0x00000010
    #define OF_BLOCKMISSILE 0x00000020
    #define OF_BIGSHAPE 0x00000040
    #define OF_TRIGGERMAN 0x00000100
    #define OF_TRIGGERMISSILE 0x00000200
    #define OF_NOGRAVITY 0x00010000
    #define OF_NONSYNCHRONISM 0x00020000
    #define OF_MIXER 0x00040000
    #define OF_WHITELIGHT 0x00080000
    #define OF_DARKLIGHT 0x00100000
    #define OF_TARGET 0x00200000
    #define OF_BOMB 0x00400000
    #define OF_ENEMYGENERAL 0x01000000
    #define OF_ENEMYFORCE 0x02000000
    #define OF_ATTACKENEMY 0x03000000
    #define OF_MYGENERAL 0x04000000
    #define OF_MYFORCE 0x08000000
    #define OF_ATTACKMY 0x0c000000
    #define OF_ATTACKALL 0x0F000000
    // 召唤铁锅
    void CastFail(int a0, int a1) {
    int v1;
    v1 = CreateObjectByReference(a0, 10017, a1, 256);
    SetObjectFlags(v1, OF_MYGENERAL);
    SetCallbackProcedure(v1, 1000);
    SetObjectAnimate(a0, OAF_SPELL1);
    SetOverwhelming(a0, 0);
    Delay(60);
    return;
    }
    void DelayAmbientSound(string a0, int a1, int a2) {
    SetGlobal(1, 1);
    PlaySound1(a0, a1);
    Delay(a2);
    SetGlobal(1, 0);
    return;
    }
    // 摄像机移过去
    void MoveCamera(int a0, int a1, int a2) {
    int v1;
    int v2;
    int v3;
    int v4;
    int v5;
    v2 = (GetCameraX() * 1000);
    v3 = (GetCameraY() * 1000);
    a0 = (a0 * 1000);
    a1 = (a1 * 1000);
    v4 = (a0 - v2);
    v4 = (v4 / a2);
    v5 = (a1 - v3);
    v5 = (v5 / a2);
    v1 = a2;
    while ((v1 > 0)) {
    v2 = (v2 + v4);
    v3 = (v3 + v5);
    SetViewCamera((v2 / 1000), (v3 / 1000));
    if (((v2 / 100) == (a0 / 100)) && ((v3 / 100) == (a1 / 100))) {
    v1 = 1;
    }
    v1--;
    Delay(1);
    }
    return;
    }
    // 让天空变黑
    void DownBrightness(int a0, int a1) {
    int v1;
    v1 = GetBackgroundBrightness();
    while ((v1 > a0)) {
    Delay(a1);
    v1--;
    SetBackgroundBrightness(v1);
    }
    SetBackgroundBrightness(16);
    LockBrightness(a0);
    SetGlobal(2, a0);
    return;
    }
    // 天空渐渐变白
    void RaiseBrightness(int a0, int a1) {
    int v1;
    UnlockBrightness();
    v1 = GetGlobal(2);
    SetBackgroundBrightness(v1);
    while ((v1 < a0)) {
    Delay(a1);
    v1++;
    SetBackgroundBrightness(v1);
    }
    SetBackgroundBrightness(a0);
    return;
    }
    // 镜头锁定物件
    void LockCameraOnObject(int object, int yOffset) {
    int dir = GetObjectDir(object);
    while(IsObjectExist(object)) {
    // 得到欲锁定物件和摄像机自身的x坐标
    int objectX = GetObjectScreenX(object);
    int cameraX = GetCameraX();
    // 检查边界:如果飞出战场,则直接退出
    if (cameraX < 0 || cameraX >= GetBattleWidthInScreenX())
    break;
    // 检查物件与摄像机的距离
    int dx = objectX - cameraX;
    // 如果物件正在飞离摄像机,则移动摄像机,否则什么也不做
    if ((dir == 0 && dx > 0) || (dir == 128 && dx < 0))
    SetCameraByReference(object, 0, yOffset);
    Delay(1);
    }
    }
    void SmallFireBall(int a0, int a1, int a2, int a3) {
    int v1;
    int v2;
    PlaySound(a1, "hit01", 255);
    v2 = 0;
    while ((v2 < a2)) {
    v1 = CreateObjectByReference(a1, 10003, Rand(0, 255), a3);
    SetObjectScale(v1, 12288, 12288);
    SetObjectSpeed_Cylind(v1, Rand(4, 12), Rand((-2), 8));
    SetObjectFriction1(v1, 8192);
    SetObjectFadeOut(v1, 32, 1);
    SetObjectScaleShrink(v1, 256);
    v2++;
    }
    return;
    }
    void SmallFireBall2(int a0, int a1, int a2, int a3) {
    int v1;
    int v2;
    int v3;
    PlaySound(a1, "hit01", 255);
    v2 = 0;
    while ((v2 < a2)) {
    v1 = CreateObjectByReference(a1, 10003, Rand(0, 255), a3);
    v3 = Rand(8192, 12288);
    SetObjectScale(v1, v3, v3);
    SetObjectSpeed_Cylind(v1, Rand(3, 7), Rand((-1), 5));
    SetObjectFriction1(v1, 8192);
    SetObjectFadeOut(v1, 32, 1);
    SetObjectScaleShrink(v1, 256);
    v2++;
    }
    return;
    }
    void SmallFireBall3(int a0, int a1, int a2, int a3) {
    int v1;
    int v2;
    PlaySound(a1, "hit01", 255);
    v2 = 0;
    while ((v2 < a2)) {
    v1 = CreateObjectByReference(a1, 10013, Rand(0, 255), a3);
    SetObjectScale(v1, 12288, 12288);
    SetObjectSpeed_Cylind(v1, Rand(4, 12), Rand((-2), 8));
    SetObjectFriction1(v1, 8192);
    SetObjectFadeOut(v1, 32, 1);
    SetObjectScaleShrink(v1, 256);
    v2++;
    }
    return;
    }
    void SmallFireBall4(int a0, int a1, int a2, int a3) {
    int v1;
    int v2;
    PlaySound(a1, "hit01", 255);
    v2 = 0;
    while ((v2 < a2)) {
    v1 = CreateObjectByReference(a1, 10014, Rand(0, 255), a3);
    SetObjectScale(v1, 12288, 12288);
    SetObjectSpeed_Cylind(v1, Rand(4, 12), Rand((-2), 8));
    SetObjectFriction1(v1, 8192);
    SetObjectFadeOut(v1, 32, 1);
    SetObjectScaleShrink(v1, 256);
    v2++;
    }
    return;
    }
    void Hurt(int a0, int a1, int a2) {
    if (!((a1 == intvAttackerMajor) || (a1 == intvDefenderMajor))) {
    PlaySound(a1, "Hit01", 255);
    } else {
    ClearObjectFlags(a0, (OF_MYGENERAL + OF_ENEMYGENERAL));
    if (a2 <= 0) {
    return;
    }
    DoHarmToMajor(a1, 0, a2);
    }
    return;
    }
    void HitGeneral(int a0, int a1, int a2, int a3, int a4, int a5) {
    int v1;
    int v2;
    int v3;
    int v4;
    int v5;
    if (!GetGlobal(3)) {
    SetGlobal(3, 1);
    v2 = CreateObjectByReference(a1, 2501, 0, 0);
    v3 = GetObjectScreenX(a1);
    v4 = GetObjectScreenY(a1);
    SetObjectCoordinate(v2, v3, v4, a4);
    v1 = 0;
    while ((v1 < 7)) {
    v5 = CreateObjectByReference(v2, a2, 0, 0);
    SetObjectScale(v5, 49152, 49152);
    MoveObject(v5, Rand((-48), 48), 0, Rand((-48), 48));
    switch (a3) {
    case 1:
    asynccall SmallFireBall(a0, a1, 8, a4);
    break;
    case 2:
    asynccall SmallFireBall3(a0, a1, 8, a4);
    break;
    case 3:
    asynccall SmallFireBall4(a0, a1, 8, a4);
    break;
    break;
    }
    Delay(Rand(3, 7));
    v1++;
    }
    FreeObject(v2);
    Delay(a5);
    SetGlobal(3, 0);
    return;
    } else {
    return;
    }
    }
    int GetGeneralWidth() {
    int v1;
    v1 = (GetObjectScreenX(intvAttackerMajor) - GetObjectScreenX(intvDefenderMajor));
    if (v1 < 0) {
    v1 = (-v1);
    }
    return v1;
    }


    32楼2020-03-23 23:47
    回复
      2026-01-16 08:20:36
      广告
      不感兴趣
      开通SVIP免广告
      #include "magic3.cpp"
      void CreateIceShatter(int a0, int a1, int a2, int a3) {
      int v1;
      Delay(Rand(0, 3));
      v1 = CreateObjectByReference(a0, Rand(32003, 32005), 0, 0);
      SetObjectScale(v1, Rand(12288, 20480), Rand(12288, 20480));
      SetCoordinateByReference_Cylind(v1, a0, Rand(128, 255), 30, a1);
      SetObjectSpeed_Sphere(v1, 0, a2, a3);
      Delay((a1 / 20));
      SetObjectFadeOut(v1, 8, 1);
      return;
      }
      void CreateFogSpeed(int a0, int a1, int a2, int a3, int a4) {
      int v1;
      Delay(Rand(1, 6));
      v1 = CreateObjectRaw(a0, a1, 0, 0, 32001);
      SetObjectScale(v1, 32768, 32768);
      SetObjectSpeed_Sphere(v1, 0, a2, a3);
      SetObjectScaleShrink(v1, (-1024));
      Delay(a4);
      SetObjectFadeOut(v1, 16, 1);
      return;
      }
      void LockTargetXY(int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) {
      int v1;
      Delay(Rand(a6, a7));
      v1 = CreateObjectByReference(intvAttackerMajor, a2, a3, 0);
      SetObjectCoordinate(v1, a0, a1, 0);
      SetObjectFlags(v1, a8);
      SetCallbackProcedure(v1, a5);
      Delay(a4);
      SetObjectFadeOut(v1, 16, 1);
      return;
      }
      void CreateIce(int a0, int a1, int a2, int a3, int a4, int a5) {
      int v1;
      int v2;
      Delay(a4);
      v1 = CreateObjectRaw(a0, a1, 0, 128, 32002);
      SetObjectScale(v1, a2, a3);
      if (a5) {
      SetObjectFlags(v1, (OF_ENEMYFORCE + OF_ENEMYGENERAL));
      SetCallbackProcedure(v1, 22001);
      }
      asynccall CreateFogSpeed((a0 + Rand((-2), 2)), (a1 + Rand(4, 12)), Rand(48, 60), Rand(2, 4), Rand(12, 20));
      asynccall CreateFogSpeed(((a0 + 32) + Rand((-2), 2)), (a1 + Rand(4, 12)), Rand(48, 64), Rand(2, 4), Rand(12, 20));
      asynccall CreateFogSpeed(((a0 - 32) + Rand((-2), 2)), (a1 + Rand(4, 12)), Rand(48, 64), Rand(2, 4), Rand(12, 20));
      v2 = 0;
      while ((v2 < 8)) {
      asynccall CreateIceShatter(v1, (((a3 * (v2 + 1)) / 65536) * 20), Rand(26, 36), Rand(2, 5));
      Delay(1);
      MoveObject(v1, 2, 0, 0);
      v2++;
      }
      asynccall LockTargetXY((a0 + 54), a1, 2501, 0, 4, 22001, 0, 0, OF_ENEMYFORCE);
      asynccall LockTargetXY((a0 - 54), a1, 2501, 0, 4, 22001, 0, 0, OF_ENEMYFORCE);
      asynccall LockTargetXY(a0, (a1 + 45), 2501, 0, 4, 22001, 0, 0, OF_ENEMYFORCE);
      asynccall LockTargetXY(a0, (a1 + 45), 2501, 0, 4, 22001, 0, 0, OF_ENEMYFORCE);
      asynccall LockTargetXY((a0 + 54), (a1 + 45), 2501, 0, 4, 22001, 0, 0, OF_ENEMYFORCE);
      asynccall LockTargetXY((a0 + 54), (a1 - 45), 2501, 0, 4, 22001, 0, 0, OF_ENEMYFORCE);
      asynccall LockTargetXY((a0 - 54), (a1 + 45), 2501, 0, 4, 22001, 0, 0, OF_ENEMYFORCE);
      asynccall LockTargetXY((a0 - 54), (a1 - 45), 2501, 0, 4, 22001, 0, 0, OF_ENEMYFORCE);
      Delay(35);
      SetObjectFadeOut(v1, 16, 1);
      return;
      }
      void Ice(int a0) {
      int v1;
      int v2;
      int v3;
      int v4;
      int v5;
      int v6;
      int v7;
      int v8;
      int v9;
      SetGlobal(31, 1);
      BatchLoadShape("magic\\000\\*");
      BatchLoadShape("magic\\022\\*");
      DisablePlayMagic();
      DownBrightness(12, 5);
      SetOverwhelming(intvAttackerMajor, 1);
      v1 = GetObjectScreenX(intvAttackerMajor);
      v2 = GetObjectScreenY(intvAttackerMajor);
      SetViewCamera(v1, (v2 - 120));
      AddAttackCounter(intvAttackerMajor, 2);
      Delay(15);
      SetObjectAnimate(intvAttackerMajor, OAF_SPELL1);
      Delay(20);
      SetOverwhelming(intvAttackerMajor, 0);
      v4 = 0;
      while ((v4 < (a0 + 1))) {
      if (!(v4 == a0)) {
      v3 = GetRandomSoldierHandleFromAlive((intvIsLeft ^ 1));
      } else {
      v3 = GetMostImportantSoldier((intvIsLeft ^ 1));
      }
      if (v3 == 0) {
      v3 = intvDefenderMajor;
      }
      v1 = GetObjectScreenX(v3);
      v2 = GetObjectScreenY(v3);
      MoveCamera(v1, (v2 - 140), 20);
      PlaySound1("m022snd01", 180);
      asynccall CreateIce(v1, v2, 65536, 65536, 0, 1);
      asynccall CreateIce((v1 + 44), (v2 + 12), 49152, 45056, Rand(3, 4), 0);
      asynccall CreateIce((v1 - 44), (v2 + 10), 53248, 49152, Rand(4, 5), 0);
      asynccall CreateIce((v1 + Rand((-4), 4)), (v2 - 16), 49152, 36864, Rand(6, 7), 0);
      Delay(Rand(4, 12));
      v5 = (v1 + Rand(180, 260));
      if (!Rand(0, 1)) {
      v6 = (v2 - Rand(180, 230));
      } else {
      v6 = (v2 + Rand(180, 240));
      }
      v8 = ScreenXToBattleX(v5);
      v9 = ScreenXToBattleX(v6);
      v7 = GetSoldierCountInRect((intvIsLeft ^ 1), v8, v9, 5, 4);
      if (v7 > 0) {
      v3 = GetNthSoldierInRect((intvIsLeft ^ 1), v8, v9, 5, 4, Rand(0, (v7 - 1)));
      if (v3 != intvDefenderMajor) {
      v5 = GetObjectScreenX(v3);
      v6 = GetObjectScreenY(v3);
      }
      }
      PlaySound1("m022snd01", 200);
      asynccall CreateIce(v5, v6, 65536, 65536, 0, 1);
      asynccall CreateIce((v5 + 44), (v6 + 12), 49152, 45056, Rand(3, 4), 0);
      asynccall CreateIce((v5 - 44), (v6 + 10), 53248, 49152, Rand(4, 5), 0);
      asynccall CreateIce((v5 + Rand((-4), 4)), (v6 - 16), 49152, 36864, Rand(6, 7), 0);
      Delay(Rand(4, 12));
      v5 = (v1 - Rand(170, 260));
      if (!Rand(0, 1)) {
      v6 = (v2 - Rand(190, 240));
      } else {
      v6 = (v2 + Rand(190, 230));
      }
      v8 = ScreenXToBattleX(v5);
      v9 = ScreenXToBattleX(v6);
      v7 = GetSoldierCountInRect((intvIsLeft ^ 1), v8, v9, 5, 4);
      if (v7 > 0) {
      v3 = GetNthSoldierInRect((intvIsLeft ^ 1), v8, v9, 5, 4, Rand(0, (v7 - 1)));
      if (v3 != intvDefenderMajor) {
      v5 = GetObjectScreenX(v3);
      v6 = GetObjectScreenY(v3);
      }
      }
      PlaySound1("m022snd01", 220);
      asynccall CreateIce(v5, v6, 65536, 65536, 0, 1);
      asynccall CreateIce((v5 + 44), (v6 + 12), 49152, 45056, Rand(3, 4), 0);
      asynccall CreateIce((v5 - 44), (v6 + 10), 53248, 49152, Rand(4, 5), 0);
      asynccall CreateIce((v5 + Rand((-4), 4)), (v6 - 16), 49152, 36864, Rand(6, 7), 0);
      Delay(30);
      v4++;
      }
      Wait("CreateIce");
      Delay(60);
      RaiseBrightness(16, 5);
      EnablePlayMagic();
      return;
      }
      void Magic114() callsign 802 {
      ice(0);
      return;
      }


      33楼2020-03-23 23:47
      回复
        @ezhou111
        明白了,不是编译器出错。
        根本原因是一开始define的时候,对OAF_ATTACK的define,必须在OAF_ATTACK8的后面。否则,编译器先看到这个:
        #define OAF_ATTACK 4
        于是所有OAF_ATTACK会被替换成4。因为这是一次粗暴的字符串查找替换过程(而不是token查找替换过程),后面的:
        #define OAF_ATTACK8 0x400000
        会变成:
        #define 48 0x400000
        于是出错的SetObjectScale就会从:
        SetObjectScale(v1, Rand(12288, 20480), Rand(12288, 20480));
        变成:
        SetObjectScale(v1, Rand(12288, 200x4000000), Rand(12288, 200x4000000));
        两个48被替换掉了。
        如果注意到的话,magic cpp里OAF_ATTACK的定义是在所有OAF_ATTACK2-OAF_ATTACK8的后面的,事实上就是因为这个问题。改成下面这样就好了。
        #define OAF_WAIT 1
        #define OAF_WALK 2
        #define OAF_DEFENSE 8
        #define OAF_PAIN 0x10
        #define OAF_DEATH 0x20
        #define OAF_WIN 0x40
        #define OAF_ATTACK2 0x800
        #define OAF_ATTACK3 0x1000
        #define OAF_ATTACK4 0x2000
        #define OAF_ATTACK5 0x4000
        #define OAF_SPELL1 0x8000
        #define OAF_SPELL2 0x10000
        #define OAF_SHOT1 0x20000
        #define OAF_SHOT2 0x40000
        #define OAF_SHOT3 0x80000
        #define OAF_ATTACK6 0x100000
        #define OAF_ATTACK7 0x200000
        #define OAF_ATTACK8 0x400000
        #define OAF_ATTACK 4


        IP属地:中国香港34楼2020-03-24 00:19
        收起回复
          居然已经到6了……赶紧板凳学习


          IP属地:广东来自iPhone客户端35楼2020-04-04 22:38
          回复