How to make resources (eg a tree) be more than the allowed object number?

Started by KyriakosCH, Thu 22/10/2020 05:33:14

Previous topic - Next topic

KyriakosCH

If one wanted to make a strategy game, how would they have resources like trees, which would be all over the map?
Afaik there is a hardcoded limit to number of objects, so it can't just be done with setting each resource as an object.
Also, ideally the strategy map would be one room (obviously larger than any screen)
This is the Way - A dark allegory. My Twitter!  My Youtube!

Gilbert

These kind of games usually arrange assets in a grid (even if it's in orthogonal view there is still a grid), so usual way is to just don't use objects and draw the graphics on the background. You use a 2-d array to hold the info of the individual items on the grid and if you say click on a certain spot on the screen you may do some calculation to find out what asset is under that spot, etc.

...or, use an engine more suited to these kind of games.

KyriakosCH

The issue is with making such "resources" depleted when used. Otherwise it makes no sense having resources in the first place :)
Is that possible?
I mean... it would be horribly tedious to do it by having the entire map be a graphic and change views dependent on what resource got used up.
This is the Way - A dark allegory. My Twitter!  My Youtube!

Khris

Drawing objects on the background requires storing their position anyway; it's simple to add a count to that.
For a map of 50x50 tiles, all you need is an  int res[2500];  to store a bunch of things.
For instance 1-100 means: that much wood. 101-200 means: that much coal. etc.

So to indicate that there's a tree that provides 20 wood at coordinates 14, 31:  res[31 * 50 + 14] = 20;

KyriakosCH

Quote from: Khris on Thu 22/10/2020 08:01:10
Drawing objects on the background requires storing their position anyway; it's simple to add a count to that.
For a map of 50x50 tiles, all you need is an  int res[2500];  to store a bunch of things.
For instance 1-100 means: that much wood. 101-200 means: that much coal. etc.

So to indicate that there's a tree that provides 20 wood at coordinates 14, 31:  res[31 * 50 + 14] = 20;

Ok, so how to have (eg) 100 trees, when the upper bound for total number of objects (which in the game wouldn't just be trees in the first place) is smaller than that in AGS?
This is the Way - A dark allegory. My Twitter!  My Youtube!

Khris

Please don't quote the entire previous post :)

The trees are drawn using sprites and DrawingSurfaces. They do not exist as AGS room objects at any point. If you're doing a 2D top-down view, you can calculate the position of a tree using its tile coordinates and current camera position, then you draw the sprite on the background. If you want the tree to cover other sprites, you need to determine the drawing order first (exactly what AGS natively does with characters, objects and walkbehinds).

Again, to indicate a tree standing somewhere on the grid, you set an element of a grid-sized array to "tree" (some number indicating as much). The alternative is to keep an array (of arbitrary size) of tree struct instances and store the coordinates and remaining wood that way.

Simple example:
Code: ags
// header
#define MAX_TREES 100
struct Tree {
  int x, y;
  int wood;
  import void Set(int x, int y, int wood);
};
import Tree trees[MAX_TREES];

// main script
Tree trees[MAX_TREES]; export trees;
void Tree::Set(int x, int y, int wood) {
  this.x = x; this.y = y; this.wood = wood;
}


You can now create trees like this:
Code: ags
  trees[0].Set(12, 23, 100);
  trees[1].Set(25, 2, 80);

SMF spam blocked by CleanTalk