Page 1 of 1

selecting terrain tiles in code

Posted: Mon Jun 24, 2013 10:45 pm
by agentorangeguy
Is it possible to designate certain terrain tiles to be targeted in code with the UI_click_on_item(); intrinsic? I'm working on code for the shovel, but I can't seem to target terrain tiles successfully, but the same code I make will target actual items. Is there anything specifically i could do to target terrain tiles, like cavefloors and so on?

Re: selecting terrain tiles in code

Posted: Tue Jun 25, 2013 6:40 am
by Colourless
8x8 terrain tiles aren't items and I don't think there is anything in the code that would allow you to do what you'd want. An 'idea' could be to place specially crafted invisible items where you'd want to be able to dig, but that doesn't sound like what you'd want (a general solution). I think modifications to exult would be needed

Re: selecting terrain tiles in code

Posted: Tue Jun 25, 2013 9:06 am
by agentorangeguy
Yeah I was kind of afraid of that. I'd have to blanket entire areas in the invisible items. I suppose maybe making an "invisible carpet" and naming it as "soft dirt" might work in the mean time..

Re: selecting terrain tiles in code

Posted: Tue Jun 25, 2013 9:50 am
by marzo
Just to expand on colourless' answer: UI_click_on_item targets either objects or tiles -- it always returns an array of the form {object, x, y, z} -- but you cannot do anything with a tile except use it to either place objects there or find stuff near it.

This might be enough for your purposes: if you want a specific tile to contain something, you hard-code the position in the shovel's usecode, and when the shovel is used at that location, you create the item and move it there.

Example:

Code: Select all

void Shovel shape#(xxx) () {
	var objpos = UI_click_on_item();
	if (objpos[0]) {
		AVATAR.say("There is something on the way, maybe I should try moving it fist.");
	} else {
		var x = objpos[1], y = objpos[2], z = objpos[3];
		var found = 0;
		if (x == 200 && y == 300 && z == 0) {
			AVATAR.say("@A-ha!@");
			found = UI_create_new_object(800);
			var gold = found->add_cont_items(10, 646, -359, 0, false);
		}
		if (found) {
			found->set_last_created();
			UI_update_last_created([x, y, z]);
		}
	}
}

Re: selecting terrain tiles in code

Posted: Tue Jun 25, 2013 10:36 am
by Colourless
I think what agentorangeguy really would want is to be able tell what index+frame the tile is.

Thinking about it, it would be like implementing the 'is_water' water intrinsic as usecode itself.

Re: selecting terrain tiles in code

Posted: Tue Jun 25, 2013 10:49 am
by Colourless
Thinking about it, and looking at the code, would be simple enough to say extend UI_click_on_item to have an extra two elements returned (shape+frame) and then add a function to return the entire Shape_info structure for a shape.

Re: selecting terrain tiles in code

Posted: Tue Jun 25, 2013 5:52 pm
by agentorangeguy
I was hoping to use only certain tiles such as dirt dungeon floors, but only the "dirt" frames and not the "stone" frames, which would be too 'hard' to dig with a shovel. then, I set a random chance that you'll pull up a gold nugget, or a gem. Right now i have it like 1 in 25 chances. For regular grass tiles and regular dirt tiles, a less of a chance of pulling something up. This way, dungeons are more profitable to dig. Another snag I have is randomizing gems when dug up. i don't know if UI_create_object uses frames or not...

Re: selecting terrain tiles in code

Posted: Tue Jun 25, 2013 11:02 pm
by Scythifuge
While z-value issues remain, as far as Exult not remembering anything above the original z-height value (as far as stackable objects & losing any z-height due to this method), the idea that I have for map building Savage Empire is to use tiles to lay out the landscape, & then place object-tiles drawn to resemble the environment on top of the tiles. This is to allow digging & destructible environments (such as craters when using player made grenades.)

You are probably too far along with your map for such a radical idea. However, maybe areas that need to be dug could be elevated one tile up, such as low hillocks. I remember some tiles in the original U6 that were shaded to give the illusion of elevated land.

Re: selecting terrain tiles in code

Posted: Wed Jun 26, 2013 7:26 pm
by agentorangeguy
Yes that would be an idea for certain spots that need to be dug up such as Hawkins' treasure area.