XEricSin 发表于 2016-4-29 19:31:53

新增城镇的脚本副简单讲解

本帖最后由 XEricSin 于 2020-2-10 13:02 编辑

这句话是最新加的,这个方法是在进城的一瞬间动态的改变一个城,比如把一部分元素城变成新城,从而实现多城共存。这个方法很老了,有兴趣可以深挖。
本脚本参考了龙城的方法,在不替换原有城镇的基础上添加新的城镇。可是,我发现龙城切换城镇时使用的内存函数老是导致游戏崩溃,因此,我避开了内存函数,转而通过城镇的列表编号来确定进的是哪座城。此脚本稍加修改就可以支持多个新城(当然会有些限制)。

本来配合新生物插件可以真正实现新城新生物,可是此插件还不完善。所以这里就以添加原版生物到新城为例子了。

第一部分
**游戏开始时替换城镇为新城
**在每座新城的名字中增加两个字母来标记是新城

!#VRz709:S^ZL^;
!#IF:V413/1; flag on TM1 to setup ZL
!#IF:V414/0; flag on TM1 to hire specific new hero
!#VRv5250:S0; new male heros in map, bit mask
!#VRv5251:S0; new female heros in map, bit mask
!#TM1:S1/164/1/255;    triggers every color every day

!?PI;
!!VRz2:Sz310036; //initial prompt
!!IF:M1/z2;
!!UN:P169/0; disable renaming town
!!UN:U98/-1/?y1;
!!VRv1:C-1/-1/-1; //for relative obj searching method
!!DO6152/1/y1/1&y1>0:P;

**转换起始城和部分野城为逐鹿城*
*function to convert towns to ZL towns
!?FU6152;
!!VRy-1:S12;y-1=chace of convert (0-100)
!!UN:U98/-1/-1/1; put coordinates of next type x1/x2 object --> (v1,2,3)
!!CA1:O?y2; get Owner of town
!!if&y2=-1:; no owner
!!VRy10:S0 R100;
!!FU&y10>y-1:E;
!!el:;
!!OW:Iy2/?y3; ai?
!!FU&y3=1:E; //if town owner is ai then end
!!en:;
*!CA1:T1; //chnge type to Rampart
!!CA1:B3/7; //fort built? in flag 1
!!CA1&1:I1; //castle look(the old pcx need to be replaced)
!!CA1&-1:I2;//no-castle look(the old pcx need to be replaced)
!!CA1:N?z3; get town Name
!!VRz2:S^%Z709 %Z3^; //add ZL to before town name
!!CA1:Nz2; set town Name
********************************************************************************


第二部分**每次进城时,更改城镇相应巢穴来模拟新城


**进入城镇界面有4个途径
*1:大地图点击城堡 2:大地图右边的城镇列表 3:英雄大地图进城
*4:进入城镇界面后,通过右下角的城镇列表切换城镇 (这个是重点和难点)(其实还有第五种,估计很少人用过,反正我是没用过)

注意难点来了。
前三种进城方式很直接,都有直接的erm检测进的是不是新城(名字是不是包含标记)
但是,第四种进城方式很特殊,没有直接的erm检测切换到哪座城。所以,龙城是用的一个内存函数。可是,我发现这个函数老是导致游戏崩溃,因此,我避开了内存函数,转而通过城镇在列表中的位置
和玩家鼠标点击的位置和次数来跟踪,到底是点的哪座城。上面的v5256-v5259就是为此设计的。
FU6154则是根据进城时的不同情况赋予v5256-v5259的初始值。

**英雄进入壁垒、逐鹿城时,更改建筑和兵种图片**
!?OB98;
!!FU6154:P0; //initialise the index of 3 towns in town screen

!!CA998:N?z3 T?y3; get Town Name/type
!!VRz2:M1/z3/0/2; get substring "ZL" if Town is a ZL

!!FU6150&z2=z709:P0/y3; //change structures
!!FU6151&z2<>z709:P0/y3; //restore structures

