• The forum has been updated. For an explanation of some of the changes, head over here.

OSP Code Campaign [M&B] Founding Villages KIT v0.76 (updated 03/05/2009)

Currently viewing this thread:

jik

Knight
Crap, shouldn't have closed the old thread on farms, but I got most of it to work, but have 1 small hicup.  It seems that this scrip will put all villages down on the same spot, though it should cough out after the first 1. 

OK here is the working code if any one is interested.  The opening comment will fill you in on how it works.  As preparation for this script, I added the disable flag to all the villages, as well as commented out the section of the script that binds them (do a search for slot_village_bound_center).  I have left in the test messages and test code blocks, but they have comments indicating where they are.  As it is, the AI can use this as it takes a party as a param, though it will be up to you how you would handle when and where the AI plans to found a village.  My final code will have other resource stipulations as well.

Here is the code:

Code:
# script_found_village.  This script will move an unbound town to the party's(past param) location.  Currently it is set to require that
# you are NOT within 5 distance of another village or town, that you are within 15 distance of a town you own, and there are unbound villages available.
# Input : party that is founding the village, though may not let AI use this code, may hard code AI villages and hide them.  
# Output : none
# If the script finds a village, it becomes marked as bound.
	("found_village",
		[(store_script_param,":party_no",1),    #will most likely be p_main_party, unless I get AI to work
		 (assign,":good_spot", 0),              #if a proper spot is found, this will change to 1
		 (party_get_current_terrain,":cur_terrain",":party_no"),
		 (assign,reg24,":cur_terrain"),        ###TEMP USAGE TEST.  reg24 is used below!
		 (display_message,"@Current terrain type is {reg24}"),
		###TERRAIN CHECK.  USE this_or_next to broaden what terrains are allowed (this_or_next|eq|neg,...)
		 (try_begin),           ##Terrain testing.
			#(eq,1,1),          ##UNCOMMENT THIS LINE AND COMMENT THE NEXT TO BYPASS TERRAIN TESTING
			(this_or_next|eq,":cur_terrain",rt_plain),  ##If you are not on plains (steppe, forest, water, desert...  See header_terrain_types.py)
			(eq,":cur_terrain",rt_snow),                ##If you are not on plains (steppe, forest, water, desert...  See header_terrain_types.py)
		###End of TERRAIN CHECK
			(try_for_range,":close_town",towns_begin, towns_end),
				(store_distance_to_party_from_party,":cur_dist", ":party_no", ":close_town"),  #see if it is close enough
				(assign,":closest_dis", 15),  ##Keep track of the closest town incase the last one checked is farther.
				(try_begin),
					(le, ":cur_dist", ":closest_dis"),  #must be within 15 distance of one of your towns
					(assign,reg24,":cur_dist"),                                           ##Part of the below test messaging
					(try_begin),
						(party_slot_eq, ":close_town",slot_town_lord, ":party_no"),       ##You own a town close enough, continue
						(assign,":closest_dis",":cur_dist"),                              ##Mark this as the closest.  Only check others that are closer
						(str_store_party_name,s26,":close_town"),                         ##record the name of the town you are closest to
						(party_get_slot,reg27,":close_town",slot_town_lord),
						(str_store_troop_name,s27,reg27),
						(display_message, "@distance measured is {reg24} from you to {s26}",0xAA0000),  ###TEST MESSAGE.  How far is it going?
						(display_message, "@{s26}'s owner is {s27}.  This should be you!"),             ###TEST MESSAGE
						(assign,":good_spot",":close_town"),                              ##looks good so far...  Keep track of the closest town that you own
						(try_for_range,":village_town",towns_begin, villages_end),
							(try_begin),
								(eq|neg, ":good_spot",-1),                                ##once failure state is hit, no use doing the rest...
								(store_distance_to_party_from_party,":too_close", ":party_no", ":village_town"),  ##make sure it's not too close to anything
								(try_begin),
									(le,":too_close",5),                                  ##needs to be outside of 5 distance from other towns/villages	
									(assign,":good_spot",-1),                             ##Too close, -1 will indcate this
									(display_message,"@TOWN or VILLAGE too close!",0x0000ff),    ###TEST MESSAGE
								(try_end),
							(try_end),
						(try_end),   ##end of the :village_town too close loop
					(try_end),
				(try_end),
			(try_end),  ##end of the your town :close_town loop
			(try_begin),
				(ge, ":good_spot", 1),
				(assign,":founded",0),                                      ## last check to make sure there are enough villages to go around.
				(try_for_range,":new_village",villages_begin, villages_end),
					(try_begin),
						(eq,":founded",0),                                  ##this will change once a usable village is found
						(try_begin),
							(party_slot_eq,":new_village",slot_village_bound_center,0),  ##make sure it is not used!
							(display_message,"@A village is available!"),                ###TEST MESSAGE
							(party_relocate_near_party,":new_village","p_main_party"),
							(enable_party,":new_village"),
							(party_set_slot, ":new_village",slot_village_bound_center, ":good_spot"),             ##this is now claimed, bind it to your town 
							(store_faction_of_party, ":town_faction", ":good_spot"),                              ##good_spot is your town, get it's faction
							(call_script, "script_give_center_to_faction_aux", ":new_village", ":town_faction"),  ##Give it's faction to the new village
							######(party_set_slot, ":new_village",slot_town_lord, ":party_no"),  ##It is now yours - wrong code for this, see above!!!
							(display_message, "@You have founded a new village that is tied to {s26}"),
							(assign,":founded",1),
						(try_end),
					(try_end),
				(try_end),
				(try_begin),
					(eq,":founded",0),   ##looks like no more free villages
					(display_message, "@NO MORE VILLAGES AVAILABLE..."),
				(try_end),
			(else_try),
				(eq, ":good_spot", 0),
				(display_message,"@You cannot found a village this far from your towns.  Must be within 15 distance"),
			(else_try),  ##Found a good spot!
				(eq, ":good_spot", -1),
				(display_message,"@You are too close to another town or village.  Must be outside of 5 distance"),
			(try_end),
			#(str_store_party_name,s26,":good_spot"),                                        ###TEST CODE: FYI causes error message if no town is found
			#(assign, reg50,":good_spot"),                                                   ###TEST CODE for below message
			#(display_message,"@good_spot variable is {reg50}.  Close to {s26}",0x00ff00),   ###TEST MESSAGE
		 (else_try),
			(display_message, "@You cannot start a village in this terrain",0xff5555),
		 (end_try),
		]
	),

