Boarding ships.

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
User avatar
Gambit
Loose Screw
Posts: 3266
Joined: August 13th, 2008, 3:00 pm
Location: Dynamica
Contact:

Boarding ships.

Post by Gambit »

Some of you have prolly played Gambits Empire Builder by now and have gotten to the point where you have a navy.

Id like to add a feature that allows each ship to store 1 unit.

Basically when you buy a ship it makes it makes its role = ship_num

Then ship_num = ship_num +1

This assigns each ship its own unique number. Then when you board a ship the unit would be stored in traveler_$ship.role

Now for the right click menu I know how to check to see if a ship is adjacent but not how to call that ships role because the right click is triggered on the unit, not the ship. So is it possible to call data from an adjacent unit? to my knowledge things like x$2 only apply to battles...


p.s. yes i finally got email ;)
SkeleRanger
Posts: 151
Joined: August 12th, 2008, 11:10 pm
Location: The Isle of Alduin

Re: Boarding ships.

Post by SkeleRanger »

Are you just putting this into a campaign you're making, or are you suggesting it should be put in mainline?
'We've strayed into a zone with a high magical index... Don't ask me how. Once upon a time a really powerful magic field must have been generated here, and we're feeling the after-effects.'
'Precisely,' said a passing bush.
--Terry Pratchett
Tale of a Mage(finished)
Art for Tale of a Mage
User avatar
Gambit
Loose Screw
Posts: 3266
Joined: August 13th, 2008, 3:00 pm
Location: Dynamica
Contact:

Re: Boarding ships.

Post by Gambit »

its for my addon. lol. boarding ships in mainline wouldnt work as they are not combat units and there is general only one of them. sometimes there not even units just pictures.



my question is. how do i call an adjacent units role? being able to store it in a variable and acess all the units info would be even more helpful.
SkeleRanger
Posts: 151
Joined: August 12th, 2008, 11:10 pm
Location: The Isle of Alduin

Re: Boarding ships.

Post by SkeleRanger »

Oh duh, Gambits Empire Builder. I thought you were refering to some civilization game. I feel really dum so I'm going to shut up now.
'We've strayed into a zone with a high magical index... Don't ask me how. Once upon a time a really powerful magic field must have been generated here, and we're feeling the after-effects.'
'Precisely,' said a passing bush.
--Terry Pratchett
Tale of a Mage(finished)
Art for Tale of a Mage
User avatar
Gambit
Loose Screw
Posts: 3266
Joined: August 13th, 2008, 3:00 pm
Location: Dynamica
Contact:

Re: Boarding ships.

Post by Gambit »

Yeah a lot of people have asked me when I plan to make transport ships actually live up to thier name.
deinotes
Posts: 7
Joined: August 31st, 2008, 9:24 am

Re: Boarding ships.

Post by deinotes »

Isn't that functionallity not already in The High Seas navel battles ?
Maybe you can look into that era for a example how to board the ship.
User avatar
Gambit
Loose Screw
Posts: 3266
Joined: August 13th, 2008, 3:00 pm
Location: Dynamica
Contact:

Re: Boarding ships.

Post by Gambit »

:lol2: :lol2: :lol2: :lol2: :lol2: :lol2:

bob uses terrain to store his units. i need to use variables. its not the boarding of the ships. its the systymatic storing, sorting, and retrieving units that has me perplexed.
Mabuse
Posts: 2239
Joined: November 6th, 2007, 1:38 pm

Re: Boarding ships.

Post by Mabuse »

so is this problem solved, or may i help you ? :)
The best bet is your own, good Taste.
Mabuse
Posts: 2239
Joined: November 6th, 2007, 1:38 pm

Re: Boarding ships.

Post by Mabuse »

i would try this (as a crude idea for now, not tested it ;))


so in essence you want to store data of a unit (which is a ship), which is adjacant to an right-clicked on other unit (lets say this uit is on coordinates $X1, $y1)


my suggestion:

Code: Select all


[store_unit]
variable=whatever #we want to store a unit in variable

[filter]
description=transport-ship #the unit we are looking for is a transportship
side=$side_number # our side

[filter_location] #and should be at a location 
radius=1 #within a 1-tile radius
[filter] #next to a unit
side=$side_number #of our side
x=$x1 #we currently right-clicked at
y=$y1
[/filter]
[/filter_location]

[/filter]

[/store_unit]

as said this assumed the coordinates of the right clicked unit are stored as x1,y1, which shouldn be a problem though (becasue there it is usually)
The best bet is your own, good Taste.
Mabuse
Posts: 2239
Joined: November 6th, 2007, 1:38 pm

Re: Boarding ships.

Post by Mabuse »

EDIT2 :
description= "transport ship"

is of course only a placeholder. you can also ask for unittype (if itis a special unit) or whatever makes the unit you want to store identifyable

but i assume this should be clear ,)
The best bet is your own, good Taste.
User avatar
SpoOkyMagician
Posts: 281
Joined: September 5th, 2008, 8:04 am
Location: I have no idea...

Re: Boarding ships.

Post by SpoOkyMagician »

