Prayer of Pity to the Event Gods!

Discuss and post your mods and scenarios here for others to download.

Moderator: Vic

User avatar
GunnyJarhead
Posts: 27
Joined: Mon Jul 16, 2012 7:31 pm
Contact:

Prayer of Pity to the Event Gods!

Post by GunnyJarhead »

Hi Guys, I'm a long time player of several years now. I play exclusively single player. Anyway...there are a lot of things I have been able to mod..such as Land, LT, Units, Rule-variables (although I don't understand everyone of them!) etc... However coding still eludes me..no it doesn't elude me..it absolutely kicks my ass. Believe me when I say that I have read and reread every post in here about coding...but lord help me I'm just not wired that way!

I have created a very large world (200x160) in which I have taken the time to include Continents, Archipelagos, Mountain Ranges, rivers that follow geographic principles, swamps in the right logical places, Rain forest and rain shadows dictated by geography etc. but id love some help in other areas (such as coding) so here goes...if any of you can Teach me on the side..or just simply write a few short codes for me to insert I would be very grateful!

I have the blank map....I would like to be able to in the event screen execute the following events.

1. Random Placement of Raw and Oil for a 200x160.

2, Random placement of Cities for a 200x160.

3. Set Weather for a 200x160 ( I do not have it divided into zones...but would love to)

Please..Please..I know some of you Coders could probably write these events in your sleep...your help would make an old jarhead very happy in completing his world!

By the way I LOVE the ERR_EAI_Leaders mod...it really slows the game down to my taste yet make it very challenging to balance feeding the General and The Bean Counters.

Thanks.

Some people are still alive only because it is illegal to kill them.
User avatar
ernieschwitz
Posts: 4240
Joined: Tue Sep 15, 2009 3:46 pm
Location: Denmark

RE: Prayer of Pity to the Event Gods!

Post by ernieschwitz »

You have posted insufficient information to do the events.

How many cities/resources should there be, how big should the be, and how well distributed... events only do what you tell them to do, and these are things they have to know exactly.

I won´t code it btw, mostly because my expertise is not the random maps or random placements of stuff. I think there are people out there more qualified than me at that...
Creator of High Quality Scenarios for:
  • Advanced Tactics Gold
    DC: Warsaw to Paris
    DC: Community Project.
Try this Global WW2 Scenario: https://www.vrdesigns.net/scenario.php?nr=280
User avatar
ernieschwitz
Posts: 4240
Joined: Tue Sep 15, 2009 3:46 pm
Location: Denmark

RE: Prayer of Pity to the Event Gods!

Post by ernieschwitz »

Oh yes, and then there is the issue of naming all those cities... what should they be called...
Creator of High Quality Scenarios for:
  • Advanced Tactics Gold
    DC: Warsaw to Paris
    DC: Community Project.
Try this Global WW2 Scenario: https://www.vrdesigns.net/scenario.php?nr=280
User avatar
Twotribes
Posts: 6466
Joined: Fri Feb 15, 2002 10:00 am
Location: Jacksonville NC
Contact:

RE: Prayer of Pity to the Event Gods!

Post by Twotribes »

ORIGINAL: ernieschwitz

Oh yes, and then there is the issue of naming all those cities... what should they be called...
Bella woods and such )
Favoritism is alive and well here.
User avatar
GunnyJarhead
Posts: 27
Joined: Mon Jul 16, 2012 7:31 pm
Contact:

RE: Prayer of Pity to the Event Gods!

Post by GunnyJarhead »

Hmmm...see...I told you I don't know how to code!

How many should there be..I have no idea, until it feels right i guess. LOL [:D]

I was able to "execute this event now", with the "Random : Place Crate" event on a blank map. Below.

0) SETVAR: TempVar9 = CheckMapWidth
1) SETVAR: TempVar9 * CheckMapHeight
2) SETVAR: TempVar9 / 200
3) LOOPER: TempVar10 FROM 0 TO 100
4) SETVAR: TempVar0 = CheckMapWidth
5) SETVAR: TempVar0 * CheckRandomPercent
6) SETVAR: TempVar0 / 100
7) SETVAR: TempVar1 = CheckMapHeight
8) SETVAR: TempVar1 * CheckRandomPercent
9) SETVAR: TempVar1 / 100
10) CHECK: TempVar9 > 0
11) CHECK: CheckLocTypeXY(TempVar0, TempVar1) == -1
12) CHECK: CheckLandscapeType(TempVar0, TempVar1) > 1
13) CHECK: CheckHexOwner(TempVar0, TempVar1) == -1
14) EXECUTE: ExecSetSpecial(43, 0, TempVar0, TempVar1)
15) SETVAR: TempVar9 - 1
16) EXECUTE: ExecHexActionCard(TempVar0, TempVar1, 1)
17) EXECUTE: AI_SetAIVP(TempVar0, TempVar1, -1, 1)
18) END CHECK
19) END CHECK
20) END CHECK
21) END CHECK
22) END LOOPER

