New portals.txt format

Wrote new code? Fixed a bug? Want to discuss technical stuff? Feel free to post it here.

Moderator: Moderators

Message
Author
iMikeLance
Moderators
Moderators
Posts: 208
Joined: 01 Feb 2010, 17:37
Noob?: No
Location: Brazil - MG
Contact:

New portals.txt format

#1 Post by iMikeLance »

EDIT: Changed to a cleaner and shorter code, also keeping compatibility with automatic portals recording:
Link: http://hastebin.com/rurewowuce.hs
I was able to implement 100% airship routing.

Sample:

Code: Select all

prt_maze01 74 12 prt_maze01 139 45
prt_maze01 85 174 prt_maze01 74 12
prt_maze01 85 56 prt_maze01 23 125
prt_maze01 85 97 prt_maze01 137 125
prt_maze01 96 45 prt_maze01 55 45
prt_maze01 99 34 prt_maze01 139 45
# splendide
moc_para01 44 19 moc_fild20 342 198 {
	steps: c r0 c
}
moc_fild20 368 197 moc_fild22b 175 159 {
	steps: c r1 c
}
moc_fild22b 182 179 mid_camp 210 291 {
	steps: c c c c r0 c
}
Airship sample:

Code: Select all

airplane 243 73 lighthalzen 302 75 {
	activation_text: Lighthalzen
}
airplane 243 73 einbroch 92 278 {
	activation_text: Einbroch
}
airplane 243 73 yuno 92 260 {
	activation_text: [J|Y]uno
}
airplane_01 243 73 yuno 12 261 {
	activation_text: [J|Y]uno
}
airplane_01 243 73 ra_fild12 292 204 {
	activation_text: Rachel
}
airplane_01 243 73 izlude 200 56 {
	activation_text: Izlude
}
==== OLD POST ====

Example (converted from bRO): http://pastebin.com/6QJ36TyL

Code: Select all

{ # yuno 152 187 -> aldebaran 168 112
	source: (
		map: yuno
		x: 152
		y: 187
	)
	dest: (
		map: aldebaran
		x: 168
		y: 112
	)
	cost: 1200
	ticket: 1
	steps: c r2 c r0
},
It's totally expandable, you can add there as many properties as you want. Identation is optional. Also you can add there properties to be used by plugins.
Currently, i'm planning to use it to add support to airplane and moskovia troubled route.
We could add a header to portals.txt to decide whether it's this new format or not, keeping compatibility with older tables.
It could be more compact though. Maybe this:

Code: Select all

dest: (map: aldebaran, x: 168, y: 112)
(And would be easier to search).

FileParsers code:

Code: Select all

sub parsePortals {
	my ($file, $r_hash) = @_;
	undef %{$r_hash};
	my $reader = Utils::TextReader->new($file);
	my %portal;
	my $sub_struct;
	until ($reader->eof) {
		$_ = $reader->readLine;
		s/\r//g;
		s/(.*)[\s\t]+#.*$/$1/;
		s/^\s+|\s+$//g;
		if (/^\}\,/) { # reached end of definition, save
			my $portal = sprintf("%s %s %s", $portal{'source'}{'map'}, $portal{'source'}{'x'}, $portal{'source'}{'y'});
			my $dest = sprintf("%s %s %s", $portal{'dest'}{'map'}, $portal{'dest'}{'x'}, $portal{'dest'}{'y'});
			$$r_hash{$portal}{'source'}{'map'} = $portal{'source'}{'map'};
			$$r_hash{$portal}{'source'}{'x'} = $portal{'source'}{'x'};
			$$r_hash{$portal}{'source'}{'y'} = $portal{'source'}{'y'};
			$$r_hash{$portal}{'dest'}{$dest} = $portal{'dest'};
			
			#$$r_hash{$portal}{'dest'}{$dest} = $portal{'misc'};
			map { $$r_hash{$portal}{'dest'}{$dest}{$_} = $portal{'misc'}{$_} } keys %{$portal{'misc'}};
			$$r_hash{$portal}{dest}{$dest}{enabled} = 1; # is available permanently (can be used when calculating a route)
			undef %portal;
			undef $sub_struct;
		} elsif (/^(\w+):\s+\(/) { # begin complex struct
			$sub_struct = $1; # set our complex struct name, like source or destination
		} elsif (/^\)$/) { # end complex struct
			undef $sub_struct;
		} elsif (/^(\w+):\s+(.+)/) {
			if ($sub_struct) {
				$portal{$sub_struct}{$1} = $2;
			} else {
				$portal{'misc'}{$1} = $2;
			}
		} elsif (!/^\{$/) {
			error ("Error in parsePortals2 $_\n");
			return 0;
		}
	}
	return 1;
}
Another uses:

Code: Select all

equip: #itemID
Equip #itemID before talking to the NPC, re-equip previous item then. Useful for moskovia, biolabs...

Code: Select all

activation_text: /airplane broadcast regex/
Would start deactivated when entering source map, and will only be available once the text is detected.

iMikeLance
Moderators
Moderators
Posts: 208
Joined: 01 Feb 2010, 17:37
Noob?: No
Location: Brazil - MG
Contact:

Re: New portals.txt format

#2 Post by iMikeLance »