!!CA998:O?y1; get town owner
!!OW:C?y2;    get hero owner
!!if&y1<>y2:;diff owner
!!FU9555&z2=z709:P1/171; change tower to sword master
!!if&z2<>z709:; change tower to original
    !!VRy4:Sy3*14;
    !!VRy4|y3=0/y3=3/y3=7:+2;
    !!VRy4|y3=1/y3=6:+4;
    !!VRy4|y3=2/y3=5:+6;
    !!VRy4&y3=4:+8;
    !!VRy4&y3=8:+3;
    !!FU9555:Py3/y4;
!!en:;
!!el:;same owner
!!FU6157&z2=z709:P;prompt to change hero提示更换英雄
!!en:;


**左键点击主界面城镇列表并进城时,更改建筑和生物图片**
*LMB on Town List slot in Adventure Screen, change dwellings
!?CM5;
!!CM:I?y1 S?y9;
!!FU&y9<>12:E; not left push
!!FU|y1<32/y1>36:E; not town slot

!!VRy2:Sy1-32; convert to slot # 0-4
!!OW:N-1/y2/?y3; y3=town #
!!CA0/y3:N?z3 T?y4; get Town name/type

!!OW:N-1/?y10;
!!FU&y10=-1:E;
!!CA0/y10:N?z10; //name of active town
!!FU&z10<>z3:E;//target town is not active

!!FU6154:P1; //initialise the index of 3 towns in town screen

!!VRz2:M1/z3/0/2; get substring "ZL" if Town is a ZL

!!FU6150&z2=z709:P0/y4;
!!FU6151&z2<>z709:P0/y4;
********************************************************************************


**左键点击地图上城镇并进城时,更改建筑和生物图片*
*LMB on Town in Big Adventure Map, change dwellings
!?CM5;
!!CM:I?y1 S?y9;
!!FU&y9<>12:E; not left push
!!FU&y1<>37:E; not big adv map
!!CM:P?v2/?v3/?v4;
!!OB2:T?y2;
!!FU&y2<>98:E; not town
!!CA2:N?z3 T?y3; //get target town name and type
*!FU&y3<>1:E; not rampart town

!!OW:N-1/?y10;//current active town
!!FU&y10=-1:E;
!!CA0/y10:N?z10; //name of active town
!!FU&z10<>z3:E;//target town is not active

!!FU6154:P1; //initialise the index of 3 towns in town screen

!!VRz2:M1/z3/0/2; get substring "ZL" if Town is a ZL

!!FU6150&z2=z709:P0/y3;
!!FU6151&z2<>z709:P0/y3;
********************************************************************************


**左键点击城镇界面中的城镇列表并进城时,更改建筑和生物图片*
* LMB push in Town Screen, on Town slot in Town List, change dwellings
!?CM1;
!!CM:I?y1 S?y2;
!!FU|y1<155/y1>157:E;//only for town slots
!!FU&y2<>12:E; //Left mouse click sub type is 12
!!VRv5256&y1=155:Sv5257; //v5256 records town index of next town screen
!!VRv5256&y1=156:Sv5258;
!!VRv5256&y1=157:Sv5259;

!!OW:W-1/v5256/?y3; //town number for next town screen
!!CA0/y3:T?y4 N?z3; //type and name of town for next town screen
!!VRz2:M1/z3/0/2; get substring "ZL" if Town is a ZL

!!FU6150&z2=z709:P0/y4; //target is ZL then redirect structures
!!FU6151&z2<>z709:P0/y4; //target is not ZL then undo redirect structures
********************************************************************************


**左键点击城镇界面中的城镇列表的上下滑动箭头时,更新当前显示的3个城的城镇列表编号**
!?CM1&415; LMB push in Town Screen, on up and down button for towns scroll
!!CM:I?y1 S?y2;
! !IF:M^%Y1 %Y2^;
!!FU&y2<>13:E; //Left mouse click sub type for scroll button is 13

!!if&y1=152:; //click up
!!FU|v5256=0/v5256=1:E;//no towns above, ignore this click
!!VRv5257:Cd-1/d-1/d-1;//reduce corresponding town index by 1
!!en:;

!!if&y1=153:; //click down
!!OW:W-1/?y3; //number of towns
!!VRy4:Sy3-2;
!!FU&v5256>=y4:E;//no towns below, ignore this click
!!VRv5257:Cd1/d1/d1;//increase corresponding town index by 1
!!en:;
*****************************************************


