[Tux4kids-commits] [SCM] tuxhistory - Educational history game branch, master, updated. 5e5d63060d4f51cb2f03d75890333798c6997288

julio (none) julio at julio-desktop.
Thu Aug 12 05:24:00 UTC 2010


The following commit has been merged in the master branch:
commit 5e5d63060d4f51cb2f03d75890333798c6997288
Author: julio <julio at julio-desktop.(none)>
Date:   Thu Aug 12 00:23:07 2010 -0500

    Some advances creating new buildings.

diff --git a/src/ai.c b/src/ai.c
index 527ef3a..27dd9a1 100644
--- a/src/ai.c
+++ b/src/ai.c
@@ -379,7 +379,46 @@ static th_point ai_find_closest_center(th_point point)
     return lowest;
 }
     
+th_point ai_alternative_tile(th_point p1, th_point p2)
+{
+    int prev_hdist;
+    int l;
+    th_point tmp_point;
 
+    prev_hdist = -1;
+    for(l=0; l<NUM_DIRS; l++)
+    {
+        if(gmaps[human_player][p2.x][p2.y].nodes[l])
+        {
+            if(ai_valid_tile(human_player, 0, gmaps[human_player][p2.x][p2.y].nodes[l]->point))
+            {
+                if(prev_hdist == -1)
+                {
+                    tmp_point = gmaps[human_player][p2.x][p2.y].nodes[l]->point;
+                    prev_hdist = HDIST(p1.x, p1.y, gmaps[human_player][p2.x][p2.y].nodes[l]->point.x,
+                           gmaps[human_player][p2.x][p2.y].nodes[l]->point.y);
+                }
+                else if(HDIST(p1.x, p1.y, gmaps[human_player][p2.x][p2.y].nodes[l]->point.x,
+                           gmaps[human_player][p2.x][p2.y].nodes[l]->point.y) < prev_hdist)
+                {
+                    tmp_point = gmaps[human_player][p2.x][p2.y].nodes[l]->point;
+                    prev_hdist = HDIST(p1.x, p1.y, gmaps[human_player][p2.x][p2.y].nodes[l]->point.x,
+                           gmaps[human_player][p2.x][p2.y].nodes[l]->point.y);
+                }
+            }
+        }
+    }
+/*    if(prev_hdist == -1)
+    {
+       for(l=0; l<NUM_DIRS; l++)
+       {
+            tmp_point = ai_alternative_tile(gmaps[human_player][p2.x][p2.y].nodes[l]->point, p2);
+            break;
+       }
+    }*/
+    printf("Alternative point: (%d, %d)\n", tmp_point.x, tmp_point.y);
+    return tmp_point;
+}
 // ai_state_update modifies the values of all objects if they change their
 // state.
 
diff --git a/src/ai.h b/src/ai.h
index 945607b..4a2f9f0 100644
--- a/src/ai.h
+++ b/src/ai.h
@@ -31,6 +31,8 @@ void ai_free_path(th_path *path);
 
 int ai_modify_state(int player, th_obj *object, int state);
 
+th_point ai_alternative_tile(th_point p1, th_point p2);
+
 int ai_state_update(list_node *node);
 
 int ai_valid_tile(int player, int unit, th_point coords);
diff --git a/src/game.c b/src/game.c
index 304e276..6353b71 100644
--- a/src/game.c
+++ b/src/game.c
@@ -553,7 +553,13 @@ static void game_handle_mouse(void)
     {
         if(io.mouseclicked_flag != 0)
         {
-            if((io.build_flag = panel_click(&io.Plclick, selection.selected_objs[0])) != -1)
+            if(io.build_flag >= 0)
+            {
+                Pmousemap = mouse_map(io.Plclick, Pscreen);
+                //rts_build(selection.selected_objs[0], io.build_flag, Pmousemap); 
+                io.build_flag = -1;
+            }
+            else if((io.build_flag = panel_click(&io.Plclick, selection.selected_objs[0])) != -1)
             {
                 io.mouseclicked_flag = 0;
                 if(io.build_flag == -3)
diff --git a/src/objects.h b/src/objects.h
index 7ddc357..9b3fa6b 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -23,6 +23,7 @@ enum{
     USE,
     DIE,
     STORE,
+    CONSTRUCTION,
     NUM_OF_STATES
 };
 
diff --git a/src/tuxrts.c b/src/tuxrts.c
index f5ec83e..48953ba 100644
--- a/src/tuxrts.c
+++ b/src/tuxrts.c
@@ -195,7 +195,7 @@ int rts_goto(th_obj *obj, th_point point)
     list_node *node;
     th_path *path;
     th_point source;
-    th_point tmp_point;
+    th_point tmp_point, extra_point;
     int l;
     int action;
 
@@ -218,19 +218,11 @@ int rts_goto(th_obj *obj, th_point point)
             tmp_point.x = -1;
             tmp_point.y = -1;
             printf("A object is on the goal tile\n");
-            for(l=0; l<NUM_DIRS; l++)
-            {
-                if(gmaps[human_player][point.x][point.y].nodes[l])
-                {
-                    if(ai_valid_tile(human_player, 0, gmaps[human_player][point.x][point.y].nodes[l]->point)){
-                        tmp_point = point;
-                        point = gmaps[human_player][point.x][point.y].nodes[l]->point;
-                        printf("New goal tile: (%d,%d)\n", point.x, point.y);
-                        break;
-                    }
-                }
-            }
-            
+
+            extra_point.x = obj->x;
+            extra_point.y = obj->y;
+            tmp_point = point;
+            point = ai_alternative_tile(extra_point, point); 
             if(tmp_point.x == -1 && tmp_point.y == -1)
                 return 0;
 
@@ -314,6 +306,116 @@ int rts_goto(th_obj *obj, th_point point)
 
 int rts_build(th_obj *obj, int type, th_point point)
 {
+    list_node *node;
+    th_path *path;
+    th_point source;
+    th_point tmp_point;
+    th_point extra_point;
+    th_obj *obj_template;
+    th_obj new_obj;
+    char obj_name[50];
+    int l;
+    int action;
+
+    if(!obj)
+    {
+        printf("rts_goto error: object invalid!\n");
+        return 0;
+    }
+    if(obj->name_enum != VILLAGER_MILKMAID)
+    {
+        return 0;
+    }
+
+    action = BUILD;
+
+    node = list_nodes;
+    do{
+        if(node->obj.x == point.x && node->obj.y == point.y)
+        {
+            printf("A object is on the goal tile\n");
+            return 0;
+        }
+        node = node->next;
+    }while(node);
+
+    
+    extra_point.x = obj->x;
+    extra_point.y = obj->y;
+    tmp_point = point;
+    point = ai_alternative_tile(extra_point, point); 
+           
+    if(tmp_point.x == -1 && tmp_point.y == -1)
+        return 0;
+
+    sprintf(obj_name, "%d", type);
+    obj_template = hashtable_lookup(obj_table_hash, obj_name);
+            
+    if(!obj_template)
+        return 0;
+
+    new_obj = *obj_template;
+    list_add(&list_nodes, new_obj);
+/*
+
+            printf("Finding a new action!\n");
+
+
+            else
+            {
+                if(node->obj.type == BUILDING) 
+                {
+                    if(node->obj.name_enum == VILLAGE_CENTER &&
+                            obj->state.carrying > 0) 
+                    {
+                        obj->state.target_point = tmp_point;
+                        obj->state.target_obj = &(node->obj);
+                        action = STORE;
+                    }
+                    else if(node->obj.name_enum == FARM)
+                    {
+                        printf("It is a farm!");
+                        obj->state.target_point = tmp_point;
+                        obj->state.target_obj = &(node->obj);
+                        obj->state.rec_point = tmp_point;
+                        obj->state.rec_point_flag = 1;    
+                        action = USE;
+                    }
+                    else
+                    {
+                        obj->state.target_point = tmp_point;
+                        obj->state.target_obj = &(node->obj);
+                        action = REPAIR;
+                    }
+                }
+            }
+            break;
+        }
+        node = node->next;
+    }while(node);
+
+    printf("Change %s state: go from (%d,%d) to (%d,%d)\n", 
+                obj->rname,
+                obj->x,
+                obj->y,
+                point.x,
+                point.y);
+    
+    source.x = obj->x;
+    source.y = obj->y;
+
+    if(!(path = ai_shortes_path(obj->player,obj->type,source, point)))
+    {
+        printf("No shortes path found or a error ocurred!\n");
+        return 1;
+    }
+    
+    obj->state.path = path;
+
+    ai_modify_state(obj->player, obj, action);
+
+    printf("Path found!\n");
+*/
     return 1;
 }
 

-- 
tuxhistory - Educational history game



More information about the Tux4kids-commits mailing list