Founding Villages Kit v0.76 for M&B v1.xxx:
Features:
Setting to define radius space needed around a new village (set to 5)
Setting to define how close it needs to be to the Town (that must belong to the party past to the script) it will be bound to (set at 15)
Checks for unbound village, moves it to the spot if other checks pass, turns off the disable flag on the village.
  - this means that you need to have (most likely disabled) unbound villages.  slot_village_bound_center needs to be 0
Binds the village to the same faction as the town. 
Test terrain, so that they cannot put villages on improper (but traversable) terrain.  Can be easily turned off


Things for the future:
Actually give the town to you.  Right now after traveling for a bit the message to grant the fief comes up.  Don't want this for villages.
Halo around the villages showing there used area
Test for needed resources to found the village


 

MountainBlade

Sergeant Knight at Arms
Wouldn't the (try_for_range,":new_village",villages_begin, villages_end), overwrite the (assign,":new_village",villages_end),  ##Break loop? I mean, it may be using some invisible counter instead of relying on the state of ":new_village".

Though you use the same method when you check if it's too close. Try building a village in a spot that's too close to two or more places. If you get the (display_message,"@TOWN or VILLAGE too close!",0x0000ff), message twice then that method doesn't work to break loops.
 

jik

Knight
I went from (assign,":new_village",0),  ##Break loop to (assign,":new_village",villages_end),  ##Break loop.  I saw assigning the looping variable to 0 in a native, though I'm not sure why making it 0 would end the loop as this type of loop goes up...  In theory, by forcing the looping variable to the end point, it should end the loop....

Well I did that and yes it does pop up more than once, so back to the drawing board.  I guess I need a new flag local var to say that I have a village....


Dropped all this and am using variables to track when the conditions are met and to not continue to check.  It now works.
 

Ruthven

Baron
WBM&BVC
So this just sort of spawns a village wherever I want? Sweet.

But you disabled all the other villages, right?
 

jik