**设置城镇巢穴为逐鹿城巢穴**change dwellings to ZL
!?FU6150; x1=dummy x2=town type
!!UN:Tx2/0/0/?y1;
!!FU&y1=138:E; simple check whether town is normal

!!UN:Tx2/0/0/138;
!!UN:Tx2/0/1/139;
!!UN:Tx2/1/0/140;
!!UN:Tx2/1/1/142;
!!UN:Tx2/2/0/144;
!!UN:Tx2/2/1/194;
!!UN:Tx2/3/0/170;
!!UN:Tx2/3/1/171;
!!UN:Tx2/4/0/167;
!!UN:Tx2/4/1/166;
!!UN:Tx2/5/0/164;
!!UN:Tx2/5/1/165;
!!UN:Tx2/6/0/168;
!!UN:Tx2/6/1/169;
!!MA:O138/x2 O139/x2 O140/x2 O142/x2 O144/x2 O194/x2;
!!MA:O170/x2 O171/x2 O167/x2 O166/x2 O164/x2 O165/x2;
!!MA:O168/x2 O169/x2 O195/x2 O192/x2;

**图片也是可以改的,可以参考龙城中的相关部分
* REDIRECT BUILDING PICTURES
! !SN:L^Era.dll^/?y1; y1=handle
! !SN:Ay1/^RedirectFile^/?y2; y2=FU address
! !SN:Ey2/1/^TBRMDW_0.def^/^TBRMDW_4.def^;
。。。
! !IF:V412/1; prevent redirected redirects
********************************************************************************



**还原普通城巢穴**restore normal Town Cr's
!?FU6151; x1=dummy x2=town type
!!UN:Tx2/0/0/?y1;
!!FU&y1<>138:E; simple check whether town is ZL

!!if&x2<8:;
!!VRy1:S14 *x2;
!!UN:Tx2/0/0/y1;
!!VRy1:+1;
!!UN:Tx2/0/1/y1;
!!VRy1:+1;
!!UN:Tx2/1/0/y1;
!!VRy1:+1;
!!UN:Tx2/1/1/y1;
!!VRy1:+1;
!!UN:Tx2/2/0/y1;
!!VRy1:+1;
!!UN:Tx2/2/1/y1;
!!VRy1:+1;
!!UN:Tx2/3/0/y1;
!!VRy1:+1;
!!UN:Tx2/3/1/y1;
!!VRy1:+1;
!!UN:Tx2/4/0/y1;
!!VRy1:+1;
!!UN:Tx2/4/1/y1;
!!VRy1:+1;
!!UN:Tx2/5/0/y1;
!!VRy1:+1;
!!UN:Tx2/5/1/y1;
!!VRy1:+1;
!!UN:Tx2/6/0/y1;
!!VRy1:+1;
!!UN:Tx2/6/1/y1;
!!el:; element town
!!UN:Tx2/0/0/118;
!!UN:Tx2/0/1/119;
!!UN:Tx2/1/0/112;
!!UN:Tx2/1/1/127;
!!UN:Tx2/2/0/115;
!!UN:Tx2/2/1/123;
!!UN:Tx2/3/0/114;
!!UN:Tx2/3/1/129;
!!UN:Tx2/4/0/113;
!!UN:Tx2/4/1/125;
!!UN:Tx2/5/0/120;
!!UN:Tx2/5/1/121;
!!UN:Tx2/6/0/130;
!!UN:Tx2/6/1/131;
!!en:;


**如果建筑图片也参考龙城改了,就要在还原城镇是一并还原
* undo all redirects
! !SN:L^Era.dll^/?y1; y1=handle
! !SN:Ay1/^RedirectFile^/?y2; y2=FU address
! !SN:Ey2/1/^^/^^;
! !IF:V412/0; unflag redirects
********************************************************************************

**进入城镇界面时,记录当前界面的3个城镇列表编号**
**when entering a town screen, a small town list will be at the bottom right corner.
**record the indexes of these towns in player's overall town list as v5257 v5258 v5259.
**v5256 is the index of the town that gives the current town screen
!?FU6154;
!!if&x1=0:; //triggered by hero
!!CA998:U?y1; town number in map
!!en:;
!!if&x1=1:; //triggered by click
!!OW:N-1/?y1; town number in map
!!en:;

!!OW:W-1/?y3;total number of towns owned
!!VRy-3:Sy3-1;max town list index
!!VRy2:S-1;default townnot in player's list
!!DO6155/0/y-3/1:Py1/?y2; //search player's town list for town number in map

**y2=index of this town in player's town list
!!VRy2&y2=-1/y3=0:S0; //entering new town when no towns
!!VRy2&y2=-1/y3=1:S1; //entering new town when having 1 town
!!VRy2&y2=-1/y3>1:S-2; //entering new town when 2 or more towns

!!if&y2=0:;entering 1st town or entering new town when no towns
!!VRv5256:S0; curret town index in player's list
!!VRv5257:C0/1/2; index of 3 towns shown in town screen list
!!FU:E;
!!en:;

!!if&y2=1:;entering 2nd town or entering new town when having 1 town
!!VRv5256:S1; curret town index in player's list
!!VRv5257:C0/1/2; index of 3 towns shown in town screen list
!!FU:E;
!!en:;

!!VRy4:Sy3-1; //num of towns -1
!!VRy5:Sy3-2; //num of towns -2
!!VRy6:Sy3-3; //num of towns -3
!!VRy7:Sy2-1; //index of towns -1
!!VRy8:Sy2+1; //index of towns +1

!!if&y2>1/y2<y5:;
!!VRv5256:Sy2; curret town index in player's list
!!VRv5257:Cy7/y2/y8; index of 3 towns shown in town screen list
!!FU:E;
!!en:;

!!if&y2=y5:;
!!VRv5256:Sy5; curret town index in player's list
!!VRv5257:Cy6/y5/y4; index of 3 towns shown in town screen list
!!FU:E;
!!en:;

!!if&y2=y4:;
!!VRv5256:Sy4; curret town index in player's list
!!VRv5257:Cy6/y5/y4; index of 3 towns shown in town screen list
!!FU:E;
!!en:;

!!if&y2=-2:;entering new town when having 2 or more towns
!!VRv5256:Sy3; curret town index in player's list
!!VRv5257:Cy5/y4/y3; index of 3 towns shown in town screen list
!!FU:E;
!!en:;
*****************************************************
**循环检测玩家城镇列表中,目标列表的编号**
!?FU6155; x1 is target town map index x2 collects the list index
!!OW:W-1/x16/?y1;
!!if&y1=x1;
!!VRx2:Sx16;
!!VRx16:S1000000;
!!FU:E;
!!en:;
!!VRx2:S-1;
*****************************************************


第三部分
由于每次建造建筑会自动刷新城镇外观,在我们离开城镇界面时,必须先把城镇外观改成新城的外观。
外观用的是稍有损坏和 完全损坏的城镇def。可以先在pac中替换成新城的def。

**退出城镇界面时,更新所有逐鹿城的外观(以及生物巢穴设置)**
*LMB push in Town Screen, on OK button(checkmark), update all ZL town looks
!?CM1;
!!CM:I?y1 S?y2;
!!FU&y1<>30720:E;
!!FU&y2<>10/y2<>12:E; //Left mouse click sub type is 10, enter/esc is 12 for OK button
!!UN:U98/-1/?y3;
!!VRv1:C-1/-1/-1;
!!DO6153/1/y3/1:P; //loop through all towns to refresh town appearance
!?FU6153;
!!UN:U98/-1/-1/2;
!!CA2:N?z3; get Town Name
!!VRz2:M1/z3/0/2; get substring "ZL" if Town is ZL
!!FU&z2<>z709:E;
*!FU6151:P0/towntype; //restore the default town setting(no need)
!!CA2:B3/7;
!!CA2&1:I1;
!!CA2&-1:I-1;
********************************************************************************





XEricSin 发表于 2016-10-18 07:41:42

YangChao01 发表于 2016-10-18 07:33
哈哈知道了谢谢。
我想起高清补丁的回城术,在回城清单选城就能切换到此城附近地图,应该有办法在取得选中 ...

主要是选城的对话框无法监测到点的是哪个城,然而又必须在跳转城镇界面前重置城镇图片。
城堡大门直接跳转界面就没办法了。
回城只是回到城门口就没关系,进城的时候可以更换巢穴和图片.

