Author Topic: Glest tower defense  (Read 45184 times)

ElimiNator

  • Airship
  • ********
  • Posts: 3,391
  • The MegaGlest Moder.
    • View Profile
Re: Glest tower defense
« Reply #75 on: 19 August 2009, 15:28:24 »
Ill upload it as soon as I can. >:( bad bandwidth,
Get the Vbros': Packs 1, 2, 3, 4, and 5!

modman

  • Guest
Re: Glest tower defense
« Reply #76 on: 19 August 2009, 21:04:38 »
startLocation gives you the position of the faction, Omega (couldn't tell if you knew that or not).

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: Glest tower defense
« Reply #77 on: 20 August 2009, 04:03:23 »
But it cannot be used like that. There is no curly braces on the start location. It should be:

createUnit('name', int index, coordinates)

So: createUnit('worker', 0, startLocation(0)) is correct. No [] or {}. This creates a worker for faction 0 at faction 0's base. Or you can use the new formating for GAE and give a direct location inside {}, in which case, you cannot give the startLocation(), and definately not 2 startLocation()'s.
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

silnarm

  • GAE Team
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Glest tower defense
« Reply #78 on: 20 August 2009, 10:35:18 »
The curly braces makes an array (technically a 'table') in LUA,

startLocation(0)
and,
{ startLocation(0)[1], startLocation(0)[2] }

are exactly the same thing :)

startLocation() returns an array, whose elements can be accessed by subscripting ( the []'s ), so what this is doing is creating a new array, and putting in it the first and second elements of the array returned by startLocation(), the result is the same, it's just a bit clumsy ;)

I've written code like that, but with offsets, so you can position things relative to a start location,
ie
createUnit ( 'unit', 0, { startLocation(0)[1]+5, startLocation(0)[2]-5 } );

crates the unit 5 cells east ( the 'x' co-ord of startLocation(0) + 5) and 5 cells north of start location 0.
Glest Advanced Engine - Code Monkey

Timeline | Downloads

ElimiNator

  • Airship
  • ********
  • Posts: 3,391
  • The MegaGlest Moder.
    • View Profile
Re: Glest tower defense
« Reply #79 on: 20 August 2009, 14:26:21 »
Realy! I didn't know that!
Get the Vbros': Packs 1, 2, 3, 4, and 5!

me5

  • Guest
Re: Glest tower defense
« Reply #80 on: 20 August 2009, 17:24:57 »
Yes it was the damn L !   :)
So here is my new code (I try to use the functions of silnarm):

Code: [Select]
<?xml version="1.0" standalone="yes" ?>

<scenario>

<difficulty value="0"/>

<players>

<player control="human" faction="defence" team="1"/>

<player control="cpu" faction="attack" team="2"/>

<player control="closed"/>

<player control="closed"/>

</players>

<map value="TD_like_4"/>

<tileset value="forest"/>

<tech-tree value="td_4"/>

<default-resources value="false"/>

<default-units value="false"/>

<default-victory-conditions value="false"/>

<scripts>

<startup>





----------------------------------------------------------------------------

--                Unit Creation and Group Management                      --

----------------------------------------------------------------------------

-- creates a unit and puts its id in group

function createAndGroup ( group, type, faction, pos )

  createUnit ( type, faction, pos );

  group[#group+1] = lastCreatedUnit ();

end

-- create a group of num units of a single unit type

function groupOfType ( group, type, faction, num, pos )

  for i=1,num do createAndGroup ( group, type, faction, pos ) end

end

-- create a group of units of different types

function groupFromTypes ( group, types, faction, pos )

  for i=1,#types do createAndGroup ( group, types[i], faction, pos ) end 

end

-- remove a unit id from a group

function removeFromGroup ( group, unitId )

  for i=1,#group do

if ( group[i] == unitId ) then

  table.remove ( group, i );

  return;

end

  end

end



-- checks if unit belongs to group

function unitIsinGroup ( group, unitId )

  for i=1,#group do

if ( group[i] == unitId ) then

 

  return true;



end

  end

end



----------------------------------------------------------------------------

--                          Group Commands                                --

----------------------------------------------------------------------------

-- give a group of units move commands to location

function groupMoveCommon ( units, location )

  for i=1,#units do givePositionCommand ( units[i], "move", location ) end

end

-- give a group of units move commands to distinct locations

function groupMoveSpecific ( units, locations )

  for i=1,#units do givePositionCommand ( units[i], "move", locations[i] ) end

end

-- give a group of units attack commands to location

function groupAttack ( units, pos )

  for i=1,#units do givePositionCommand ( units[i], "attack", pos ) end

end

----------------------------------------------------------------------------

--                             Geometry                                   --

----------------------------------------------------------------------------

-- is pos in rectangle

function pointIsIn ( pos, rectangle )

  if ( pos[1] >= rectangle[1] and rectangle[3] > pos[1]

  and pos[2] >= rectangle[2] and rectangle[4] > pos[2] ) then

return true;

  end

  return false;

end

-- returns a rectangle around the point 'pos'

function areaAround ( pos )

  return { pos[1]-5, pos[2]-5, pos[1]+5, pos[2]+5 };

end





----------------------------------------------------------------------------

--                             Start-Up                                   --

----------------------------------------------------------------------------

-- the patrol table will store the waypoints and regions around them

patrol = {};

patrol.waypoints = { {15,15}, {70,15}, {70,20}, {15,20}, {10,10} };

patrol.regions = {};

for i=1,#patrol.waypoints do

  patrol.regions[#patrol.regions+1] = areaAround(patrol.waypoints[i]);

end

-- Make a group of 8 daemons...

disableAi (1);

daemons = {};

daemons.units = {};

groupOfType ( daemons.units, "daemon", 1, 8, patrol.waypoints[1] );

-- start them on their way...

groupMoveCommon ( daemons.units, patrol.waypoints[2] );

-- remember where they are currently going...

daemons.dest = 2; -- index of current target



tickCount = 0;











disableAi(1)

createUnit ( "castle", 0, startLocation(0) );

createUnit('worker', 0, {startLocation(0)[1],startLocation(0)[2]});

createUnit ( "initiate", 1, startLocation(1) );

givePositionCommand(lastCreatedUnit(1), 'move', startLocation(0));

createUnit ( "archer", 0, {38,55} );



createUnit ( "victim", 1, {30,55} );

setCameraPosition({30,55});

giveResource('gold', 0, 2000);

giveResource('stone', 0, 100);

giveResource('wood', 0, 2000);

giveResource('food', 0, 500);



startTime = os.time();



a=true;

</startup>



 

<unitDied>



timeSinceStart = os.time() - startTime;

x=30;



if (a==true) then

a=false;

else

a=true;

end

if (a==true) then

x=30

else

x=46

end

       

      if ( lastDeadUnitName()  == "victim"  ) then

createUnit ( "victim", 1, {x,55} );





tickCount = tickCount + 1;



if( (#daemons.units) > 1 ) then --check how big the group is because if there are 0 units I will get an error

-- Check if daemons have reached target...

local cur_pos = unitPosition(daemons.units[1]);

local cur_dest = patrol.regions[daemons.dest];

if ( pointIsIn(cur_pos, cur_dest) ) then

  -- we have arrived, set next destination...

  daemons.dest = daemons.dest % #patrol.waypoints + 1;

  -- and head on out..

  groupMoveCommon ( daemons.units, patrol.waypoints[daemons.dest] );

end

-- Do things at particular times here...

if ( tickCount == 10 ) then

  -- scripted action...

elseif ( tickCount == 20 ) then

  -- another scripted action...

elseif ( tickCount == 30 ) then

  -- etc

end



end



end







if(unitIsinGroup ( daemons.units, lastDeadUnit () )) then

--What happens if an unit dies betweeen the line before and the line after this comment (lastDeadUnit!=lastDeadUnit)?

if ((#daemons.units) > 1) then

removeFromGroup ( daemons.units, lastDeadUnit ())

end



giveResource('gold', 0, 500);

giveResource('stone', 0, 50);

giveResource('wood', 0, 50);

giveResource('food', 0, 50);



end



</unitDied>





</scripts>

</scenario>

What the code should  do (I'll tell only the important things) :
It creates a unit called archer (modiefied standard archer) and to the left of that unit another unit which is called victim (a unit with low HP). The unit victim is killed all the time by the unit archer. When victim dies the timer (tickCount) is incremented and a new victim is created to the right of archer (so victim alternates its position but archer keeps it's position). A group of 8 daemons is also created and "patrols" along some points all the time. The worker can build the standard "defence_tower". When a unit of the group is killed the player gets ressources.

I think my code has a lot of bugs but the most important to me is this one:
When a unit is killed glest creates victim not at the predefined place. Victim is generated lower then the predefined position. WHY? ???

btw. can I do "a=!a;" (a is NOT a) in Lua?

ElimiNator

  • Airship
  • ********
  • Posts: 3,391
  • The MegaGlest Moder.
    • View Profile
Re: Glest tower defense
« Reply #81 on: 20 August 2009, 21:55:38 »
OK a new non .SVN versions out.

Get it a original link.
Get the Vbros': Packs 1, 2, 3, 4, and 5!

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: Glest tower defense
« Reply #82 on: 21 August 2009, 04:41:32 »
My bad, I just realized that two days ago when looking at the new GAE lua. I didn't know it needed [1] for x pos and [2] for y pos. I now completely understand it though.

However, I have a suggestion. It states on the XML page that the show message box function will return NULL. In my opinion, it should return true when the ok button is pressed, so we can show the message, then if it is true (ie: the ok button is pressed) we can start our code. This way we don't get attacked or something while still reading the boxes, and can set up scripts to start once the box is done.

This is pretty common, as I've used it in JS with confirm boxes (yes/no) as they return a bool value depending on reply. On that same topic, peerhaps we need a confirm box. Also, possibly a prompt box (get user input, save to a specified variable). The user input can be used to personalize the scripts (might not work with other languages though).

In lua, not is ~=. So if if you want that WEIRD bit of code you had, it would be written as a~=a. However, that is useless code, since a cannot possibly not equal itself. But maybe a~=b will work! :D
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

silnarm

  • GAE Team
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Glest tower defense
« Reply #83 on: 21 August 2009, 08:39:17 »
However, I have a suggestion...
This is on the tracker as 'pause while lua messages are displayed', or something to that effect. It will get implemented soon.

Quote from: omega
In lua, not is ~=. So if if you want that WEIRD bit of code you had, it would be written as a~=a. However, that is useless code, since a cannot possibly not equal itself. But maybe a~=b will work! :D
Look closly at the operators he used, and where.  you've changed the order of the operators, thus changing the meaning. He wasn't doing a test, he was 'flipping' a boolean's value, which I would have assumed would be done like this,
a = ~a

However, I'm wrong too, '~=' is the 'not equal' operator, but '~' is not the 'not' operator.
It is rather, 'not', so it should be,
a = not a

When a unit is killed glest creates victim not at the predefined place. Victim is generated lower then the predefined position. WHY? ???

When a unit is created from LUA, the engine tries to place it with 2 cells of space around it, if the position you are specifiying does not have such space, a close by location that has got such space will be chosen instead. 

Also, a dead unit still occupies it cell for a little while after dying, so if the archer is killing the victim too quickly, even though you are alternating between two victim positions, it may be that the dead unit from the last tick is blocking the new unit.  You could try adding more victim positions if you think this might be the case.

Quote
btw. can I do "a=!a;" (a is NOT a) in Lua?

See above :)
Glest Advanced Engine - Code Monkey

Timeline | Downloads

me5

  • Guest
Re: Glest tower defense
« Reply #84 on: 21 August 2009, 11:48:20 »
I will try to add more victim positions but could there be another reason because the victim is build at another position when a unit dies for example everytime a daemon is killed the victim unit gets a wrong position (also when the initiate dies). It does not influence the scenario that much because the wrong position is still in the range of the archer but I'd like to know why this happens.

me5

  • Guest
Re: Glest tower defense
« Reply #85 on: 21 August 2009, 15:07:44 »
Silnarm you were right.
I think when another unit than victim dies "a" alternates also. So when a "nonvictim" unit dies "a" becomes true/false (depending on what it was before) and the next time victim dies "a" is alternated again.
=> twice alternating is the same as not to alternate "a". So glest tries to create victim at the same position as before.( I put the "position-test" into the if statement so that "a" is only alternated when victim dies and it worked.) Silnarm in your function "removeFromGroup" there is  "table.remove ( group, i );" what does this exactly do? Does it erase only the value of the array or does it remove the whole element so an array a[3] becomes a[2]? An array in Lua starts at 1, right?
Code: [Select]
function removeFromGroup ( group, unitId )

  for i=1,#group do

if ( group[i] == unitId ) then

  table.remove ( group, i );

  return;

end

  end

Sometimes I get an error "Can not find unit to get position". I think I still have some bugs when dealing with the index of the array. Is it allowed to remove the last element of a table?
When I try to use "<=" in if statements I get an error. (Lua<->XML intermixture??)

silnarm

  • GAE Team
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Glest tower defense
« Reply #86 on: 22 August 2009, 01:21:03 »
Silnarm in your function "removeFromGroup" there is  "table.remove ( group, i );" what does this exactly do? Does it erase only the value of the array or does it remove the whole element so an array a[3] becomes a[2]? An array in Lua starts at 1, right?

I believe table.remove() should indeed remove the element, shuffling higher elements down.  This was to ensure the array didn't get 'gaps' in it.  I haven't had a chance to test this very well yet though...

Quote from: me5
Sometimes I get an error "Can not find unit to get position". I think I still have some bugs when dealing with the index of the array. Is it allowed to remove the last element of a table?

This would seem to indicate we are keeping 'stale' unit ids, so table.remove() may indeed be failing us.  I'll do some tests this weekend and get back to you :)

Quote from: me5
When I try to use "<=" in if statements I get an error. (Lua<->XML intermixture??)

Yes, '<' will confuse the xml parser, you'll have to "turn your logic around",
ie. if you wanted,
a <= b
you would have to do,
b >= a
Glest Advanced Engine - Code Monkey

Timeline | Downloads

hailstone

  • GAE Team
  • Battle Machine
  • ********
  • Posts: 1,568
    • View Profile
Re: Glest tower defense
« Reply #87 on: 22 August 2009, 03:56:38 »
Quote
Yes, '<' will confuse the xml parser
That's annoying. Perhaps external scripts will work. (see http://pgl.yoyo.org/luai/i/dofile )
Glest Advanced Engine - Admin/Programmer
https://sourceforge.net/projects/glestae/

silnarm

  • GAE Team
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Glest tower defense
« Reply #88 on: 22 August 2009, 07:24:37 »
Quote
Yes, '<' will confuse the xml parser
That's annoying. Perhaps external scripts will work. (see http://pgl.yoyo.org/luai/i/dofile )

nope, tried that a while ago, doesn't load them :(
Glest Advanced Engine - Code Monkey

Timeline | Downloads

hailstone

  • GAE Team
  • Battle Machine
  • ********
  • Posts: 1,568
    • View Profile
Re: Glest tower defense
« Reply #89 on: 22 August 2009, 12:03:15 »
I tried it and it works   ;D

Code: (basic_tutorial.xml) [Select]
<startup>
    dofile("gae_scenarios/Tutorials/basic_tutorial/startup.lua")
</startup>

Code: (startup.lua) [Select]
one = 1
two = 2
disableAi(1)
createUnit('castle', 0, startLocation(0))
setCameraPosition(unitPosition(lastCreatedUnit()))
createUnit('farm', 0, startLocation(0))
giveResource('gold', 0, 250)
giveResource('food', 0, 50)
giveResource('wood', 0, 50)
giveResource('stone', 0, 100)
if one <= two then
    showMessage('Welcome', 'GlestBasicTutorial')
    showMessage('WillBeUsingTech', 'GlestBasicTutorial')
    showMessage('NeedWorkers', 'Resources')
end
setDisplayText('ProduceWorkers')
objective= 'produce_worker'

EDIT: I have updated the wikia.
« Last Edit: 22 August 2009, 12:28:49 by hailstone »
Glest Advanced Engine - Admin/Programmer
https://sourceforge.net/projects/glestae/

silnarm

  • GAE Team
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Glest tower defense
« Reply #90 on: 22 August 2009, 12:51:00 »
I tried it and it works   ;D
Code: (basic_tutorial.xml) [Select]
<startup>
    dofile("gae_scenarios/Tutorials/basic_tutorial/startup.lua")
</startup>
...
EDIT: I have updated the wikia.

Ahhh... path relative to the executable... how did I not think of that  :-[

Nice one. This will make things a bit easier to manage!
Glest Advanced Engine - Code Monkey

Timeline | Downloads

me5

  • Guest
Re: Glest tower defense
« Reply #91 on: 22 August 2009, 20:33:40 »
I think I get this error because I test the position of unit before removing it from array. So glest try to find the position of a dead unit whose id is still in the array.
Next question on your code silnarm:
When you create a unit you implement first an array "daemons = {};" and then another one "daemons.units = {};" ? Is this an array with an element which is also an array? ???
Can't I just use "daemons = {};" ?
Code: [Select]
-- Make a group of 8 daemons...

disableAi (1);

daemons = {};

daemons.units = {};

groupOfType ( daemons.units, "daemon", 1, 8, patrol.waypoints[1] );

silnarm

  • GAE Team
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Glest tower defense
« Reply #92 on: 22 August 2009, 23:58:25 »
Next question on your code silnarm:
When you create a unit you implement first an array "daemons = {};" and then another one "daemons.units = {};" ? Is this an array with an element which is also an array? ???
Can't I just use "daemons = {};" ?

Yep. Technically they are 'tables', the one and only data structure LUA supports.  As the only data structure, it is very versatile. They can be used just like the more familiar arrays from other languages, but what the really are is an 'associative array', you can put anything in them, and you can index them with anything, daemons.units is equivalent to daemons["units"].

The way I used the 'top-level' table 'daemons' was as an object, a convenient place to store information about a group of deamons, in this example another table of the unit IDs and the current destination.  It probably seems strange, but it allows you to keep data relating to that group of daemons all in same 'place', so as your script grows it will hopefully still be manageable. If you just use 'daemons' (which is perfectly acceptable) then you need to store their detination somewhere else, and it is not 'logically' tied to them by any means... what happens when you have 15 groups of daemons, each with their own current destination?

I think I get this error because I test the position of unit before removing it from array. So glest try to find the position of a dead unit whose id is still in the array.

That would do it :) You need to remove the unit as soon as it dies...
Code: [Select]
<unitDiedOfType type="deamon">
-- We don't need to find the group the deamon is in, the removeFromGroup () function
-- will search the group specified, removing the unit if found, so if we had our daemon
-- groups in individual tables, all in a table called 'daemons' in a table called 'badGuys',
-- we can just iterate over them all, calling removeFromGroup () on each...
for i=1,#badGuys.daemons do
  removeFromGroup ( badGuys.daemons[i].units, lastDeadUnit () );
end
</unitDiedOfType>

It probably makes sense to have removeFromGroup() return true if it found and removed the unit, so we could stop once we'd found it, to be a little more efficient... but I wouldn't worry about that for now.

I just checked the Wiki actually, there were a couple of errors, the functions lastDeadUnitId() and lastCreatedUnitId() don't exist, and are actually lastDeadUnit() and lastCreatedUnit().  Check that, if you are using lastDeadUnitId() the script will fail silently, you'll get no error message.
Glest Advanced Engine - Code Monkey

Timeline | Downloads

me5

  • Guest
Re: Glest tower defense
« Reply #93 on: 24 August 2009, 14:35:48 »
I spend a whole day on this bug and still havn't fixed it. I hope you guys can help me.
Sometimes the group of units stops to walk.
The funny thing is when I use these waypoints ({15,15}, {70,15}, {70,20}, {15,20}, {10,10}) only the third wave of attackers stops at the second waypoint. If I use these waypoints ({120,91}, {49,91}, {49,30}, {5,30}) the second wave of attackers stops also at the second waypoint.
Code: [Select]
<?xml version="1.0" standalone="yes" ?>

<scenario>

<difficulty value="0"/>

<players>

<player control="human" faction="defence" team="1"/>

<player control="cpu" faction="attack" team="2"/>

<player control="closed"/>

<player control="closed"/>

</players>

<map value="TD_like_4"/>

<tileset value="forest"/>

<tech-tree value="td_6"/>

<default-resources value="false"/>

<default-units value="false"/>

<default-victory-conditions value="false"/>

<scripts>

<startup>





----------------------------------------------------------------------------

--                Unit Creation and Group Management                      --

----------------------------------------------------------------------------

-- creates a unit and puts its id in group

function createAndGroup ( group, type, faction, pos )

  createUnit ( type, faction, pos );

  group[#group+1] = lastCreatedUnit ();

end

-- create a group of num units of a single unit type

function groupOfType ( group, type, faction, num, pos )

  for i=1,num do createAndGroup ( group, type, faction, pos ) end

end

-- create a group of units of different types

function groupFromTypes ( group, types, faction, pos )

  for i=1,#types do createAndGroup ( group, types[i], faction, pos ) end 

end

-- remove a unit id from a group

function removeFromGroup ( group, unitId )

  for i=1,#group do

if ( group[i] == unitId ) then

  table.remove ( group, i );

  return;

end

  end

end



-- checks if unit belongs to group

function unitIsinGroup ( group, unitId )

  for i=1,#group do

if ( group[i] == unitId ) then

 

  return true;



end

  end

end



----------------------------------------------------------------------------

--                          Group Commands                                --

----------------------------------------------------------------------------

-- give a group of units move commands to location

function groupMoveCommon ( units, location )

  for i=1,#units do givePositionCommand ( units[i], "move", location ) end

end

-- give a group of units move commands to distinct locations

function groupMoveSpecific ( units, locations )

  for i=1,#units do givePositionCommand ( units[i], "move", locations[i] ) end

end

-- give a group of units attack commands to location

function groupAttack ( units, pos )

  for i=1,#units do givePositionCommand ( units[i], "attack", pos ) end

end

----------------------------------------------------------------------------

--                             Geometry                                   --

----------------------------------------------------------------------------

-- is pos in rectangle

function pointIsIn ( pos, rectangle )

  if ( pos[1] >= rectangle[1] and rectangle[3] > pos[1]

  and pos[2] >= rectangle[2] and rectangle[4] > pos[2] ) then

return true;

  end

  return false;

end

-- returns a rectangle around the point 'pos'

function areaAround ( pos )

  return { pos[1]-5, pos[2]-5, pos[1]+5, pos[2]+5 };

end





----------------------------------------------------------------------------

--                             Start-Up                                   --

----------------------------------------------------------------------------

-- the patrol table will store the waypoints and regions around them

patrol = {};

patrol.waypoints = {{15,15}, {70,15}, {70,20}, {15,20}, {10,10} };



patrol.regions = {};

for i=1,#patrol.waypoints do

  patrol.regions[#patrol.regions+1] = areaAround(patrol.waypoints[i]);

end

-- Make a group of 8 daemons...

disableAi (1);

daemons = {};

daemons.units = {};

groupOfType ( daemons.units, "daemon", 1, 8, patrol.waypoints[1] );

-- start them on their way...

groupMoveCommon ( daemons.units, patrol.waypoints[2] );

-- remember where they are currently going...

daemons.dest = 2; -- index of current target



tickCount = 0;











disableAi(1)

createUnit ( "castle2", 0, {10,30} );

createUnit('worker', 0, {startLocation(0)[1],startLocation(0)[2]});

createUnit('defense_tower', 0, {50,24});

createUnit('defense_tower', 0, {40,24});

createUnit('defense_tower', 0, {53,24});

createUnit('defense_tower', 0, {44,24});

createUnit('defense_tower', 0, {36,24});

createUnit('defense_tower', 0, {50,32});

createUnit('defense_tower', 0, {40,32});

createUnit('defense_tower', 0, {53,32});

createUnit('defense_tower', 0, {44,32});

createUnit('defense_tower', 0, {36,32});

createUnit('defense_tower', 0, {startLocation(0)[1]-4,startLocation(0)[2]});

createUnit ( "initiate", 1, startLocation(1) );

givePositionCommand(lastCreatedUnit(1), 'move', startLocation(0));

createUnit ( "archer", 0, {38,55} );



createUnit ( "victim", 1, {30,55} );

setCameraPosition({30,55});

giveResource('gold', 0, 2000);

giveResource('stone', 0, 100);

giveResource('wood', 0, 2000);

giveResource('food', 0, 500);



startTime = os.time();



a=true;

wave=0;

</startup>



 

<unitDied>



timeSinceStart = os.time() - startTime;

x=30;

--spawnedgroup;

<!--

a= not a;



if (a==true) then

x=30

else

x=46

end

-->

alone= {};

setDisplayText(#alone)

       

if(unitIsinGroup ( daemons.units, lastDeadUnit () )) then

--alone= 6;

--setDisplayText(#alone)

--What happens if an unit dies betweeen the line before and the line after this comment (lastDeadUnit!=lastDeadUnit)?

if ((#daemons.units) > 1) then

removeFromGroup ( daemons.units, lastDeadUnit ())

elseif ((#daemons.units) == 1) then

vitality =false;

removeFromGroup ( daemons.units, lastDeadUnit ())

diedat= tickCount;

wave=wave+1;

createUnit ( "summoner", 1, startLocation(1) );



end



giveResource('gold', 0, 500);

giveResource('stone', 0, 50);

giveResource('wood', 0, 50);

giveResource('food', 0, 50);



end



if ( lastDeadUnitName()  == "victim"  ) then

 

a = not a;



if (a==true) then

x=30

else

x=46

end



 

createUnit ( "victim", 1, {x,55} );





tickCount = tickCount + 1;





if( (#daemons.units) >= 1 ) then --check how big the group is because if there are 0 units I will get an error

-- the value has to be 2 because the first unit is created at the 2nd place of the array

-- Check if daemons have reached target...

local cur_pos = unitPosition(daemons.units[1]);

local cur_dest = patrol.regions[daemons.dest];

if ( pointIsIn(cur_pos, cur_dest) ) then

-- we have arrived, set next destination...

daemons.dest = daemons.dest % #patrol.waypoints + 1;

-- and head on out..

groupMoveCommon ( daemons.units, patrol.waypoints[daemons.dest] );

end

-- Do things at particular times here...

if ( tickCount == 10 ) then

  --spawnedgroup

elseif ( tickCount == 20 ) then

  -- another scripted action...

elseif ( tickCount == 30 ) then

  -- etc

end



end



end







if ((vitality==false) ) then

if (((tickCount- diedat) == 10) and (wave==1)) then

groupOfType ( daemons.units, "battlemage", 1, 8, patrol.waypoints[1] );

groupMoveCommon ( daemons.units, patrol.waypoints[2] );

elseif (((tickCount- diedat) == 10) and (wave==2)) then

groupOfType ( daemons.units, "battlemage", 1, 8, patrol.waypoints[1] );

groupMoveCommon ( daemons.units, patrol.waypoints[2] );

elseif (((tickCount- diedat) == 10) and (wave==3)) then

--groupOfType ( daemons.units, "initiate", 1, 8, patrol.waypoints[1] );

--groupMoveCommon ( daemons.units, patrol.waypoints[2] );

end

end



</unitDied>





</scripts>

</scenario>

I guess there is no "unitKill(unid)" command or something similar?

me5

  • Guest
Re: Glest tower defense
« Reply #94 on: 24 August 2009, 20:07:58 »
FIXED ;D
I did not reset the destination to 2 ("daemons.dest = 2;")  >:(

PolitikerNEU

  • Guest
Re: Glest tower defense
« Reply #95 on: 24 August 2009, 20:45:20 »
Couldn't you try encapsulating the lua-Script in
Code: [Select]
<![CDATA[ Script
  blabla
]]>
?
Then you could use < and >

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: Glest tower defense
« Reply #96 on: 25 August 2009, 04:25:54 »
BTW, just a little bit off topic, is it possible to use givePositionCommand() to give a patrol command? I think that since it is a 'position' command like walk and attack, it should work... Must test. I have great plans for a spy mission in military!

I think perhaps GAE needs a way to place a unit in an EXACT location without the 2 cell margin if it is possible. If the location is not possible, it will place as normal, etc;

Also, perhaps Glest needs a give any command function, to give a command. It could just give commands that do not need positions, since I imagine givePositionCommand will do that.
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

hailstone

  • GAE Team
  • Battle Machine
  • ********
  • Posts: 1,568
    • View Profile
Re: Glest tower defense
« Reply #97 on: 25 August 2009, 05:18:14 »
Couldn't you try encapsulating the lua-Script in
Code: [Select]
<![CDATA[ Script
  blabla
]]>
?
Then you could use < and >

I haven't tested. TinyXML says it doesn't support DOCTYPE so I'm not sure if it will accept any other 'special' tags.
Glest Advanced Engine - Admin/Programmer
https://sourceforge.net/projects/glestae/

silnarm

  • GAE Team
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Glest tower defense
« Reply #98 on: 25 August 2009, 09:01:37 »
Also, perhaps Glest needs a give any command function, to give a command. It could just give commands that do not need positions, since I imagine givePositionCommand will do that.

Every command needs some information though.  Build Command, build what?  Upgrade Command, which upgrade? Harvest command, harvest what/where?  Gaurd command, gaurd what/where? etc.

Likely candidates to join move and attack in the 'Position Command' family are Guard, Harvest, Patrol, and Repair.  But many of them will need alternatives, a 'Unit Command' if you will, to guard or repair a specific unit, harvest might be a special case, if you don't care to tell it where to go harvest, you might just want to tell it what to go harvest... etc.

Couldn't you try encapsulating the lua-Script in
Code: [Select]
<![CDATA[ Script
  blabla
]]>
?
Then you could use < and >

I haven't tested. TinyXML says it doesn't support DOCTYPE so I'm not sure if it will accept any other 'special' tags.

Yeah, this should work OK (even with TinyXML, I think). Personally I'd prefer if the code wasn't in with the XML anyway, so I'll be using dofile() now :)
Glest Advanced Engine - Code Monkey

Timeline | Downloads

me5

  • Guest
Re: Glest tower defense
« Reply #99 on: 25 August 2009, 09:35:59 »
Is it possible to mix text from the XML file and the one from lua file.
I mean I have an integer variable a (a=3;) and a text "Hello number:" in my lua language file (hello =Hello number:).
Now I want to display this text: "Hallo number: 3".
I tried: "setDispayText("hello" .. a)" but it didn't work. Or is there another way to do this. When I just use text from XML file I get this 3questionmarks (??? mytext ???) at the beginning and the end.