⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mbm_mlmap.d2l

📁 转载其他网站的资料与大家分享
💻 D2L
📖 第 1 页 / 共 5 页
字号:
//##################################################
//######   Matts Map and Pathing Library    ########
//##################################################
/*
----------------------------------------------------
Version 2.0.3
----------------------------------------------------
Copyright (C) 2003 Matt Lanteigne aka mattlant <mattlant@hotmail.com>
----------------------------------------------------

This program is free software; You can redistrubute freely as long as this
header stays intact. Modifications may be done as long as original header
and credits stay.

This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY
or FITNESS FOR A PARTICULAR PURPOSE.

----------------------------------------------------
Known Issues:
- Not all functions fully tested

----------------------------------------------------
TODO:
- Add automatic support for doors

----------------------------------------------------
FIXES and upgrades:
2.0.3
- Fixed a problem with pathuing very short distances
- Fixed a ton of small misc errors

2.0.2
- Added in Area Caching
- Added in FindPathToRoom
- Added in FindPathALongPoints (requested by scavenger)
- Fixed getMapExit bugs
- commeneted out some path to map code which may speed pathing a bit
- fixed some other misc bugs

2.0.1
- fixed problems in PathMove method
- removed mlReason and replaced with a member variable called:
.LastError

2.0.0
- Made it .29 compliant
- added in different heuristics and factor options
- added in a function called FindScore so you can know the cost
of moving to a destination
- crosslevel pathing is non functional
- GetFarObject is non functional
- Encapsulated all functions inside an object

1.0.3
- Added in mlFindClosestWalkable(x,y)
this will return the closest walkable x,y to the given x,y
- fixed up a couple misnumbered warps
- added in a couple more range checks
- fixed up some other small misc code
- changed to dynamically linked dll(smaller d2h file)

1.0.2
- Changed communication to completely file I/O
This should fix problems people were having with the msg function.
- Fixed some code in the mlMap.d2h, including a 10k per game mem leak :(
- Added mlgetLevelWarpNumber(warptype, level)
this will allow you to get the warptypes tile number, so its now easier
to use getTile function ie:
stairs = getUnit(5, mlgetLevelWarpNumber(mlWARPNEXT));
- cleaned up some miscellaneous code

1.0.1
Area cross level pathing sometomes wouldnt get good coordinates (fixed)
Act 1 Town cross level pathing (fixed)
Map edge wrap around in pathing algoritm's if both far edges are open (hehe)(outdoor areas only)(fixed)
D2MapReply msg's stop processing. (possibly fixed and MUCH faster)
being added:
waypoint warps(done)
getFarObject(done)
remove printed messages and make them optional(done)
seperate the dprint into a new function(done)
have walkcalls passed the actual value for advanced stuff(done)
out of bounds checks for more stability(done)
mlMap.d2h optional error log(done)

----------------------------------------------------
Bit Structure:
Map bits:
bit 0 : block walk
bit 1 : block light
bit 2 : Block LOS (block jump too)
bit 3 : block Player's walk but not Mercenary's walk (weird)
bit 4 : ?
bit 5 : block light only (not LOS) ?
bit 6 : ?
bit 7 : ?
NPC/Monster bits: //to be implemented in next release
bit 8 :
bit 9 :
bit 10 :
bit 11 :
bit 12 :
bit 13 :
bit 14 :
bit 15 :

*/
include("mbm/mlHeap.d2l");
//include("terminal.d2l");

var SCORE = [1, 1.414];
var FORWARDHEURISTICS = ["nofh", "euclidian", "euclidiannosqrt", "manhattan", "diagshortcut", "maxdxdy"]

var mlFHNONE = 0;
var mlFHEUCLIDIAN = 1;
var mlFHEUCLIDIANNOSQRT = 2;
var mlFHMANHATTAN = 3;
var mlFHDIAGSHORTCUT = 4;
var mlFHMAXDXDY = 5;




//////////////////////////////////////////////////////////////////////
// varANT VARIABLES
// -------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////
//d2map settings varants(used internally only)
var mlCURRENTMAP = 0;
var mlPRINTMSG = 1;
var mlDOLOGGING = 2;
var mlMAPINFO = 3;

//path reduction types
var mlWALK = 0;
var mlTELEPORT = 1;

//path algo types
var mlBREADTHFIRST = 1;
var mlASTAR = 0;

//path reduction algo types
var mlREDUCEWALK = 0;
var mlREDUCESORC = 1;
var mlREDUCEJUMP = 2;

