From fc5cb2f664c9da659591c7572beb1d4058a4071f Mon Sep 17 00:00:00 2001 From: nvhaizi1 Date: Tue, 24 May 2022 22:45:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86Get=20Bus=20Position?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bus.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/bus.c b/src/bus.c index 3994ed6..19addc9 100644 --- a/src/bus.c +++ b/src/bus.c @@ -15,10 +15,17 @@ void RunBus(int direction) } int GetBusPosition() { - int a,b; - a=the_bus->rail_node_pos->id;//指向站点的指针以及这个指针对应的站台id; - b=a*(rails->last_node_distance)+abs(the_bus->distance); - return b; + int a,b,c; + b=0; + rail_node_t *p = rails; + a=the_bus->rail_node_pos->id;//指向站点的指针以及这个指针对应的站台id + while(p->id != a) + { + b+=p->next_node_distance; + p=p->next_node; + } + c=b+(the_bus->distance); + return c; } int JudgeOnStation() {