Knight
Right.  What it will do is scan through the list of villages (villages_begin to villages_end).  If it finds an unbound village it will use it.  So you can hide the last few villages, the first few, or what ever.  Just make sure they are unbound.  I believe that bound means they are tied to a specific town/castle.

Like I said though, AI can use this, but you have to set the conditions (outside of the ones in the script itself) for them to use it.  You could do something like (based on my code conditions) that when they need a village and have the resources, patrol an area and check every so often.

I will also be attempting to test the terrain for the right terrain to place it.  So no farms on snow, sand, or forest... well we'll see.
 

MartinF

Squire
I like it!

Just a thought. Villages currently get 'started up' in the game start script. So if you place a new village, it will already be up and running. At least, I think that's how it work atm. Are you going to do something for that? Like reset the village to stage 0 after it's been placed?

A lot of potential with this. It makes the world map less static, which is always good. If you (not you specifically, jik, just 'one') can write a good AI for this, you could have a more civilization styled MNB mod, where all factions start out with one town and a village or something, and then have to earn resources to build the rest.

Would be slightly complicated of course, but hey, somewhere down the line we're going to get bored and will need to have a challenge.. right? :wink:
 

jik

Knight
MartinF said:
I like it!

Just a thought. Villages currently get 'started up' in the game start script. So if you place a new village, it will already be up and running. At least, I think that's how it work atm. Are you going to do something for that? Like reset the village to stage 0 after it's been placed?

A lot of potential with this. It makes the world map less static, which is always good. If you (not you specifically, jik, just 'one') can write a good AI for this, you could have a more civilization styled MNB mod, where all factions start out with one town and a village or something, and then have to earn resources to build the rest.

Would be slightly complicated of course, but hey, somewhere down the line we're going to get bored and will need to have a challenge.. right? :wink:

Thanks MartinF, that's where I am hoping to go.  With these ideas, you can also start as a village, then upgraded to a town further down the road(just replace the village with a hidden unused town).  It would be nice to have a (halo) around your towns to mark off the radius it uses, but message indicators are fine for now.
 

MartinF

Squire
heh.. I'm looking at a halo for the patrol radius of my bases, so I'll keep you posted on that.

I'd also like to add some information to the mous-over pop-up. You wouldn't happen to have looked at that already, would you?

And yeah, basically this is another way of tackling custom settlement's 'growing settlement' idea. I think it's a bit more viable for most mods that don't want to completely rebuild each and every scene, but that do want a less static map.
 

jik

Knight
MartinF said:
heh.. I'm looking at a halo for the patrol radius of my bases, so I'll keep you posted on that.

I'd also like to add some information to the mous-over pop-up. You wouldn't happen to have looked at that already, would you?

And yeah, basically this is another way of tackling custom settlement's 'growing settlement' idea. I think it's a bit more viable for most mods that don't want to completely rebuild each and every scene, but that do want a less static map.

I've wanted to look at that.  The custom settlement mod does something with it as it shows population when rolling over the villages.  I want something similar.  I'll let you know what I found. 

There's a slight problem with the code, and I am trying to find it.  seems it still let me put down a village near other towns.  Not sure why, so I''m going over the code again.  Will post again once that is fix.  Also fixing the messages displayed.
 

MISHO

Banned
So does this make the AI able to build villages?
And i it only for v750 of M&B or is it v750 of the kit?
 
This is a cool idea. Someone could make a build the whole world from scratch mod I bet, with even AI using it? That would be something.
 

jik

Knight
It's v0.75 of the kit, for M&B v1.xxx.  I should post that at the top...

The AI can do this, I have made it so any party can call this script as long as you pass the party in mind to the script.  There is no AI involved yet.  You could throw it in a trigger for a troop that is patrolling around his town.  Have him try it every .5 hours.  If you want to take it far enough, you could later upgrade the villages to towns (using the same idea of moving the hidden town to that spot then hiding the village).  The you could spread your empire.  You can also adjust it to check for either towns or villages within 15 (just change the end point for the loop) so you could make a string of villages across the land.

This is just a starter kit.  It does have a lot of potential, and I would like to see where people might go with it.  So my stipulation for using this in your mod is that you tell me when your mod is done, I'd like to see how it worked for you :wink:


[EDIT]