Well, now that airship routing if fully working I need a way to fix some other cases:
* DONE: routing from ra_fild12 -> airship. There's a portal that makes that route, but it's different. It has a talksequence, but it's also a portal. You have to step into it, then the talksequence begins. Kore needs a native way to handle this kind of talk. I just don't see the best way to do it. It would be strange to put it in Task::TalkNPC, would be nicer if we create another task. EDIT: hugel -> airplane has the same problem.
* Bungee Jump. This should be simple: Kore can walk to the "teleport" spot over and over again until it reaches it's destination ( in this case, nif_in).

ei8ht
Noob
Noob
Posts: 1
Joined: 21 Aug 2017, 20:53
Noob?: Yes

Re: New portals.txt format

#3 Post by ei8ht »

noob here and i would like to create a route for bungy im not sure where to put this code and how it works. is it in the macro.txt? what to change in config?

thank you in advance
iMikeLance wrote:EDIT: Changed to a cleaner and shorter code, also keeping compatibility with automatic portals recording:
Link: http://hastebin.com/rurewowuce.hs
I was able to implement 100% airship routing.

Sample:

Code: Select all

prt_maze01 74 12 prt_maze01 139 45
prt_maze01 85 174 prt_maze01 74 12
prt_maze01 85 56 prt_maze01 23 125
prt_maze01 85 97 prt_maze01 137 125
prt_maze01 96 45 prt_maze01 55 45
prt_maze01 99 34 prt_maze01 139 45
# splendide
moc_para01 44 19 moc_fild20 342 198 {
	steps: c r0 c
}
moc_fild20 368 197 moc_fild22b 175 159 {
	steps: c r1 c
}
moc_fild22b 182 179 mid_camp 210 291 {
	steps: c c c c r0 c
}
Airship sample:

Code: Select all

airplane 243 73 lighthalzen 302 75 {
	activation_text: Lighthalzen
}
airplane 243 73 einbroch 92 278 {
	activation_text: Einbroch
}
airplane 243 73 yuno 92 260 {
	activation_text: [J|Y]uno
}
airplane_01 243 73 yuno 12 261 {
	activation_text: [J|Y]uno
}
airplane_01 243 73 ra_fild12 292 204 {
	activation_text: Rachel
}
airplane_01 243 73 izlude 200 56 {
	activation_text: Izlude
}
==== OLD POST ====

Example (converted from bRO): http://pastebin.com/6QJ36TyL

Code: Select all

{ # yuno 152 187 -> aldebaran 168 112
	source: (
		map: yuno
		x: 152
		y: 187
	)
	dest: (
		map: aldebaran
		x: 168
		y: 112
	)
	cost: 1200
	ticket: 1
	steps: c r2 c r0
},
It's totally expandable, you can add there as many properties as you want. Identation is optional. Also you can add there properties to be used by plugins.
Currently, i'm planning to use it to add support to airplane and moskovia troubled route.
We could add a header to portals.txt to decide whether it's this new format or not, keeping compatibility with older tables.
It could be more compact though. Maybe this:

Code: Select all

dest: (map: aldebaran, x: 168, y: 112)
(And would be easier to search).

FileParsers code:

Code: Select all

sub parsePortals {
	my ($file, $r_hash) = @_;
	undef %{$r_hash};
	my $reader = Utils::TextReader->new($file);
	my %portal;
	my $sub_struct;
	until ($reader->eof) {
		$_ = $reader->readLine;
		s/\r//g;
		s/(.*)[\s\t]+#.*$/$1/;
		s/^\s+|\s+$//g;
		if (/^\}\,/) { # reached end of definition, save
			my $portal = sprintf("%s %s %s", $portal{'source'}{'map'}, $portal{'source'}{'x'}, $portal{'source'}{'y'});
			my $dest = sprintf("%s %s %s", $portal{'dest'}{'map'}, $portal{'dest'}{'x'}, $portal{'dest'}{'y'});
			$$r_hash{$portal}{'source'}{'map'} = $portal{'source'}{'map'};
			$$r_hash{$portal}{'source'}{'x'} = $portal{'source'}{'x'};
			$$r_hash{$portal}{'source'}{'y'} = $portal{'source'}{'y'};
			$$r_hash{$portal}{'dest'}{$dest} = $portal{'dest'};
			
			#$$r_hash{$portal}{'dest'}{$dest} = $portal{'misc'};
			map { $$r_hash{$portal}{'dest'}{$dest}{$_} = $portal{'misc'}{$_} } keys %{$portal{'misc'}};
			$$r_hash{$portal}{dest}{$dest}{enabled} = 1; # is available permanently (can be used when calculating a route)
			undef %portal;
			undef $sub_struct;
		} elsif (/^(\w+):\s+\(/) { # begin complex struct
			$sub_struct = $1; # set our complex struct name, like source or destination
		} elsif (/^\)$/) { # end complex struct
			undef $sub_struct;
		} elsif (/^(\w+):\s+(.+)/) {
			if ($sub_struct) {
				$portal{$sub_struct}{$1} = $2;
			} else {
				$portal{'misc'}{$1} = $2;
			}
		} elsif (!/^\{$/) {
			error ("Error in parsePortals2 $_\n");
			return 0;
		}
	}
	return 1;
}
Another uses:

Code: Select all

equip: #itemID
Equip #itemID before talking to the NPC, re-equip previous item then. Useful for moskovia, biolabs...

Code: Select all

activation_text: /airplane broadcast regex/
Would start deactivated when entering source map, and will only be available once the text is detected.

Post Reply