Fix:maptool:Another name for faroe islands
[navit-package] / navit / navigation.c
index b2cc630..ce01152 100644 (file)
@@ -38,7 +38,7 @@
 #include "plugin.h"
 #include "navit_nls.h"
 
-#define DEBUG
+/* #define DEBUG */
 
 struct suffix {
        char *fullname;
@@ -70,9 +70,9 @@ struct navigation {
        int turn_around;
        int turn_around_limit;
        int distance_turn;
-       int distance_last;
        struct callback *route_cb;
        int announce[route_item_last-route_item_first+1][3];
+       int tell_street_name;
 };
 
 
@@ -143,15 +143,16 @@ struct navigation *
 navigation_new(struct attr *parent, struct attr **attrs)
 {
        int i,j;
+       struct attr * attr;
        struct navigation *ret=g_new0(struct navigation, 1);
        ret->hash=item_hash_new();
        ret->callback=callback_list_new();
        ret->callback_speech=callback_list_new();
        ret->level_last=-2;
-       ret->distance_last=-2;
        ret->distance_turn=50;
        ret->turn_around_limit=3;
        ret->navit=parent->u.navit;
+       ret->tell_street_name=1;
 
        for (j = 0 ; j <= route_item_last-route_item_first ; j++) {
                for (i = 0 ; i < 3 ; i++) {
@@ -159,6 +160,10 @@ navigation_new(struct attr *parent, struct attr **attrs)
                }
        }
 
+       if ((attr=attr_search(attrs, NULL, attr_tell_street_name))) {
+               ret->tell_street_name = attr->u.num;
+       }
+
        return ret;     
 }
 
@@ -237,7 +242,7 @@ static char
 {
        switch (n) {
        case 0:
-               return _("zeroth"); // Not shure if this exists, neither if it will ever be needed
+               return _("zeroth"); // Not sure if this exists, neither if it will ever be needed
        case 1:
                return _("first");
        case 2:
@@ -260,7 +265,7 @@ static char
 {
        switch (n) {
        case 0:
-               return _("zeroth exit"); // Not shure if this exists, neither if it will ever be needed
+               return _("zeroth exit"); // Not sure if this exists, neither if it will ever be needed
        case 1:
                return _("first exit");
        case 2:
@@ -327,7 +332,7 @@ get_distance(int dist, enum attr_type type, int is_length)
                int rem=(dist/100)%10;
                if (rem) {
                        if (is_length)
-                               return g_strdup_printf(_("%d.%d kilometer"), dist/1000, rem);
+                               return g_strdup_printf(_("%d.%d kilometers"), dist/1000, rem);
                        else
                                return g_strdup_printf(_("in %d.%d kilometers"), dist/1000, rem);
                }
@@ -670,7 +675,7 @@ navigation_itm_new(struct navigation *this_, struct item *ritem)
        if (ritem) {
                ret->streetname_told=0;
                if (! item_attr_get(ritem, attr_street_item, &street_item)) {
-                       dbg(0,"no street item\n");
+                       dbg(1, "no street item\n");
                        return NULL;
                }
                if (item_attr_get(ritem, attr_direction, &direction))
@@ -682,7 +687,8 @@ navigation_itm_new(struct navigation *this_, struct item *ritem)
                ret->item=*sitem;
                item_hash_insert(this_->hash, sitem, ret);
                mr=map_rect_new(sitem->map, NULL);
-               sitem=map_rect_get_item_byid(mr, sitem->id_hi, sitem->id_lo);
+               if (! (sitem=map_rect_get_item_byid(mr, sitem->id_hi, sitem->id_lo)))
+                       return NULL;
                if (item_attr_get(sitem, attr_street_name, &attr))
                        ret->name1=map_convert_string(sitem->map,attr.u.str);
                if (item_attr_get(sitem, attr_street_name_systematic, &attr))
@@ -1172,7 +1178,7 @@ command_new(struct navigation *this_, struct navigation_itm *itm, int delta)
        dbg(1,"enter this_=%p itm=%p delta=%d\n", this_, itm, delta);
        ret->delta=delta;
        ret->itm=itm;
-       if (itm && itm->prev && itm->prev->ways && !(itm->flags & AF_ROUNDABOUT) && (itm->prev->flags & AF_ROUNDABOUT)) {
+       if (itm && itm->prev && itm->ways && itm->prev->ways && !(itm->flags & AF_ROUNDABOUT) && (itm->prev->flags & AF_ROUNDABOUT)) {
                int len=0;
                int angle=0;
                int entry_angle;
@@ -1318,7 +1324,7 @@ navigation_item_destination(struct navigation_itm *itm, struct navigation_itm *n
                /* TRANSLATORS: gives the name of the next road to turn into (into the E17) */
                ret=g_strdup_printf(_("%sinto the %s"),prefix,itm->name2);
        name1=ret;
-       while (*name1) {
+       while (name1 && *name1) {
                switch (*name1) {
                case '|':
                        *name1='\0';
@@ -1389,6 +1395,9 @@ show_maneuver(struct navigation *nav, struct navigation_itm *itm, struct navigat
                } else if (delta < 165) {
                        /* TRANSLATORS: Don't forget the ending space */
                        strength=_("strongly ");
+               } else if (delta < 180) {
+                       /* TRANSLATORS: Don't forget the ending space */
+                       strength=_("really strongly ");
                } else {
                        dbg(1,"delta=%d\n", delta);
                        /* TRANSLATORS: Don't forget the ending space */
@@ -1484,7 +1493,7 @@ show_maneuver(struct navigation *nav, struct navigation_itm *itm, struct navigat
        }
        if (cmd->itm->next) {
                int tellstreetname = 0;
-               char *destination = NULL; 
+               char *destination = NULL;
  
                if(type == attr_navigation_speech) { // In voice mode
                        // In Voice Mode only tell the street name in level 1 or in level 0 if level 1
@@ -1506,8 +1515,9 @@ show_maneuver(struct navigation *nav, struct navigation_itm *itm, struct navigat
                else
                     tellstreetname = 1;
 
-               if(tellstreetname) 
+               if(nav->tell_street_name && tellstreetname)
                        destination=navigation_item_destination(cmd->itm, itm, " ");
+
                if (level != -2) {
                        /* TRANSLATORS: The first argument is strength, the second direction, the third distance and the fourth destination Example: 'Turn 'slightly' 'left' in '100 m' 'onto baker street' */
                        ret=g_strdup_printf(_("Turn %1$s%2$s %3$s%4$s"), strength, dir, d, destination ? destination:"");
@@ -1688,6 +1698,10 @@ navigation_update(struct navigation *this_, struct route *route, struct attr *at
                return;
        dbg(1,"enter\n");
        while ((ritem=map_rect_get_item(mr))) {
+               if (ritem->type == type_route_start && this_->turn_around > -this_->turn_around_limit+1)
+                       this_->turn_around--;
+               if (ritem->type == type_route_start_reverse && this_->turn_around < this_->turn_around_limit)
+                       this_->turn_around++;
                if (ritem->type != type_street_route)
                        continue;
                if (first && item_attr_get(ritem, attr_street_item, &street_item)) {
@@ -1711,6 +1725,7 @@ navigation_update(struct navigation *this_, struct route *route, struct attr *at
                }
                navigation_itm_new(this_, ritem);
        }
+       dbg(2,"turn_around=%d\n", this_->turn_around);
        if (first) 
                navigation_destroy_itms_cmds(this_, NULL);
        else {
@@ -1719,17 +1734,6 @@ navigation_update(struct navigation *this_, struct route *route, struct attr *at
                        make_maneuvers(this_,this_->route);
                }
                calculate_dest_distance(this_, incr);
-               dbg(2,"destination distance old=%d new=%d\n", this_->distance_last, this_->first->dest_length);
-               if (this_->first->dest_length > this_->distance_last && this_->distance_last >= 0) 
-                       this_->turn_around++;
-               else
-                       this_->turn_around--;
-               if (this_->turn_around > this_->turn_around_limit)
-                       this_->turn_around=this_->turn_around_limit;
-               else if (this_->turn_around < -this_->turn_around_limit+1)
-                       this_->turn_around=-this_->turn_around_limit+1;
-               dbg(2,"turn_around=%d\n", this_->turn_around);
-               this_->distance_last=this_->first->dest_length;
                profile(0,"end");
                navigation_call_callbacks(this_, FALSE);
        }