As anyone played with testing the terrain (party_get_current_terrain operation) at all?  Is it possible to change the terrain while playing (like turning all the rt_plain spots to rt_snow to simulate winter)?
 

wickedshot

Sergeant Knight
MartinF said:
heh.. I'm looking at a halo for the patrol radius of my bases, so I'll keep you posted on that.

I'd also like to add some information to the mous-over pop-up. You wouldn't happen to have looked at that already, would you?

And yeah, basically this is another way of tackling custom settlement's 'growing settlement' idea. I think it's a bit more viable for most mods that don't want to completely rebuild each and every scene, but that do want a less static map.
Yes, this code presents some really interesting options.

Great job jik.
 
Nice idea, really. I'm interested in seeing mods putting this to use. Maybe even custom settlements mod can use it, so every game will really be different from each other in all senses.
 

jik

Knight
Pehu Wizzard said:
Nice idea, really. I'm interested in seeing mods putting this to use. Maybe even custom settlements mod can use it, so every game will really be different from each other in all senses.

If they want it they just need to ask.  Might mess with how they layed things out though.  The one issue with this is that you have to modify some of the basic code to have it run smooth.  Ok, maybe just the part where villages are bound, and disabling them all.  It just depends on what you are looking to do.
 

SPD_Phoenix

Master Knight
Thanks, jik. I was looking for something like this for my personal mod.

So, in theory:
- I can define new unbound disabled villages and use this script to found new villages (?).
- I can modify the script to allow me to found new town (?). More like building up village into town which then allow me to found more new villages (?).
- Also, I can build new castle base on this same script (?).

As for resource and requirement for founding new village, besides from the already defined conditions in the script, I'm planning to use the following:
- Peasants/farmers: I plan to reenable refugee party which run from village to village. The trigger would be when a village is raided or may be infested with bandit, it will spawn a small refugee party (5 to 15). This party will try to run to the nearest village (of the same faction). Player can recruit these parties to found new village. Required number may be 30 - 50 peasants/farmers.

Building up the new village:
- Quests: gathering resources. I will probably use only quarry and wood logs. These are not normal merchandise goods. I plan to do a simple resource gathering in camp menu. Probably will require to camp in some specific area (forrest for wood logs and mountainous for quarry).
- Quests: build new houses quest, may be land clearing quest. Using the similar format of the training peasant against bandit quest. Basically, make player party rest at the village for a few hours (the time will be determine on party size and party engineering skill) to complete the houses. Each successful quest will then give some amount of completion to the new village. When the completion reach 100, the viilage will be considered complete and will then begins to function normally (generating goods and trade with town, generate income, generate recruits,...).

Edit: hit the wrong button and post it before I finish.
 

jik

Knight
funny... since I got side tracked with working on a zombie survival mod, I haven't put more work into my own...  :???:

Glad this is going to get some use soon.  What it does so far is pretty basic.  But on these concepts, you could have towns/castles disabled/hidden in the same fashion.  Then when conditions are met (I would check after each upgrade is built) then you can remove the village and put in a town (adding the village back to the unused pool).  You would have to look at relocating all parties (and anything else associated with villages/towns/castles - such as the owner) to the new town (party).

I still like how I put this together (I think it was my first or 2nd kit) and would like to see it grow.  If you have questions on it, feel free to ask me.  I do ask one thing in return.  Tell me how it's going.
 

Dudro

Knight at Arms
So this isn't a "found your own village, that belongs, to you, and you can only found one" is it?  Oh well.  Anyways, it still sounds incredible, keep up the good work.
 

jik

Knight
Dudro said:
So this isn't a "found your own village, that belongs, to you, and you can only found one" is it?  Oh well.  Anyways, it still sounds incredible, keep up the good work.

As I made it, it's more to expand your kingdom.  I envisioned starting with 1 town, then having to make villages to support it with resources such as food, wood and ore.  The generic basic parts of the code could have you create a village anywhere really and start your own factions.
 

Dudro

Knight at Arms
Right, cool.

I still don't think I get it though.

So, if you do not belong to a kingdom, you can make a village.  That can then be upgraded (in the future, as your post said) to a city, and more villages can be made around it?


Or is it like this -- You capture a city, you can place the villages anywhere you want?
 
Top Bottom