Index: engines/drascula/graphics.cpp
===================================================================
--- engines/drascula/graphics.cpp	(revision 34519)
+++ engines/drascula/graphics.cpp	(working copy)
@@ -302,68 +302,71 @@
 }
 
 void DrasculaEngine::centerText(const char *message, int textX, int textY) {
-	char bb[200], m2[200], m1[200], mb[10][50];
+	char bb[200], m2[200], nextLine[200], centered_text[10][50];
 	char m3[200];
-	int h, fil, textX3, textX2, textX1, conta_f = 0, ya = 0;
+	int i, nextLineWidth, maxLineWidth, numLines = 0;
 
-	strcpy(m1, " ");
+	for (i = 0; i < 10; i++)
+		centered_text[i][0] = '\0';
+
+	textX = CLIP<int>(textX, 60, 255);
+	maxLineWidth = (textX <= 160) ? 2 * textX : 2 * (315 - textX);
+	nextLineWidth = strlen(message) * CHAR_WIDTH;
+
+	strcpy(nextLine, message);
 	strcpy(m2, " ");
 	strcpy(m3, " ");
 	strcpy(bb, " ");
 
-	for (h = 0; h < 10; h++)
-		strcpy(mb[h], " ");
+	while (true) {
+		bool emergency = false;
 
-	if (textX > 160)
-		ya = 1;
+		strcpy(bb, nextLine);
+		scumm_strrev(bb);
 
-	strcpy(m1, message);
-	textX = CLIP<int>(textX, 60, 255);
+		// If the next line is still too long, remove a word from it.
 
-	textX1 = textX;
+		if (nextLineWidth >= maxLineWidth) {
+			char *ptr = strrchr(nextLine, ' ');
 
-	if (ya == 1)
-		textX1 = 315 - textX;
-
-	textX2 = (strlen(m1) / 2) * CHAR_WIDTH;
-
-	while (true) {
-		strcpy(bb, m1);
-		scumm_strrev(bb);
-
-		if (textX1 < textX2) {
-			strcpy(m3, strrchr(m1, ' '));
-			strcpy(m1, strstr(bb, " "));
-			scumm_strrev(m1);
-			m1[strlen(m1) - 1] = '\0';
-			strcat(m3, m2);
-			strcpy(m2, m3);
+			if (ptr) {
+				strcpy(m3, ptr);
+				strcpy(nextLine, strchr(bb, ' '));
+				scumm_strrev(nextLine);
+				nextLine[strlen(nextLine) - 1] = '\0';
+				strcat(m3, m2);
+				strcpy(m2, m3);
+			} else
+				emergency = true;
 		};
 
-		textX2 = (strlen(m1) / 2) * CHAR_WIDTH;
+		nextLineWidth = strlen(nextLine) * CHAR_WIDTH;
 
-		if (textX1 < textX2)
-			continue;
+		// If the next line is now of appropriate length, add it to the
+		// centered lines.
 
-		strcpy(mb[conta_f], m1);
+		if (emergency || nextLineWidth < maxLineWidth) {
+			strcpy(centered_text[numLines++], nextLine);
 
-		if (!strcmp(m2, ""))
-			break;
+			int len = strlen(m2);
 
-		scumm_strrev(m2);
-		m2[strlen(m2) - 1] = '\0';
-		scumm_strrev(m2);
-		strcpy(m1, m2);
-		strcpy(m2, "");
-		conta_f++;
+			if (len > 0) {
+				scumm_strrev(m2);
+				m2[len - 1] = '\0';
+				scumm_strrev(m2);
+				strcpy(nextLine, m2);
+				*m2 = '\0';
+			} else
+				break;
+		}
 	}
 
-	fil = textY - (((conta_f + 3) * CHAR_HEIGHT));
+	int y = textY - (((numLines + 2) * CHAR_HEIGHT));
 
-	for (h = 0; h < conta_f + 1; h++) {
-		textX3 = strlen(mb[h]) / 2;
-		print_abc(mb[h], ((textX) - textX3 * CHAR_WIDTH) - 1, fil);
-		fil = fil + CHAR_HEIGHT + 2;
+	for (i = 0; i < numLines; i++) {
+		int x = (strlen(centered_text[i]) / 2) * CHAR_WIDTH;
+		print_abc(centered_text[i], textX - x - 1, y);
+		y += (CHAR_HEIGHT + 2);
 	}
 }
 
