src/waypoint.cpp
changeset 10148 ad8e8a65f6a2
parent 10136 5d822fc9a3b8
child 10207 c291a21b304e
equal deleted inserted replaced
10147:f0215b6c526e 10148:ad8e8a65f6a2
   384 	if (!IsValidWaypointID(p1)) return CMD_ERROR;
   384 	if (!IsValidWaypointID(p1)) return CMD_ERROR;
   385 
   385 
   386 	Waypoint *wp = GetWaypoint(p1);
   386 	Waypoint *wp = GetWaypoint(p1);
   387 	if (!CheckOwnership(wp->owner)) return CMD_ERROR;
   387 	if (!CheckOwnership(wp->owner)) return CMD_ERROR;
   388 
   388 
   389 	if (!StrEmpty(_cmd_text)) {
   389 	bool reset = StrEmpty(_cmd_text);
       
   390 
       
   391 	if (!reset) {
   390 		if (strlen(_cmd_text) >= MAX_LENGTH_WAYPOINT_NAME_BYTES) return CMD_ERROR;
   392 		if (strlen(_cmd_text) >= MAX_LENGTH_WAYPOINT_NAME_BYTES) return CMD_ERROR;
   391 		if (!IsUniqueWaypointName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
   393 		if (!IsUniqueWaypointName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
   392 
   394 	}
   393 		if (flags & DC_EXEC) {
   395 
   394 			free(wp->name);
   396 	if (flags & DC_EXEC) {
       
   397 		free(wp->name);
       
   398 
       
   399 		if (reset) {
       
   400 			MakeDefaultWaypointName(wp); // sets wp->name = NULL
       
   401 		} else {
   395 			wp->name = strdup(_cmd_text);
   402 			wp->name = strdup(_cmd_text);
   396 			wp->town_cn = 0;
   403 		}
   397 
   404 
   398 			UpdateWaypointSign(wp);
   405 		UpdateWaypointSign(wp);
   399 			MarkWholeScreenDirty();
   406 		MarkWholeScreenDirty();
   400 		}
       
   401 	} else {
       
   402 		if (flags & DC_EXEC) {
       
   403 			free(wp->name);
       
   404 
       
   405 			MakeDefaultWaypointName(wp);
       
   406 			UpdateWaypointSign(wp);
       
   407 			MarkWholeScreenDirty();
       
   408 		}
       
   409 	}
   407 	}
   410 	return CommandCost();
   408 	return CommandCost();
   411 }
   409 }
   412 
   410 
   413 /**
   411 /**