//Warp types
//short int WARPS[85] = {0,0,3,3,1,0,3,4,1,0,4,1,0,1,0,1,0,1,0,3,4,3,1,0,5,3,1,1,0,0,1,1,0,3,3,3,3,3,3,4,5,6,7,8,9,1,0,
//3,1,0,4,3,1,4,5,1,0,3,1,1,0,4,1,1,5,1,1,0,0,0,1,3,4,1,0,3,3,1,0,3,4,1,0};
var mlWARPNONE = 99;
var mlWARPNEXT = 0;
var mlWARPPREVIOUS = 1;
var mlWARPWAYPOINT = 2;
var mlWARPOTHER1 = 3;
var mlWARPOTHER2 = 4;
var mlWARPOTHER3 = 5;
var mlWARPOTHER4 = 6;
var mlWARPOTHER5 = 7;
var mlWARPOTHER6 = 8;
var mlWARPOTHER7 = 9;
var mlWARPOTHER8 = 10;
var mlWARPUNDERGROUNDPASSAGE = 0;
var mlWARPDEN = 3;
var mlWARPHOLE = 3;
var mlWARPCAVE = 3;
var mlWARPCRYPT = 3;
var mlWARPMAUSOLEUM = 4;
var mlWARPTOWER = 4;
var mlWARPTOWNTOSEWERTRAP = 3;
var mlWARPTOWNTOSEWERDOCK = 4;
var mlWARPSEWERTOTOWNDOCK = 3;
var mlWARPTOWNTOHAREM = 5;
var mlWARPHAREMTOTOWN = 3;
var mlWARPTOMB = 3;
var mlWARPVIPER = 3;
var mlWARPTALTOMB1 = 3;
var mlWARPTALTOMB2 = 4;
var mlWARPTALTOMB3 = 5;
var mlWARPTALTOMB4 = 6;
var mlWARPTALTOMB5 = 7;
var mlWARPTALTOMB6 = 8;
var mlWARPTALTOMB7 = 9;
var mlWARPMAGGOT = 3;
var mlWARPDESSERTSEWERTRAP = 4;
var mlWARPSPIDER = 3;
var mlWARPDUNGEONFORT = 4;
var mlWARPDUNGEONHOLE = 5;
var mlWARPKURASTTOSEWER = 3;
var mlWARPKURASTTOTEMPLE = 4;
var mlWARPTRAVINCALTOMEPH = 5;
var mlWARPCITYTORIVER = 0;
var mlWARPRIVERTOCITY = 1;
var mlWARPBARRICADEDOWN = 3;
var mlWARPBARRICADEDOWNWALL = 4;
var mlWARPICECAVEDOWNFLOOR = 3;
var mlWARPTEMPLETONIHL = 3;
var mlWARPMOUNTAINTOICE = 3;
var mlWARPMOUNTAINTOBAAL = 4;

//Waypoint varants DO NOT USE
var mlWAYPOINTS = new Array(119,145,156,157,237,238,288,323,324,398,402,429,494,496,511,539);

//Direction varants
var mlNORTH = 0;
var mlEAST = 1;
var mlSOUTH = 2;
var mlWEST = 3;

//Walkcalls return values
var mlCONTINUE = 1;
var mlSTOP = 2;
var mlSTEPAHEAD = 100;
var mlSTEPBACK = 200;

//Settings varants
var mlNO = 0;
var mlYES = 1;

var DelayLoadRooms = true;
var DontLoadRooms = false;

//////////////////////////////////////////////////////////////////////
// LIBRARY GLOBAL VARIABLES
// -------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////
var mlMapMSGDelay = 100;
var watched = false;

var pathhop = null;
var walkdel = 150;
//var RandomMove = 1;
//var RandomMoveDel = 10;

var mldebugdelay = 0;
var mldebuglevel=0;
var mldebuglog="output/mlMap.log";

