Here's a conversation I had with CariElf regarding how resources are randomly placed at the start of a map.
21:59 <Heavenfall> Can I ask exactly how resources are spawned when creating a map? I've been experimenting with the <rarity> tag but I get completely contradicting results all the time
22:05 <Cari_Elf> hmm
22:05 <Cari_Elf> I'm not finding the functions that used to do it
22:10 <Heavenfall> I don't even know if a higher number means more spawn or less spawn, that's how contradicting the results are
22:10 <Cari_Elf> it should mean more
22:10 <Cari_Elf> I found the function that I think is doing it
22:11 <Cari_Elf> it tries to place the resources within a certain distance of player's starting positions
22:11 <Cari_Elf> even the ones that aren't used
22:12 <Heavenfall> that... makes no sense... if I have rarity 700, I can get one to spawn right next to someone, and one to spawn half a map away from anyone
22:13 <Heavenfall> and if I set rarity to 5, I'll get one spawn... and if I set it to 300 I'll get one spawn... that's why I'm confused
22:15 <Cari_Elf> hmm
22:15 <Cari_Elf> this is weird
22:15 <Cari_Elf> ok
22:15 <Cari_Elf> you're talking about the rarity of the actual resource type, right?
22:15 <Cari_Elf> I thought you meant the frequency of the resource objects
22:16 <Heavenfall> well that's what I thought rarity was
22:16 <Heavenfall> if not, then what controls how often and where stuff spawns?
22:16 <Heavenfall> and by stuff I mean resourcenodes, that I can build improvements on
22:17 <Cari_Elf> no, rarity is actually for the resource types
22:17 <Cari_Elf> like the bees are less common than fertile ground
22:17 <Cari_Elf> for the actual placement of resource nodes, that appears to be dependent on the number of land tiles
22:18 <Cari_Elf> ULONG ulBaseResources = ulLandTiles/200;
22:18 <Heavenfall> does it interact with the <PreferredTerrain> tag?
22:19 <Heavenfall> or how would you recommend I go about introducing a new resource into the game? let's say I want 1 at the least on every map
22:19 <Cari_Elf> the preferred terrain helps choose the tile
22:20 <Cari_Elf> I think
22:20 <Heavenfall> and is <HarvestType> involved? I'm just groping in the dark here
22:20 <Cari_Elf> no
22:20 <Cari_Elf> it helps pick the resource based on terrain
22:20 <Cari_Elf> once it has the empty tile
22:20 <Cari_Elf> let me check harvest type
22:21 <Cari_Elf> I think that has to do with what tech you need to build on it
22:22 <Cari_Elf> now do you want to introduce a new variety of like a food resource or do you want to create an entirely new resource?
22:22 <Cari_Elf> with one or more varieties?
22:22 <Heavenfall> basically I have 5-6 new resource types I would like to add to the game
22:22 <Heavenfall> which are the mount resources
22:22 <Heavenfall> brutes, skaths, umberdoths, primal bears, bears, drakes
22:23 <Heavenfall> and on a small map, I would like at least 1 of each to spawn
22:23 <Heavenfall> they are new resources, yes
22:24 <Cari_Elf> seems to me that there are ones that you could imitate
22:25 <Cari_Elf> yeah like horses?
22:27 <Heavenfall> yeah, but I won't learn anything about the process from doing that, which means less control
22:27 <Heavenfall> besides, a small map almost never have a warg OR a horse resourcenode
22:27 <Cari_Elf> that's because their terrain type isn't very common
22:28 <Cari_Elf> I had to ask Brad about that one
22:28 <Heavenfall> okay so its definitely limited by preferredterrain
22:28 <Cari_Elf> yeah, if there isn't a lot of tiles with their terrain, it won't be as likely to be picked
22:29 <Cari_Elf> it's more of an indirect limitation
22:29 <Heavenfall> and its roughly 1 per 200 tiles of that particular terrain?
22:30 <Heavenfall> and rarity only decides if its randomly included close to the spawn?
22:30 <Cari_Elf> no, it gets the tottal number of resource hoards from dividing the number of land tiles by 200
22:30 <Cari_Elf> then it starts going in a loop and it calls a function GetRandomEmptyLandTile, which excludes hills
22:31 <Cari_Elf> once it has a tile for that resource (if it doesn't give up to save time)
22:31 <Cari_Elf> it will try to get a random resource type that likes that tile's terrain
22:32 <Cari_Elf> of the resources that like that terrain
22:32 <Cari_Elf> it does a random roll based on the rarity
22:32 <Cari_Elf> and the one with the best roll gets placed on that tile
22:33 <Cari_Elf> like I bet if you changed the terrain for horses and wargs to forest, they'd start showing up more often
22:35 <Heavenfall> so in reality, there's no way to be even close to precise in how many of a resourcehorde should spawn
22:35 <Cari_Elf> not without specifically placing them on custom maps
22:35 <Heavenfall> I mean if I'm looking to add 5-6 new resources, i can't tuck them all into the same preferredterrain, because they'll bump each other off
22:37 <Cari_Elf> that's a distinct possibility
22:37 <Heavenfall> I don't suppose there's any way to have them act like shards? there always seems to be 1 of every shard on the map
22:37 <Heavenfall> and I don't think probability would support that
22:37 <Cari_Elf> no, shards have their own placement functions
22:38 <Cari_Elf> and now Brad makes sure that some start by the starting points
22:38 <Cari_Elf> let me see if there's a tag that will make them go on any terrain
22:40 <Cari_Elf> oh
22:40 <Cari_Elf> actually
22:40 <Cari_Elf> it looks like if you don't specify a terrain then it just goes by the rarity
22:41 <Cari_Elf> however
22:41 <Cari_Elf> if there are any for that tile's terrain, it will put one of those there
22:41 <Cari_Elf> so that may not be helpful
22:42 <Heavenfall> what weight does rarity have when rolling for resources?
22:42 <Cari_Elf> ULONG ulRarity = rand()%((ULONG)pResource->GetRarity()); if(ulRarity > ulMostCommon) { ulMostCommon = ulRarity; pResourceTypeOut = pResource; }
22:43 <Cari_Elf> ulRarity will be beteween 0 and the rarity-1
22:44 <Cari_Elf> whatever rolls the highest will be the one chosen
22:44 <Cari_Elf> a higher rarirty would mean that you might get a larger number
22:44 <Cari_Elf> but there's stil a lot of lower ones
22:46 <Heavenfall> so if I had one with 10 rarity, and one with 100 rarity, there would be an 82% chance of it being the 100 rarity one?
22:48 <Cari_Elf> I think so
22:50 <Heavenfall> this is a really difficult system to "add" to
22:50 <Heavenfall> whatever I do, I'll end up pushing old resources out
22:50 <Heavenfall> and it's so random, there's no way to tell if I'll end up with 10 of one resource or 0
22:53 <Heavenfall> like this map I just spawnned... where I got 5 of the new resource in desert, and 0 horses and 0 oasis
22:53 <Heavenfall> oh well, it is what it is
22:53 <Heavenfall> thanks for the information