It did place crates..but very few and far between. So I ran it again, and it added even more crates, I did this a few times (imagining that they were Cities instead of Crates) until I got what I thought was a good distribution. I tried to changes the code above to place cities instead of crates..but never could get it to do it.

I never could get it to place Raw and Oil doing "execute the event now" using "Random : Place Raw and Oil"...this worked to an extent. Id did place the R&O but only in a very small section of the 200x160 map. It placed it only in the upper left hand corner. Once again I could continue to execute the event until it felt right.

0) LOOPER: TempVar0 FROM 0 TO CheckMapWidth
1) LOOPER: TempVar1 FROM 0 TO CheckMapHeight
2) CHECK: CheckSlot(TempVar0, TempVar1, 0) == 1
3) EXECUTE: ExecChangeLocationType(TempVar0, TempVar1, 2, 8)
4) EXECUTE: ExecSetLandscape(TempVar0, TempVar1, 5)
5) EXECUTE: ExecSetSprite(TempVar0, TempVar1, 0)
6) END CHECK
7) CHECK: CheckSlot(TempVar0, TempVar1, 0) == 2
8) EXECUTE: ExecChangeLocationType(TempVar0, TempVar1, 3, 8)
9) EXECUTE: ExecSetLandscape(TempVar0, TempVar1, 0)
10) EXECUTE: ExecSetSprite(TempVar0, TempVar1, 0)
11) END CHECK
12) END LOOPER
13) END LOOPER


I think that if I knew what to change to get these to Cover the Map and could identify where to change what it places..it would be a great start.

Thanks for replying
Some people are still alive only because it is illegal to kill them.
GrumpyMel
Posts: 864
Joined: Fri Dec 28, 2007 8:37 pm

RE: Prayer of Pity to the Event Gods!

Post by GrumpyMel »

Alot of details you need to map out. To point you in the right direction (I think), you would need to:

- Do a check to make sure it was the first turn, so that your event wouldn't keep getting processed every turn after that.
- Setup variables to use as counters for each location type you want to add.
- Add a loop for each location type that did the following until the counter variable reached the number that you want..
-- Generate 2 random numbers that you can use for X and Y coordinates of a hex that fits within the boundaries of your map.
-- Do whatever logic checks you need to do (right terrain type, distance from other objects, etc) to make sure the coordinates you generated are valid to plop down that location type.
--Execute  the editor function for adding that location type (you could probably use the counter for naming, if you didn't care much about being fancy...."City 1", etc)
-- Increment your counter variable by 1 and go back to the start of your loop.

I'm sure there may be more elegant methods of doing it, but the above is a brute force methodology that should with a bit of tweaking, work.

P.S. I'm also not real experienced with doing random maps and object placement. I'm used to working more with historical scenarios.


GrumpyMel
Posts: 864
Joined: Fri Dec 28, 2007 8:37 pm

RE: Prayer of Pity to the Event Gods!

Post by GrumpyMel »

ORIGINAL: GunnyJarhead

Hmmm...see...I told you I don't know how to code!

How many should there be..I have no idea, until it feels right i guess. LOL [:D]

I was able to "execute this event now", with the "Random : Place Crate" event on a blank map. Below.

0) SETVAR: TempVar9 = CheckMapWidth
1) SETVAR: TempVar9 * CheckMapHeight
2) SETVAR: TempVar9 / 200
3) LOOPER: TempVar10 FROM 0 TO 100
4) SETVAR: TempVar0 = CheckMapWidth
5) SETVAR: TempVar0 * CheckRandomPercent
6) SETVAR: TempVar0 / 100
7) SETVAR: TempVar1 = CheckMapHeight
8) SETVAR: TempVar1 * CheckRandomPercent
9) SETVAR: TempVar1 / 100
10) CHECK: TempVar9 > 0
11) CHECK: CheckLocTypeXY(TempVar0, TempVar1) == -1
12) CHECK: CheckLandscapeType(TempVar0, TempVar1) > 1
13) CHECK: CheckHexOwner(TempVar0, TempVar1) == -1
14) EXECUTE: ExecSetSpecial(43, 0, TempVar0, TempVar1)
15) SETVAR: TempVar9 - 1
16) EXECUTE: ExecHexActionCard(TempVar0, TempVar1, 1)
17) EXECUTE: AI_SetAIVP(TempVar0, TempVar1, -1, 1)
18) END CHECK
19) END CHECK
20) END CHECK
21) END CHECK
22) END LOOPER

It did place crates..but very few and far between. So I ran it again, and it added even more crates, I did this a few times (imagining that they were Cities instead of Crates) until I got what I thought was a good distribution. I tried to changes the code above to place cities instead of crates..but never could get it to do it.

I never could get it to place Raw and Oil doing "execute the event now" using "Random : Place Raw and Oil"...this worked to an extent. Id did place the R&O but only in a very small section of the 200x160 map. It placed it only in the upper left hand corner. Once again I could continue to execute the event until it felt right.

0) LOOPER: TempVar0 FROM 0 TO CheckMapWidth
1) LOOPER: TempVar1 FROM 0 TO CheckMapHeight
2) CHECK: CheckSlot(TempVar0, TempVar1, 0) == 1
3) EXECUTE: ExecChangeLocationType(TempVar0, TempVar1, 2, 8)
4) EXECUTE: ExecSetLandscape(TempVar0, TempVar1, 5)
5) EXECUTE: ExecSetSprite(TempVar0, TempVar1, 0)
6) END CHECK
7) CHECK: CheckSlot(TempVar0, TempVar1, 0) == 2
8) EXECUTE: ExecChangeLocationType(TempVar0, TempVar1, 3, 8)
9) EXECUTE: ExecSetLandscape(TempVar0, TempVar1, 0)
10) EXECUTE: ExecSetSprite(TempVar0, TempVar1, 0)
11) END CHECK
12) END LOOPER
13) END LOOPER


I think that if I knew what to change to get these to Cover the Map and could identify where to change what it places..it would be a great start.

Thanks for replying

In your first code example TempVar10 is the counter for how many crates you are seting, so it's setup to loop through your crate setting 100 times (meaning 100 crates maximum). Tempvar9 looks like it's used to reduce that number for smaller maps to make sure that there isn't more then 1 crate for every 200 hex's on the map.

The second example looks like it's using a Slot to control which area of the map stuff gets generated...if I'm reading it right (doing this from memory) it's looking for Area 0 slots that are painted 1 or 2.....or I could have it reversed and it's Area 1 and 2 slots that are painted with a 0. Anyway, that's why it's only generating stuff on part of your map....at least I believe that's it....pretty rusty with the editor.





lancer
Posts: 2963
Joined: Tue Oct 18, 2005 8:56 am

RE: Prayer of Pity to the Event Gods!

Post by lancer »

G'day Gunny,

This is actually trickier to do than it looks.

You'd need to take into account terrain as you don't want cities on top of mountains nor do you want resources in the ocean, for example.

Then you'd need to consider spacing. With a pure random distribution it would be possible to end up with your cities or resources all bunched up in one little corner of the map.

Next would be what people inhabit what cities? You'll notice on a normal random map that cities with similiar types of people are roughly grouped together. Not much good being German if all the german cities have been shotgunned here there and everywhere.

Resource distribution needs to be balanced in some manner so that all the oil isn't on one side of the map and the raw on the other.

What you're attempting to do here requires a fair bit of time and effort.

Cheers,
Lancer
User avatar
GunnyJarhead
Posts: 27
Joined: Mon Jul 16, 2012 7:31 pm
Contact:

RE: Prayer of Pity to the Event Gods!

Post by GunnyJarhead »

I'm willing to put in the time and effort if I just understood the jargon! Well Dang...I guess I'll keep plugging away!
Some people are still alive only because it is illegal to kill them.
User avatar
GunnyJarhead
Posts: 27
Joined: Mon Jul 16, 2012 7:31 pm
Contact:

RE: Prayer of Pity to the Event Gods!

Post by GunnyJarhead »

OK...small breakthrough I took the Place Raw and Oil and was able to change LocType to City and Change the Landscape Type to Urban. It placed them on the map as I was hoping.

Now..since it is a 200x10 map it is still only placing them them in a small upper left hand corner...not hitting the rest of the map. Working on trying to figure that out now.
Some people are still alive only because it is illegal to kill them.
User avatar
ernieschwitz
Posts: 4240
Joined: Tue Sep 15, 2009 3:46 pm
Location: Denmark

RE: Prayer of Pity to the Event Gods!

Post by ernieschwitz »

Making the landscapetype to urban won´t make them into locations. But at least you´ve come some way.. I agree with Lancer this is no simple process...
Creator of High Quality Scenarios for:
  • Advanced Tactics Gold
    DC: Warsaw to Paris
    DC: Community Project.
Try this Global WW2 Scenario: https://www.vrdesigns.net/scenario.php?nr=280
lancer
Posts: 2963
Joined: Tue Oct 18, 2005 8:56 am

RE: Prayer of Pity to the Event Gods!

Post by lancer »

G'day Gunny,

You have to fight your way into the editor. Put your big, ambitious plans up on the shelf and start small.

Use the default 20 x 20 map in the editor.

Write an event from scratch.

What you want is a basic loop structure that checks every hex on the map. Like this...

loop temp1 from 0 to CheckMapWidth
loop temp2 from 0 to CheckMapHeight
(inside loop structure - put your code stuff here)
end loop
end loop


Inside the loop structure you then run a quick check to see if that hex rings a bell with a random number, like this...

temp3 = checkRandomPercent
check temp3 < threshold value (eg. 10)
(inside check)
end check


Now if you're random chance comes up, in the above example, a 10% chance, you then plonk down a structure. The loop structure above gives you the hex coordinates - temp1 (x) and temp 2 (y) so this is pretty easy. You put the 'doing stuff code' inside the check as you only want it to happen when you get a random number under your threshold.

ExecSetLandscape(temp1,temp2,New LT#)


this function is found in the 'Exec' list under 'Hex and Areaslots'. The New LT# refers to the index number for the landscape type you want to use.

Find these by exiting the code part of the editor and pressing the 'Landscape' button (up the top left amongst all the other little buttons). For example Plains are '0' and sea is '1'.

Have a play around with this and see how you go. Once it's working try plonking down some 'Location types'. Find these under 'LT' (top left, all those buttons). Eg. Raw level 1 mine is '2'. Use this function to do this (found in the same place as above)...

ExecChangeLocationType(temp1,temp2,New Loctype#, People#)

People is who actually owns the location. Neutral means nobody does. Guess where you find the list of People id? The mess of little buttons again, under 'Ppl'. Everything has an Id #.


Cheers,
Lancer
User avatar
GunnyJarhead
Posts: 27
Joined: Mon Jul 16, 2012 7:31 pm
Contact:

RE: Prayer of Pity to the Event Gods!

Post by GunnyJarhead »

Lancer,

Thanks....I know you have other things to do...but I really appreciate the help. Your examples with explanations are helpful.

Ok I did as you said...and I understand the event code for those parts now except......that when I run the code I get a Loctypes or LandTypes placed on the map in a diagonal line. Sample 1. What I wrote is Sample 2.

Its not scattered over the map.
Image

Image
Attachments
Sample1.jpg
Sample1.jpg (120.96 KiB) Viewed 113 times
Some people are still alive only because it is illegal to kill them.
User avatar
GunnyJarhead
Posts: 27
Joined: Mon Jul 16, 2012 7:31 pm
Contact:

RE: Prayer of Pity to the Event Gods!

Post by GunnyJarhead »

Sample 2

Image



I'll keep playing with it that way. On another note....I have been modding some existing code...im almost there....[:D]

Thanks


Image
Attachments
Sample2.jpg
Sample2.jpg (31.63 KiB) Viewed 113 times
Some people are still alive only because it is illegal to kill them.
lancer
Posts: 2963
Joined: Tue Oct 18, 2005 8:56 am

RE: Prayer of Pity to the Event Gods!

Post by lancer »

G'day Gunny,

You've got your baseball cap on backwards. Look at line 0 and line 1 above, spot the problem?

Your loop controller on Line 0 uses the same variables (eg. tempVar1) as the looper on line 1. This isn't good 'cause the variables control what the loops do. If you have the same set of variables trying to control both loops then you'll get schizophrenic results like your map above.

To fix ituse variables that are different to anything used elsewhere (as a general rule you don't want individual variables to do more than one thing at a time, they are simple folk).

Also your loops need to start at '0' 'cause that's where the hex coords start on a map (0,0)

so...

Looper temp 0 from 0 to checkmapheight
Looper temp 1 from 0 to checkmapwidth

Cheers,
Lancer
GrumpyMel
Posts: 864
Joined: Fri Dec 28, 2007 8:37 pm

RE: Prayer of Pity to the Event Gods!

Post by GrumpyMel »

Lancer is right.

You are using your 2 Loops to generate the X, Y coordinates of the hex you want to work on. By using his method, you step through every hex in the map and roll a random chance to see if something is there.

So, first Loop gives you the X coordinate....

So it looks like this.. Looper [value you use to store x]&nbsp; from [Hex Row you Want to start at for X] to [Hex Row you Want to End at for X]

If you know the exact size of the map you are working with, you can actualy use numbers instead of variables, if it makes it easier to understand what's going on there....

So... Looper: TempVar0 (You are using this to store X coordinate) from 0 to 20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Looper: TempVar1 (You are using this to store Y coordinate) from 0 to 20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (Do something at the current X,Y coordinates)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Looper:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Looper

Each time the Looper gets to it's own End Looper (see how they are nested, one inside the other) it increments the value in the variable you were using for it by 1 and goes back to beginning of the loop and repeats the procedure....until it gets to the highest value you've told it to use, then it stops)

So if you think about what it's doing when it executes that code...

The first loop tells it to go through every row on the map starting at hex row 0 and do something....

&nbsp;&nbsp;&nbsp;&nbsp; .....that something is to go down each column in the current row (the second loop) and do something....
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ......that something is to determine if something is there.

You really only need to user variables to substitute for something that you expect to change like the X,Y coordinates of the hex you are currently checking or the value of the random number you just rolled....for something that you know like the number of the hex row that you'd like to start at when checking something you can just use the actual numbers. I've found that helps make things alot easier to understand when starting to code. When you get more experienced, you can make more use of variables and other functions....which helps make it more reusable in different situations (like changing the map size) without needing to make any changes to it.

It can also help you keep track of things when you put a comment above each line of code to explain what you think it's doing. That way you can at least see if your logic is sound. When you get more experienced, you can use comments less...but they still can be very helpfull if you ever have to go back to an event that you wrote awhile back and are trying to remember exactly how it works.

Another trick I use to help me keep things straight is at the start of my event code use comments to spell out exactly what each variable I'm using will be used to store....for example

Comment: TempVar0 = The X Coordinate on the Map
Comment: TempVar1 = The Y Coordinate on the Map

That way it helps avoid mix ups about using the wrong variable when writing your code, as you always have a handy reference.
User avatar
ernieschwitz
Posts: 4240
Joined: Tue Sep 15, 2009 3:46 pm
Location: Denmark

RE: Prayer of Pity to the Event Gods!

Post by ernieschwitz »

You can even cut some corners, if you are working with a map you don´t know the size of, or do know the size of, and simply can´t be bothered to check the maps width and height. You simply make the end x variable be CheckMapWidth, and the y end variable be CheckMapHeight.

Which i can see has been done :)
Creator of High Quality Scenarios for:
  • Advanced Tactics Gold
    DC: Warsaw to Paris
    DC: Community Project.
Try this Global WW2 Scenario: https://www.vrdesigns.net/scenario.php?nr=280
GrumpyMel
Posts: 864
Joined: Fri Dec 28, 2007 8:37 pm

RE: Prayer of Pity to the Event Gods!

Post by GrumpyMel »

ORIGINAL: ernieschwitz

You can even cut some corners, if you are working with a map you don´t know the size of, or do know the size of, and simply can´t be bothered to check the maps width and height. You simply make the end x variable be CheckMapWidth, and the y end variable be CheckMapHeight.

Which i can see has been done :)

Yes, but many times I think it starts to get confusing for folks who are inexperienced and often uncomfortable with coding to see alot of functions and variables crammed onto a page.

Rather then try to learn everything at once, or even try to code things in the most efficient manner....usualy you are better off just learning one simple step, getting it to work the way you intend....and once you are comfortable with it, improve on it and make it more flexible and efficient. At least I know that's what really helped me when I first started working with code.





User avatar
ernieschwitz
Posts: 4240
Joined: Tue Sep 15, 2009 3:46 pm
Location: Denmark

RE: Prayer of Pity to the Event Gods!

Post by ernieschwitz »

You may be right... I am too much of a perfectionist myself, so, it would be a failure in my traits i guess to require the same of others.
Creator of High Quality Scenarios for:
  • Advanced Tactics Gold
    DC: Warsaw to Paris
    DC: Community Project.
Try this Global WW2 Scenario: https://www.vrdesigns.net/scenario.php?nr=280
User avatar
GunnyJarhead
Posts: 27
Joined: Mon Jul 16, 2012 7:31 pm
Contact:

RE: Prayer of Pity to the Event Gods!

Post by GunnyJarhead »

Afternoon Guys,

I have made some significant progress! I am now able to:

Randomly Change a Landscape, Location, etc...I can even control where these random event occur based on several factors such as previous location or landscape type, and even based on slots! I'm slowly getting closer to what I'm after.

Now I think I'm gonna try and figure out how to rename locations, and randomly change there owners etc!

Whoo Hoo!

Thanks for the help guys! Keep it coming...please!
Some people are still alive only because it is illegal to kill them.
Post Reply

Return to “Mods and Scenarios”