function oMap(_initarea, _pathtomap) {
	this.Area = null;
	this.RoomList = null;
	this.InitList = null;
	var AreaCache = new Object();
	this.Path = null;

	this.minx = Number.MAX_VALUE;
	this.miny = Number.MAX_VALUE;
	this.maxx = 0;
	this.maxy = 0;
	this.roomsizex = 0;
	this.roomsizey = 0;
	this.sizex = 0;
	this.sizey = 0;
	this.AreaInitialized = null;
	this.PathToMap = _pathtomap;
	this.LastPathScore = 0;
	this.LastError = "";

	this.InitializeMap = oMap_initmap;
	this.FindPath = oMap_findpath;
	this.FindSorcPath = oMap_findsorcpath;
	this.FindSorcPath2 = oMap_findsorcpath2;
	this.IsWalkable = oMap_iswalkable;
	this.LOS = oMap_los;
	this.FindClosestWalkable = oMap_findclosestwalkable;
	this.getMapExit = oMap_getmapexit;
	this.DumpMap = oMap_dumpmap;
	this.getLevelWarpXY = oMap_getlevelwarpxy;
	this.FindScore = oMap_findscore;
	this.PathMove = oMap_pathmove;
	this.InitializeRooms = oMap_initrooms;
	this.ReleaseRooms = oMap_releaserooms;
	this.RoomXY = _xy;
	this.LoadPos = _loadpos;
	this.IsOpenXY = _isopenxy;
	
	if(_initarea)
		this.InitializeMap();

	function oMap_initrooms() {
		this.minx = Number.MAX_VALUE;
		this.miny = Number.MAX_VALUE;
		this.maxx = 0;
		this.maxy = 0;
		this.roomsizex = 0;
		this.roomsizey = 0;
		this.sizex = 0;
		this.sizey = 0;
		this.AreaInitialized = me.area;
		this.InitList = new Array();
		this.RoomList = new Array();
		var stime = new Date();
		var troom = getRoom();

		do {
			if (troom.x*5 > this.maxx) {
				this.maxx = troom.x*5;
			}
			if (troom.y*5 > this.maxy) {
				this.maxy = troom.y*5;
			}
			if (troom.x*5 < this.minx) {
				this.minx = troom.x*5;
			}
			if (troom.y*5 < this.miny) {
				this.miny = troom.y*5;
			}

			if (!troom.getStat(11)) { troom.init(); this.InitList.push(troom); }

			 print("["+this.RoomList.length+"] room number: " + troom.number + " location: " + (troom.x*5) + "," + (troom.y*5) + " dimesion: " + troom.getStat(11) + "x" + troom.getStat(12));
			if (me.x >= troom.x*5 && me.y >= troom.y*5 && me.x < troom.x*5 + troom.getStat(11) && me.y < troom.y*5 + troom.getStat(12))
				print("this room is my room");
			 delay(100);


			if(troom.getStat(11) > this.roomsizex)
				this.roomsizex = troom.getStat(11)
			if(troom.getStat(12) > this.roomsizey)
				this.roomsizey = troom.getStat(12)

			this.RoomList.push({x:troom.x*5,y:troom.y*5,xmax:troom.x*5 + troom.getStat(11),ymax:troom.y*5 + troom.getStat(12),number:troom.number});

		} while(troom.getNext());

		this.maxx += this.roomsizex;
		this.maxy += this.roomsizey;
		this.sizex = this.maxx - this.minx;
		this.sizey = this.maxy - this.miny;
		print("Done init... time: " + (new Date() - stime));
	}

	function oMap_releaserooms() {

		//for (var x = 0; x < this.InitList.length; x++) {
		//	this.InitList[x].release();
		//}
		
		//this.RoomList = null;
		//this.InitList = null;
	}

	//////////////////////////////////////////////////////////////////////
	// oMap.Initializemap()
	// -------------------------------------------------------------------
	// Used to initialize the current areas map
	//////////////////////////////////////////////////////////////////////
	function oMap_initmap() {
		this.minx = Number.MAX_VALUE;
		this.miny = Number.MAX_VALUE;
		this.maxx = 0;
		this.maxy = 0;
		this.roomsizex = 0;
		this.roomsizey = 0;
		this.sizex = 0;
		this.sizey = 0;
		this.AreaInitialized = me.area;
		var stime = new Date();
		var troom = getRoom();

		this.RoomList = new Array();
		var vx, vy;

		if (troom) do {
			if (troom.x*5 > this.maxx) {
				this.maxx = troom.x*5;
			}
			if (troom.y*5 > this.maxy) {
				this.maxy = troom.y*5;
			}
			if (troom.x*5 < this.minx) {
				this.minx = troom.x*5;
			}
			if (troom.y*5 < this.miny) {
				this.miny = troom.y*5;
			}
		} while(troom.getNext());
		
		if (!DontLoadRooms) {
			this.Area = new Array();
			this.Area.length = this.miny + 200;
			for(var i = 0; i<this.Area.length; i++){
				this.Area[i] = new Array();
				this.Area[i].length = this.minx + 200;
			}
		}

		troom = getRoom();
		var init = false;
		if (troom) do {
			if(!troom.getStat(11)) { troom.init(); init = true; }
			if (!DontLoadRooms)
				this.RoomList.push({orgx:troom.x,orgy:troom.y,x:troom.x*5,y:troom.y*5,xmax:troom.x*5 + troom.getStat(11),ymax:troom.y*5 + troom.getStat(12),loaded:false});
//			 print(this.RoomList.length + "] room number: " + troom.number + " location: " + (troom.x*5) + "," + (troom.y*5));
//			if (me.x >= troom.x*5 && me.y >= troom.y*5 && me.x < troom.x*5 + troom.getStat(11) && me.y < troom.y*5 + troom.getStat(12))
//				print("this room is my room");
//			 delay(100);

			if(troom.getStat(11) > this.roomsizex)
				this.roomsizex = troom.getStat(11)
			if(troom.getStat(12) > this.roomsizey)
				this.roomsizey = troom.getStat(12)
			var tx,ty;
			var q, r;
			q = troom.y*5 - this.miny;
			r = troom.x*5 - this.minx;
			
			if (!DelayLoadRooms && !DontLoadRooms)
			for(var y = 0; y < troom.getStat(12); y++) {
//				var tt = "";
//				var vv = new Array();
				for(var x = 0; x<troom.getStat(11); x++) {

//					vv[r + x] = troom.getCollision(x,y);
					this.Area[q + y][r + x] = (0 | troom.getCollision(x,y));
//					tt += troom.getCollision(x,y) + q + y + r + x ? "a" : "b";
					// print(troom.y*5,this.miny,y);
				}
//				this.Area[q + y] = vv;
			}
			if(init) {troom.release(); init = false;}
		} while(troom.getNext());
		this.maxx += this.roomsizex;
		this.maxy += this.roomsizey;
		this.sizex = this.maxx - this.minx;
		this.sizey = this.maxy - this.miny;
//		print("Done init... time: " + (new Date() - stime));
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -