00001 #include <stdio.h>
00002 #include <SocketHandler.h>
00003 #include <StdoutLog.h>
00004 #include <Uid.h>
00005 #include <ListenSocket.h>
00006 #include "Robot.h"
00007 #include "Map.h"
00008 #include "Base.h"
00009 #include "InjectSocket.h"
00010 #include "RowoHandler.h"
00011
00012
00013 std::string GetMyUid()
00014 {
00015 std::string myuid;
00016 FILE *fil;
00017 if ((fil = fopen("myuid.txt","rt")) != NULL)
00018 {
00019 char slask[1000];
00020 fgets(slask,1000,fil);
00021 slask[strlen(slask) - 1] = 0;
00022 fclose(fil);
00023 myuid = slask;
00024 }
00025 else
00026 {
00027 Uid uid;
00028 myuid = uid.GetUid();
00029 fil = fopen("myuid.txt","wt");
00030 fprintf(fil,"%s\n",myuid.c_str());
00031 fclose(fil);
00032 }
00033 return myuid;
00034 }
00035
00036
00037 int main(int argc,char *argv[])
00038 {
00039 RowoHandler h;
00040 StdoutLog log;
00041 h.RegStdLog(&log);
00042 ListenSocket<InjectSocket> ll(h);
00043 std::string myuid = GetMyUid();
00044 Map map;
00045 Base home(map);
00046 bool quit = false;
00047 struct timeval tvo;
00048 struct timezone tz;
00049
00050 if (ll.Bind("localhost",32766) == -1)
00051 {
00052 exit(-1);
00053 }
00054 h.Add(&ll);
00055
00056
00057 h.SetMyUid(myuid);
00058 h.SetMap(&map);
00059 map.SetMax(1000, 1000);
00060 map.AddObject(&home, false);
00061
00062 gettimeofday(&tvo,&tz);
00063 while (!quit)
00064 {
00065 h.Select(0,100000);
00066 struct timeval tv;
00067 gettimeofday(&tv,&tz);
00068 long diff = tv.tv_usec - tvo.tv_usec;
00069 if (diff < 0)
00070 {
00071 diff += 1000000;
00072 }
00073 if (tv.tv_sec != tvo.tv_sec)
00074 {
00075 if (map.objects_in_map() < 1000)
00076 {
00077 map.SpawnRandom();
00078 }
00079 }
00080 if (diff >= 50000)
00081 {
00082 map.IncreaseTime( diff );
00083 tvo = tv;
00084 }
00085 }
00086 }
00087
00088