YangChao01 发表于 2016-10-18 09:10:49

应该是有某个内存地址记录着点到哪个城的,只是 WOG小组没找到这个地址或者找到了没告诉我们,高清补丁作者可能会知道。
还有很多环境变量之类的信息,存在但 ERM里找不到的,例如战场双方士气运气的基值,存档信息的开局默认种族初始英雄奖励选择等等。
这些可能要有兴趣的高手来完成了。

XEricSin 发表于 2016-4-29 19:36:54

此脚步必须在完整的mod中运行。

下载mod包可以来这里:
我也来YY一个新种族
http://www.h3wog.com/forum.php?mod=viewthread&tid=55530
(出处: WoG-英雄无敌III 中文论坛)

a6825425 发表于 2016-4-30 09:01:07

大神,这个只能在3.58F么,封神不能加载把?

XEricSin 发表于 2016-4-30 09:28:25

a6825425 发表于 2016-4-30 09:01
大神,这个只能在3.58F么,封神不能加载把?

这个要在era2.46中运行。
可以跟封神一起,但是必须关闭界面增强,不然内存会超30MB。
目前脚本部分基本完成。
新生物动画还在制作中。

贤知有您 发表于 2016-4-30 21:36:27

持续关注中,希望楼主的大作尽早面世.
:good_job::good_job:

XEricSin 发表于 2016-5-4 09:08:37

脚本更新了。生物经验和技能还不完整。

XEricSin 发表于 2016-5-5 01:43:04

新生物大部分功能已经弄好了。
可以在城镇中招募。
还需要野外巢穴部分。
新英雄有待开发。

本脚本要结合新生物插件使用。
本脚本还使用了封神97,98两个脚本中的以下函数:
**(FU777710,FU16011, FU16022, FU16023, FU16037, FU16038, FU16040, FU16061,)

XEricSin 发表于 2016-5-6 19:46:01

马卡尔 发表于 2016-5-6 19:42
一片天书~~~~ 是不是以后就能脱离8种族限制了

等VCMI版本出来之后才能完全脱离。

andyleeok 发表于 2016-5-13 23:48:11

很牛B啊,学习一下

andyleeok 发表于 2016-5-14 23:44:28

神一样代码,大神啊

xr1998 发表于 2016-6-4 14:26:57

我进来膜拜一下,感谢楼主的努力

zhang2016007 发表于 2016-7-17 22:19:58

看天书一样;lh;完全不懂:shufu:

XEricSin 发表于 2016-7-17 23:49:49

xiaojie666 发表于 2016-7-17 18:02
内存超30m是mod的大小还是什么啊

不是mod大小。
是游戏加载mod时占用的空间。
主要跟脚本大小有关。一个100kb的脚本可能占用1-5mb的内存吧。

XEricSin 发表于 2016-7-20 02:59:15

warwolfworld 发表于 2016-7-19 18:55
原來這篇也是LZ發的啊!!
http://www.h3wog.com/forum.php?mod=viewthread&tid=55530
所以可以兼容封 ...

新城兼容,但是新兵种就不一定了

天穹剑印 发表于 2016-7-22 22:38:20

厉害啊,虽然看不懂但是很想学习一下

yq1599527 发表于 2016-7-29 11:04:56

楼主辛苦,只能膜拜学习

softds 发表于 2016-9-10 09:44:50

有各位大大的努力才有今天我们玩游戏的信仰,多谢!

小真真 发表于 2016-10-2 14:47:35

虽然看不大明白。膜拜一下大神

YangChao01 发表于 2016-10-17 06:38:10

楼主的 ERM技术自不用说,楼主的耐心更是厉害。

顺便问一下,进入城填界面还有一种途径是什么,是英雄回城术回城?还是王国资源界面?

XEricSin 发表于 2016-10-18 06:58:57

YangChao01 发表于 2016-10-17 06:38
楼主的 ERM技术自不用说,楼主的耐心更是厉害。

顺便问一下,进入城填界面还有一种途径是什么,是英雄回 ...

就是王国资源界面。貌似还有地狱的城堡大门。
页: [1] 2
查看完整版本: 新增城镇的脚本副简单讲解

捐赠