Well... Let's see here... Let's lay this concept out in words...

So you want to garrison units into a ship and whenever you want, you can ungarrison them as well. Well, first off think about this. The map has to be all terrain. No cave walls or voids. If you do, this could mess up ungarrisoning units. But yea, the code above sounds right. But the basic concept is this... (just giving the concept.)

Find units around the ship. (radius of 1)
Store the units in a array.
Remove the units.
Once moved to where you want... Ungarrison (create) the units from new X,Y.

As I said above, units could be dropped off into water or other unwanted terrains if not careful. Plus the units have to be killed after storing them. So remembering HP is practically pointless but possible. Then recreating them again with same x,y but with new current position.

As far as what it would lool like in code... lets see... (Give me a sec while I type it out. I will re-edit soon. The code may not be right but the concept will be there.)

You would obviously have to make the 2 menu items 'garrison' and 'ungarrison'. (You could put the code in the command i believe too. Dunno offhand atm thou.) I wouldn't know because I never use them. :|

Code: Select all

[event]
     name=menu_item 'garrison_units'
     first_time_only=no
     [store_units]
          x,y=$x1,$y1
          radius=1
     [/store_units]
     [kill]
          [filter]
               [filter_???] # (whatever this is called. where it checks N,NE,SE,etc...)
                     ... <filter the locations here.>
               [/filter_???]
          [/filter]
     [/kill]
[event]
Then...

Code: Select all

[event]
     name=menu_item ungarrison_units
     first_time_only=no
     [unit]
          [filter]
               [/filter_???]
                    ... (filter with x,y within the array or however you do it...)
               [/filter_???]
          [/filter]
     [/unit]
[/event]
The WML syntax I wrote is obviously not correct. I would have to look up the Wiki but I am a bit tired and I don't remember the exact code atm... But the concept of the code is there. Hopefully that will get you started.

oh and just a few extra comments as well. CLEAR the variable everytime you ungarrison and reinitialize every time you garrison units. This will keep it from remembering old units that could not be created and keep the variable. I also recommend not letting it garrison more than 6 units at a time. Since it uses the N,NE,SE,etc thing. But if you get it up and running; give 20 units a try. XD (Since they could move to the hex at any time.)
"You don't have to understand me, I'm just there!" ~ SpoOkyMagician
Creator of: Unwelcome Guests Series, Modifiable Android Project, SpoOky's Survivals, and many more... (Most of my old stuff is gone.)
(User Page)
User avatar
A Guy
Posts: 793
Joined: May 24th, 2008, 1:55 am

Re: Boarding ships.

Post by A Guy »

The [store_units] code is wrong. It is spelled as [store_unit], not [store_units]. You must use a [filter] tag to filter what units to store, and you must describe what variable to store the unit into. You can use [filter_adjacent] to filter for units adjacent to a certain unit or location. I do not believe that [store_unit] accepts a location filter.

You can also use kill=yes in the [store_unit] tag to remove the units from play.
I'm just... a guy...
I'm back for now, I might get started on some work again.
opensourcejunkie
Posts: 547
Joined: August 11th, 2008, 3:19 pm

Re: Boarding ships.

Post by opensourcejunkie »

hey, this is a little off topic, but I thought I'd speak up about your method of storing the unit.
Gambit wrote:Basically when you buy a ship it makes it makes its role = ship_num

Then ship_num = ship_num +1

This assigns each ship its own unique number. Then when you board a ship the unit would be stored in traveler_$ship.role
When I programmed the gold caravan transport code for Longbow, a similar idea was proposed - have a variable for each caravan that would hold the amount of gold being transported in that caravan. It was later suggested, however, that a more elegant solution would be to store the amount of gold in a variable inside of the unit itself. (e.g. $ship_variable.passenger_variable). That way you don't have to mess around with roles, and the data remains packaged together in a logical fashion.

It's a suggestion, anyway.
--OSJ
what if the Bible's claims about Christ depicted accurate, verifiable history? given some research, you might be surprised at the evidence...
User avatar
Gambit
Loose Screw
Posts: 3266
Joined: August 13th, 2008, 3:00 pm
Location: Dynamica
Contact:

Re: Boarding ships.

Post by Gambit »

i should put a unit inside another unit :? :?: :| :hmm:
opensourcejunkie
Posts: 547
Joined: August 11th, 2008, 3:19 pm

Re: Boarding ships.

Post by opensourcejunkie »

i should put a unit inside another unit :? :?: :| :hmm:
more or less : - ). I mean, that is what's happening in "real life" - a unit is being placed inside of a ship. From a code stand-point, it isn't all that awkward either. Units are nothing more than big variables that hold a lot of other variables (unit.x, unit.y, unit.hitpoints, etc.). It shouldn't be a problem to place a unit as a sub-variable of another unit (unit.passenger).

Anyway, I think it's the elegant way to accomplish this, although if the other method makes more sense to you, then go with whatever's comfortable for you.
--OSJ
what if the Bible's claims about Christ depicted accurate, verifiable history? given some research, you might be surprised at the evidence...
Post Reply