New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] add lua gamemap object for map generation. #3611

Open
wants to merge 7 commits into
base: 1.14
from

Conversation

Projects
None yet
2 participants
@gfgtdf
Contributor

gfgtdf commented Oct 10, 2018

this pr does two things:

  1. Add a lua gamemap object whihc can be used in lua map generators which has the following funcions
    1.1) set_terrain, get_terrain, like the usualy set/get_terrain functions, map:set_location(loc, "*^Gg", "overlay")
    1.2) a data fiels that basiciall serializes the map to a string `` local res = map.data
    1.3) get_locations, which accepts a custom lua filter table which is not wml, but similar to the usual filters
-- assuming lua helper functions f_terrain etc are defined properly.
local locs = wesnoth.get_locations(
  f_and(
    f_terrain("Gg"),
    f_or(
      f_adjacent(f_terrain("Mv"), "n"),
      f_x("0-1")
    )
  )
)

but is easier to use form lua and has a clear tree structore that avoids certain hard to understand behviour of old location filter in particular wrt to radius and not etc.
1.4) function to deal with startign locations.

  1. wesnoth.generate_default_map that invokes the default map generator from lua.

Ofc both things can easiyl be used together that is, by first letting the default mapgenerator do it's job and the do the finetuning with custom gamemap actions, this in in particual what some umc addons currently do and this code would make it very easy to do suhc things right in the mapgeneration code.

@gfgtdf

This comment has been minimized.

Show comment
Hide comment
@gfgtdf

gfgtdf Oct 11, 2018

Contributor

Ok the travis builds fail becasue the xcode projectiles are not updated for this, but that's nothing i can fix.

This pr curently targets 1.14 but it intended for master as soon as master is fixed, but also for a possible 1.14. featurerelease.

minor changes to the filtersyntax still migth happen, but it is mostly complete.

Contributor

gfgtdf commented Oct 11, 2018

Ok the travis builds fail becasue the xcode projectiles are not updated for this, but that's nothing i can fix.

This pr curently targets 1.14 but it intended for master as soon as master is fixed, but also for a possible 1.14. featurerelease.

minor changes to the filtersyntax still migth happen, but it is mostly complete.

@gfgtdf

This comment has been minimized.

Show comment
Hide comment
@gfgtdf

gfgtdf Oct 11, 2018

Contributor

i wonder whether i shoudl rename the and and or filters to all and any but i would not know what to renamte the nand filter to then.

Contributor

gfgtdf commented Oct 11, 2018

i wonder whether i shoudl rename the and and or filters to all and any but i would not know what to renamte the nand filter to then.

@CelticMinstrel

This comment has been minimized.

Show comment
Hide comment
@CelticMinstrel

CelticMinstrel Oct 12, 2018

Member

I don't like this filter syntax; see my comment on the forums.

Possible alternative suggestion: use string keys instead of functions:

local locs = wesnoth.get_locations{
  all = {
    terrain = "Gg",
    any = {
      adjacent = {terrain = "Mv", "n"},
      x = "0-1"
    }
  }
}
Member

CelticMinstrel commented Oct 12, 2018

I don't like this filter syntax; see my comment on the forums.

Possible alternative suggestion: use string keys instead of functions:

local locs = wesnoth.get_locations{
  all = {
    terrain = "Gg",
    any = {
      adjacent = {terrain = "Mv", "n"},
      x = "0-1"
    }
  }
}
@CelticMinstrel

This comment has been minimized.

Show comment
Hide comment
@CelticMinstrel

CelticMinstrel Oct 12, 2018

Member

