Hi,
I don't know if you know travian. Travian (http://www.travian.com) is a browser game (programmed in PHP) where you can build your own village.
I was wondering how they program their building logs.
When a player wants to build something, he pays his recources and then the construction starts. The construction lasts a period of time (depending on the building).
Example.
I build a house: it takes 20 and 10 seconds minutes. 20 min 10 seconds later, I can see the house. Then I can build a threehouse, this takes 7min30sec. How do they program it that exactly after 7min30 sec, the building is made?
I don't think it can be done with a cron job... it would have to be run every second...
How to: Travian tasks
Moderator: General Moderators
Code: Select all
create table buildings(
building_id int not null auto_increment primary key,
building_type_id int not null,
construction_start timestamp
);
create table building_types (
building_type_id int not null auto_increment primary key,
name char(64) not null,
construction_time int not null unsigned
);
select building_id, (time_to_sec(timediff(now(),construction_start))/construction_time) * 100 as percents_complete
from buildings
inner join building_types using(building_type_id); -- this query will give you all the buildings with their completion status
- The Phoenix
- Forum Contributor
- Posts: 294
- Joined: Fri Oct 06, 2006 8:12 pm
It could be that the action of 'create town' goes as follows:boonika wrote:Well, the datebase thing I understand. It's the timer I would like to know. And is such a timer possible with PHP?
1. Add new db entry for town, with a 'ready at' date in the future
2. Next cron run (every 5 minutes is common for web games), it processes that request, and builds everything that needs to be built, but again sets those items with a "ready at" date
3. View towns only shows items with a ready at date < now. ("SELECT items where ready_at < time()").
That way, cron can run, and you can't see things that are built until the very second - without needing per-second timing from cron.