Translations/Euphoria

Материал из SpeccyWiki
Перейти к: навигация, поиск

Andrew771 on Euphoria 2D [1] (excerpt, pp. 67-69)

Deep thoughts have shown that Civilization is too hard to start it at once. There is, of course, Vitaly Kubekin's positive experience with his very beautiful Civ-demo. There is also a good game Anno Domini from Jonathan Cauldwell, fit in just 4k! The actual game, though, requires a well thought-out database with a lot of interconnections, even having fields added in the course of the development. That's not easy to start something like this from scratch and in assembly language. So I decided to make a simplified 3D game, which doesn't contain research and a lot of unit types. This became Euphoria 2D, released in 2012. The purpose of writing this game was to find out possible difficulties that will appear while writing Civilization, and to check the idea of distinct buildings in cells instead of cities.

In short, Euphoria 2D is good old Kingdom Euphoria with a map. The same peasants and soldiers, grain with stones and wood added, land is infinite, gold is removed. Galleys added to move units across the seas. There are several types of buildings to produce, keep and influence units and resources:

  • houses to bring peasants;
  • barracks to teach soldiers;
  • garners to keep grain;
  • storehouses to keep stones and wood;
  • dockyards to produce galleys;
  • temples to enhance the spirit of civilization.

There are also as arable land for growing grain, roads to improve mobility of units, defensive walls and towers. The landscape in the game is randomly generated. Mountains are used to mine stones, forests to obtain wood.

Three enemy civilizations have the same capabilities as yours. Everyone plays against everyone. If your units are hungry, they rise in revolt and turn rebels, to play against you, becoming the fourth enemy civilization and having the same features as regular civilizations. The only difference, if the units in the rebel civilization are hungry, then go back to you. There is no happiness! The goal is to destroy all enemies.

The landscape is generated with random rectangles. Initially 15 large rectangles are placed, which mean continents. Then smaller rectangles are attached to them to produce meadows, mountains and forests (total of 1415 rectangles). Sizes of rectangles decrease linearly. This makes quite picturesque landscapes.

Artificial Intelligence (AI) for enemy civilizations is made as follows. Every civilization has 2 global missions of 7 units each. All the other units make local jobs. The missions are to take control of nearby areas, that are 6x6 squares, in which the entire map is divided. If a mission occasionally encounters another civilization, it can fight because of a conflict of interests. Once the area is occupied, the current mission of civilization changes. Units can establish one new city in an area. A city consists of buildings of any type, surrounded with walls and towers. The centre of the area becomes city centre. Placement of walls and towers is set in advance, with 11x11 template, but if the sea or the mountains don't make it possible to use this template, the walls are moved inside the city or don't appear at all if they are too close to the city centre.

A mission consists of four steps: collect units, move them by the sea, move them by dry land, take control of the centre of the area.

At the first step, necessary units are accumulated on the current area: a certain number of peasants, soldiers and galleys. However, they still continue to carry out their local jobs.

If there are at least some (predetermined) number of sea cells between the current area and target area, the second step begins - moving by the sea. Galleys wait until they are filled with units, then they move as close as possible to the centre of target area, where the passengers will be landed on the shore. One passenger stays on the galley and moves it back to the collection point for the new batch of units. Galleys can't sail empty, as it was in Sid Meier's dreams. Here it is, crossing the river with a wolf, a goat, and a cabbage.

Units move by dry land by themselves, heading to the centre of the target area. Not straightforward, a unit tries to find the best way possible (preferably a road or meadow) out of three directions towards the target. I did not bother to search the optimal path because it turned out that this algorithm is enough, since all the dry land cells are passable, including the buildings.

If at least one of the units set foot on the desired cell, this mission ends, new target for capture is selected, and new mission starts. And so until the civilization conquers the whole world, if others will let it!

Number of units engaged in the mission was found experimentally. Armies up to 15 units were tried, but testing has shown that large number of units takes too long to collect, there is traffic jam in cities (because only one unit can be in a cell), and units hinder each other. Upgrading is inhibited, nanotechnology doesn't develop, new units can't be born because the houses are occupied. It's Moscow! So, missions were limited to 7 unit squads.

The rest of idlers, not engaged in missions, perform routine work - build new buildings, collect resources and store them. Buildings are made if there is a need of this type of buildings. There is a predefined number of square meters per person. Unfortunately, for the whole civilization, not for a specific city. This defect is scheduled to be corrected in the future. So, parasite soldiers go to the starting point of our euphorians, using abandoned galleys sometimes. This deception was done because the other way the civilizations would evolve themselves, ignoring the human threat, traffic jams and unemployment. But this is the only deception in the game, the rest of the AI is honest and has just the same possibilities as the player has.

At each turn, units not just perform their tasks mindlessly, they look around: what if there is an enemy or a freebie? The following procedures in the given order are performed for each unit, when there is a suitable object found within the search distance: - attack an enemy unit if the enemy is weaker or equal in strength; - capture an enemy building; - execute the mission; - move to the tower to enhance the protection, if the unit is a soldier; - retreat in the opposite direction, if the enemy on the adjacent cell is stronger; - find a garner with grain (for a soldier) or arable land (for a peasant), if the unit is hungry (has less than 20 points of grain); - land an ownerless galley to the nearest shore, if it has passengers; - get together for a mission.

The testing has shown that the order of there procedures and the order of buildings to build influence the civilization deeply. It can become infantile with poor fertility - or aggressive and breeding like rabbits.

I'd like to write some words about the architecture of the program. This game doen't need very fast calculations and memory economy because this leads to sophisticated code that is hard to control. You change something, something else fails. I tried to save memory by calling a procedure of address calculation (from a compact database) every time. So, sometimes a number of procedures like this should be called to find what's in 5th bit of 9th byte of 3rd unit, which is simply a flag - to fight or not to fight. That's not good. The better way is to create a buffer at the start or each turn of a unit, where we unpack all the data from the database, data from surrounding cells, units, buildings. We can even make a label for each field of this buffer (except for the arrays, of course) and address the needed data by that label. This way the code will be readable. That would be better to write it in high level language with a good compiler. For this game, speed is not so important.