(Also, doesn't wesnoth.get_locations already exist and take a WML filter?)

Member

CelticMinstrel commented Oct 12, 2018

(Also, doesn't wesnoth.get_locations already exist and take a WML filter?)

@gfgtdf

This comment has been minimized.

Show comment
Hide comment
@gfgtdf

gfgtdf Oct 12, 2018

Contributor

Possible alternative suggestion: use string keys instead of functions:

This doesn't really work becasue

  1. It doesnt allow you to speficy the order in which the subfilters (of and, any etc) are executed, note that the order in which woud write the attributes in lua code is irrelevent,
  2. it doesnt easily allow you to put filters of the same type in one and, for example filters like f_all(f_adjacent("Ww", "s"), f_adjacent("Gs", "n"), f_adjacent("Mv", "nw")) would need to be worked around with multiple nested alls etc.

(Also, doesn't wesnoth.get_locations already exist and take a WML filter?)

yes the new functis is actuall a mber ber function of the map object, see the example code in the last commit for a working example

Contributor

gfgtdf commented Oct 12, 2018

Possible alternative suggestion: use string keys instead of functions:

This doesn't really work becasue

  1. It doesnt allow you to speficy the order in which the subfilters (of and, any etc) are executed, note that the order in which woud write the attributes in lua code is irrelevent,
  2. it doesnt easily allow you to put filters of the same type in one and, for example filters like f_all(f_adjacent("Ww", "s"), f_adjacent("Gs", "n"), f_adjacent("Mv", "nw")) would need to be worked around with multiple nested alls etc.

(Also, doesn't wesnoth.get_locations already exist and take a WML filter?)

yes the new functis is actuall a mber ber function of the map object, see the example code in the last commit for a working example

@wesnoth wesnoth deleted a comment from codacy-bot Oct 12, 2018

@wesnoth wesnoth deleted a comment from codacy-bot Oct 12, 2018

@wesnoth wesnoth deleted a comment from codacy-bot Oct 12, 2018

@wesnoth wesnoth deleted a comment from codacy-bot Oct 12, 2018

@CelticMinstrel

This comment has been minimized.

Show comment
Hide comment
@CelticMinstrel

CelticMinstrel Oct 12, 2018

Member

Hm okay, I see what you mean... but more importantly, if you want to add an entirely new filter syntax, I think you should try to consider all the ways in which it could be done, rather than adding something that's almost the same as the existing filters just with a few small differences... which is what this is.

Member

CelticMinstrel commented Oct 12, 2018

Hm okay, I see what you mean... but more importantly, if you want to add an entirely new filter syntax, I think you should try to consider all the ways in which it could be done, rather than adding something that's almost the same as the existing filters just with a few small differences... which is what this is.

@gfgtdf

This comment has been minimized.

Show comment
Hide comment
@gfgtdf

gfgtdf Oct 12, 2018

Contributor

Hm okay, I see what you mean... but more importantly, if you want to add an entirely new filter syntax, I think you should try to consider all the ways in which it could be done, rather than adding something that's almost the same as the existing filters just with a few small differences... which is what this is.

Well yes I thought of multiple ways to have filters, including doing the whole thing as a string, and an attributr bases syntax like you suggested itomething before implem nting this and this one just ended up working best,

Contributor

gfgtdf commented Oct 12, 2018

Hm okay, I see what you mean... but more importantly, if you want to add an entirely new filter syntax, I think you should try to consider all the ways in which it could be done, rather than adding something that's almost the same as the existing filters just with a few small differences... which is what this is.

Well yes I thought of multiple ways to have filters, including doing the whole thing as a string, and an attributr bases syntax like you suggested itomething before implem nting this and this one just ended up working best,

gfgtdf added some commits Oct 8, 2018

prepare map_location refactor
currently there xists different coorignate formats
1) The wml format in which the topleft border corner tile is (0,0)
2) The `struct map_location` format in which the topleft noborder
   corner tile is (0,0), which means the topleft border corner
   tile is (-1,-1)
3) the format that is uses to index the tilemap structure where
   again the topleft border corner tile is (0,0)

It would be nice if we could eventually refactor out (2) and to
start that i'll start to use map_location::wml_x() which uses
format (1) instead of map_location::x which uses format (1), once
all occurance use the wml format we can remove the other one and
rename wml_x() to just x. (same for y)
add option to disable wml tests in msvc.
they just take way to long.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment