Guest User

guiscript.asc

a guest
Feb 17th, 2014
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 50.99 KB | None | 0 0
  1. // Gui Script
  2. // ================================ OPTIONS ===============================================
  3. // ============================= EDIT FROM HERE ===========================================
  4.  
  5. // Setup the default Language (only affects the provided GUIs)
  6. // Unhandled events can directly be changed in the function Unhandled()
  7.  
  8. // Currently supported languages:
  9. // eLangEN (English)
  10. // eLangDE (German)
  11. // eLangES (Spanish)
  12. // eLangFR (French)
  13. // eLangIT (Italian)
  14.  
  15. int lang = eLangEN;
  16.  
  17. int
  18. ActionLabelColorNormal = 15219, // colour used in action bar
  19. ActionLabelColorHighlighted = 38555, // highlighted colour used in action bar
  20. invUparrowONsprite = 124, // sprite slot of the upper inv arrow / normal
  21. invUparrowOFFsprite = 154, // sprite slot of the upper inv arrow / disabled
  22. invUparrowHIsprite = 137, // sprite slot of the upper inv arrow / highlighted
  23. invDownarrowONsprite = 128, // " " " lower " "
  24. invDownarrowOFFsprite = 155, // " " " lower " "
  25. invDownarrowHIsprite = 141, // " " " lower " "
  26. walkoffscreen_offset = 30, // offset used by WalkOffScreen and exit extensions
  27. cursorspritenumber = 19, // used for semi-blockable movement
  28. blankcursorspritenumber = 29; // used for semi-blockable movement
  29. bool openDoorDoubleclick = true; // doubleclick on open doors changes room instantly
  30. bool NPC_facing_player = false; // Non playable characters are facing
  31. // the player before talk-to and give-to
  32. bool oldschool_inv_clicks = false; // turned on: right-click on inv items is lookat
  33. // turned off: right-click on inv items is use
  34.  
  35. // You can define Audioclips, which are being used in the doorscripts
  36. #ifver 3.2
  37. // In AGS 3.2 you do it this way:
  38. // Audioclip *openDoorSound = aDoorsound;
  39. AudioClip* openDoorSound,
  40. closeDoorSound,
  41. unlockDoorSound;
  42. #endif
  43.  
  44. #ifnver 3.2
  45. // In AGS 3.1 you have to assign a number:
  46. // openDoorSound = 15;
  47. int openDoorSound = 0,
  48. closeDoorSound = 0,
  49. unlockDoorSound = 0;
  50. #endif
  51.  
  52. // ============================= EDIT UNTIL HERE ===========================================
  53.  
  54.  
  55. // ========================== variables (not to edit) ======================================
  56.  
  57. String madetext; // String that is shown in the action bar
  58. String numbers; // used by getInteger() to convert strings
  59. String door_strings[6]; // default messages for the door script
  60.  
  61. int global_action; // containing the current clicked action
  62. int default_action; // default action (most likely walk-to)
  63. int alternative_action; // right-click action
  64. int used_action; // used_action = global_action, if not cancelled
  65. int GSagsusedmode; // on_mouse_click -> unhandled_event
  66. int GSloctype; // the result of GetLocationType
  67. int GSlocid; // on_mouse_click ->
  68. int GScancelable; // MovePlayer
  69. String GSlocname; // on_mouse_click -> unhandled_event
  70. String GSinvloc; // locationname>extension
  71. String SHOWNlocation; // location translated
  72. String location; // The location name underneath the cursor
  73. bool player_frozen; // player can't move
  74. bool disabled_gui; // GUI disabled
  75. int door_state[MAX_DOORS]; // Array for the door script
  76. int action_button[A_COUNT_]; // Array containing the verb button Ids
  77. int action_button_normal[A_COUNT_]; // contains the verb button sprites
  78. int action_button_highlight[A_COUNT_]; // Contains the highlighted verb button sprites
  79. int button_action[A_COUNT_]; // Array containg the related actions like eGA_LookAt
  80.  
  81. String tresult; // translated result of the action mode, eg. "Look at %s"
  82. String act_object; // action_object - object used in action
  83. String item; // inventory item to be used or given
  84. int GStopsaveitem = 0; // top savegame element of the save GUI
  85. int listBoxGap; // used in the save-game dialog to determine a list-item's height
  86. int dc_speed; // double click speed, set in the game start section
  87.  
  88.  
  89. int action_l_keycode[A_COUNT_]; // lower case keycodes for the verbs
  90. int action_u_keycode[A_COUNT_]; // upper case keycodes for the verbs
  91. InventoryItem*ItemGiven; // Item given to a character
  92. char key_l_yes, key_u_yes, key_l_no, key_u_no; // translated keys for yes and no
  93. bool doubleclick; // doubleclick occured
  94. bool timer_run; // is doubleclick timer running
  95. int timer_click; // double click timer
  96.  
  97.  
  98.  
  99. // ============================= Helper functions ===========================================
  100. function set_door_state(int door_id, int value) {
  101. door_state[door_id] = value;
  102. }
  103.  
  104. int get_door_state(int door_id) {
  105. return door_state[door_id];
  106. }
  107.  
  108. function init_object (int door_id, int obj){
  109. if (get_door_state(door_id) == 1) {
  110. object[obj].Visible=true;
  111. object[obj].Clickable=false;
  112. }
  113. else {
  114. object[obj].Visible=false;
  115. object[obj].Clickable=false;
  116. }
  117. }
  118.  
  119. int Absolute(int value) {
  120. if (value<0) return -value;
  121. return value;
  122. }
  123.  
  124. int Offset(int point1, int point2) {
  125. return Absolute(point1 - point2);
  126. }
  127.  
  128. int getButtonAction(int action) {
  129. return button_action[action];
  130. }
  131.  
  132. function disable_gui()
  133. {
  134. disabled_gui=true;
  135. gMaingui.Visible=false;
  136. gAction.Visible=false;
  137. }
  138.  
  139. function enable_gui()
  140. {
  141. disabled_gui=false;
  142. gMaingui.Visible=true;
  143. gAction.Visible=true;
  144. Wait(1);
  145. }
  146.  
  147. bool is_gui_disabled() {
  148. return disabled_gui;
  149. }
  150.  
  151. function set_double_click_speed(int speed){
  152. dc_speed = speed;
  153. }
  154.  
  155. // ============================= verb action functions ===========================================
  156. function TranslateAction(int action, int tr_lang) {
  157. if (tr_lang == eLangDE) {
  158. if (action == eMA_WalkTo) tresult="Gehe zu %s";
  159. else if (action == eGA_LookAt) tresult="Schau %s an";
  160. else if (action == eGA_TalkTo) tresult="Rede mit %s";
  161. else if (action == eGA_GiveTo) {
  162. if (item.Length>0) tresult="Gib !s an %s";
  163. else tresult="Gib %s";
  164. }
  165. else if (action == eGA_PickUp) tresult="Nimm %s";
  166. else if (action == eGA_Use) {
  167. if (item.Length>0) tresult="Benutze !s mit %s";
  168. else tresult="Benutze %s";
  169. }
  170. else if (action == eGA_Open) tresult="Öffne %s";
  171. else if (action == eGA_Close) tresult="Schließe %s";
  172. else if (action == eGA_Push) tresult="Drücke %s";
  173. else if (action == eGA_Pull) tresult="Ziehe %s";
  174. else tresult=" ";
  175. }
  176. else if (tr_lang == eLangES) {
  177. if (action == eMA_WalkTo) tresult="Ir a %s";
  178. else if (action == eGA_LookAt) tresult="Mirar %s";
  179. else if (action == eGA_TalkTo) tresult="Hablar con %s";
  180. else if (action == eGA_GiveTo) {
  181. if (item.Length>0) tresult="Dar !s a %s";
  182. else tresult="Dar %s";
  183. }
  184. else if (action == eGA_PickUp) tresult="Coger %s";
  185. else if (action == eGA_Use) {
  186. if (item.Length>0) tresult="Usar !s con %s";
  187. else tresult="Usar %s";
  188. }
  189. else if (action == eGA_Open) tresult="Abrir %s";
  190. else if (action == eGA_Close) tresult="Cerrar %s";
  191. else if (action == eGA_Push) tresult="Empujar %s";
  192. else if (action == eGA_Pull) tresult="Tirar de %s";
  193. else tresult=" ";
  194. }
  195. else if (tr_lang == eLangFR) {
  196. if (action == eMA_WalkTo) tresult="Aller vers %s";
  197. else if (action == eGA_LookAt) tresult="Regarder %s";
  198. else if (action == eGA_TalkTo) tresult="Parler à %s";
  199. else if (action == eGA_GiveTo) {
  200. if (item.Length>0) tresult="Donner !s à %s";
  201. else tresult="Donner %s";
  202. }
  203. else if (action == eGA_PickUp) tresult="Prendre %s";
  204. else if (action == eGA_Use) {
  205. if (item.Length>0) tresult="Utiliser !s sur %s";
  206. else tresult="Utiliser %s";
  207. }
  208. else if (action == eGA_Open) tresult="Ouvrir %s";
  209. else if (action == eGA_Close) tresult="Fermer %s";
  210. else if (action == eGA_Push) tresult="Pousser %s";
  211. else if (action == eGA_Pull) tresult="Tirer %s";
  212. else tresult=" ";
  213. }
  214. else if (tr_lang == eLangIT) {
  215. if (action == eMA_WalkTo) tresult="Vai a %s";
  216. else if (action == eGA_LookAt) tresult="Esamina %s";
  217. else if (action == eGA_TalkTo) tresult="Parla con %s";
  218. else if (action == eGA_GiveTo) {
  219. if (item.Length>0) tresult="Dai !s a %s";
  220. else tresult="Dai %s";
  221. }
  222. else if (action == eGA_PickUp) tresult="Raccogli %s";
  223. else if (action == eGA_Use) {
  224. if (item.Length>0) tresult="Usa !s con %s";
  225. else tresult="Usa %s";
  226. }
  227. else if (action == eGA_Open) tresult="Apri %s";
  228. else if (action == eGA_Close) tresult="Ferma %s";
  229. else if (action == eGA_Push) tresult="Premi %s";
  230. else if (action == eGA_Pull) tresult="Tira %s";
  231. else tresult=" ";
  232. }
  233. else {
  234. if (action == eMA_WalkTo) tresult="Go to %s";
  235. else if (action == eGA_LookAt) tresult="Look at %s";
  236. else if (action == eGA_TalkTo) tresult="Talk to %s";
  237. else if (action == eGA_GiveTo) {
  238. if (item.Length>0) tresult="Give !s to %s";
  239. else tresult="Give %s";
  240. }
  241. else if (action == eGA_PickUp) tresult="Pick up %s";
  242. else if (action == eGA_Use) {
  243. if (item.Length>0) tresult="Use !s with %s";
  244. else tresult="Use %s";
  245. }
  246. else if (action == eGA_Open) tresult="Open %s";
  247. else if (action == eGA_Close) tresult="Close %s";
  248. else if (action == eGA_Push) tresult="Push %s";
  249. else if (action == eGA_Pull) tresult="Pull %s";
  250. else tresult=" ";
  251. }
  252. // fill object and item into action template
  253. tresult=GetTranslation(tresult);
  254. int ip=tresult.IndexOf("!s");
  255. if (ip>=0) {
  256. int op=tresult.Contains("%s");
  257. tresult=tresult.ReplaceCharAt(ip, '%');
  258. if (ip<op) tresult=String.Format(tresult, item, act_object);
  259. else tresult=String.Format(tresult, act_object, item);
  260. }
  261. else tresult=String.Format(tresult, act_object);
  262. }
  263.  
  264. bool isAction(Action test_action) {
  265. return global_action == test_action;
  266. }
  267.  
  268. function UsedAction(Action test_action) {
  269. return ((used_action == test_action) && (GSagsusedmode != eModeUseinv)) ||
  270. ((test_action == eGA_UseInv) && (used_action == eGA_Use) && (GSagsusedmode == eModeUseinv)) ||
  271. ((test_action == eGA_GiveTo) && (used_action == eGA_GiveTo) && (GSagsusedmode == eModeUseinv) && ItemGiven!=null);
  272. }
  273.  
  274. function SetAction(Action new_action) {
  275. // set default action
  276. if (new_action == eMA_Default) new_action=default_action;
  277. // set corresponding cursormode
  278. if (new_action == eMA_WalkTo) mouse.Mode=eModeUsermode2;
  279. else if (new_action == eGA_LookAt) mouse.Mode=eModeLookat;
  280. else if (new_action == eGA_TalkTo) mouse.Mode=eModeTalkto;
  281. else if (new_action == eGA_GiveTo) mouse.Mode=eModeInteract;
  282. else if (new_action == eGA_PickUp) mouse.Mode=eModePickup;
  283. else if (new_action == eGA_Use) mouse.Mode=eModeInteract;
  284. else if (new_action == eGA_Open) mouse.Mode=eModeUsermode1;
  285. else if (new_action == eGA_Close) mouse.Mode=eModeUsermode1;
  286. else if (new_action == eGA_Push) mouse.Mode=eModeUsermode1;
  287. else if (new_action == eGA_Pull) mouse.Mode=eModeUsermode1;
  288. // save action
  289. global_action=new_action;
  290. }
  291. function SetDefaultAction(Action def_action) {
  292. default_action=def_action;
  293. SetAction(eMA_Default);
  294. }
  295.  
  296. // ============================= Load/Save game ===========================================
  297.  
  298. function GetLucasSavegameListBox(ListBox*lb) {
  299. // stores savegames in slots 100-199
  300. String buffer, sgdesc;
  301. int maxsavegames, counter=0;
  302. maxsavegames=99;
  303. lb.Clear();
  304. while (counter<maxsavegames) {
  305. buffer=String.Format("%d.", counter+1);
  306. sgdesc=Game.GetSaveSlotDescription(counter+100);
  307. if (sgdesc==null) sgdesc="";
  308. buffer=buffer.Append(sgdesc);
  309. lb.AddItem(buffer);
  310. counter++;
  311. }
  312. lb.TopItem=GStopsaveitem;
  313. lb.SelectedIndex=-1;
  314. }
  315.  
  316. // ============================= GlobalCondition ===========================================
  317. int GlobalCondition(int parameter) {
  318. // here are some conditions that are used many times in the script
  319. int cond;
  320. InventoryItem*ii=InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
  321. GUIControl*gc=GUIControl.GetAtScreenXY(mouse.x, mouse.y);
  322. int gcid=-1;
  323. if (gc!=null) gcid=gc.ID;
  324. // if the mouse is in the inventory and modes Walk or pickup are selected
  325. if (parameter == 1)
  326. cond = (ii != null && (isAction(eMA_WalkTo) || isAction(eGA_PickUp)));
  327. // if the mode is useinv and the mouse is over the active inv (like "use knife on knife")
  328. else if (parameter == 2)
  329. cond =(player.ActiveInventory == ii && Mouse.Mode == eModeUseinv);
  330. // if the mode is talk, or "Give", and the mouse isnt over a character
  331. else if (parameter == 3)
  332. cond =((isAction(eGA_TalkTo) || (isAction(eGA_GiveTo) && (Mouse.Mode == eModeUseinv))) && (GetLocationType(mouse.x, mouse.y) != eLocationCharacter));
  333. // if its GIVE and the mouse isnt over a inv.item
  334. else if (parameter == 4)
  335. cond = ((Mouse.Mode == eModeInteract) && isAction(eGA_GiveTo) && (ii == null));
  336. return cond;
  337. }
  338. // ============================= Verb Extensions and actions ===========================================
  339.  
  340. char ExtensionEx(int index, String name){
  341. //returns the extension in the position 'index' of the string 'name'.
  342. //returns 0 if the name has no extension or if you passed an empty string.
  343. if (name.Length==0) return 0;//if you passed an empty string
  344. int pos;
  345. pos=name.IndexOf(">");
  346. if (pos==-1) return 0;
  347. else if (pos+index<name.Length) return name.Chars[pos+index];
  348. else return 0;
  349. }
  350.  
  351. char Extension(){
  352. // Check the (first) extension (>*) of a string
  353. return ExtensionEx(1,location);
  354. }
  355.  
  356. function RemoveExtension(){
  357. //removes the extension of a string
  358. int pos = location.IndexOf(">");
  359. int length=location.Length;
  360. if (Extension()!=0)location=location.Truncate(pos);
  361. return pos;
  362. }
  363.  
  364. function AddExtension(char extension) {
  365. //adds an extension to a thing that doesn't have one
  366. int length=location.Length;
  367. if (Extension()==0) {
  368. location=location.Append(">n");
  369. location=location.ReplaceCharAt(length+1, extension);
  370. }
  371. }
  372.  
  373. function SetAlternativeAction(char extension, Action alt_action) {
  374. if (alt_action==eMA_Default) {
  375. if (Extension()==extension)
  376. alternative_action = alt_action;
  377. }
  378. else {
  379. int button=action_button[alt_action];
  380. int normalbuttonpic=action_button_normal[alt_action];
  381. int overbuttonpic=action_button_highlight[alt_action];
  382. // used for setting the default action given the extension.
  383. GUIControl*gc=gMaingui.Controls[button];
  384. Button*b=gc.AsButton;
  385. if (Extension()==extension) {
  386. b.NormalGraphic=overbuttonpic;
  387. alternative_action=alt_action;
  388. }
  389. else b.NormalGraphic=normalbuttonpic;
  390. b.MouseOverGraphic=overbuttonpic;
  391. }
  392. }
  393.  
  394. // Door extension for Open/Close
  395. function OpenCloseExtension(int door_id) {
  396. if ((get_door_state(door_id)==0) || (get_door_state(door_id)==2)) AddExtension('o');
  397. else AddExtension('c');
  398. }
  399.  
  400. function VariableExtensions() {
  401. // define here, which things will use a variable extension (>v)
  402. // by default, it's only used for doors.
  403. int r=player.Room;
  404. Object*oo=Object.GetAtScreenXY(mouse.x, mouse.y);
  405. int o=0;
  406. if (oo!=null) o=oo.ID;
  407. Hotspot*hh=Hotspot.GetAtScreenXY(mouse.x, mouse.y);
  408. int h=hh.ID;
  409.  
  410. // Open/Close Extension:
  411. // Room | Hotspot |(Door_id)
  412. if (r==1 && h == 1) OpenCloseExtension (20);
  413. //else if (r==2 && h == 2) OpenCloseExtension (3);
  414.  
  415. // Other possible extensions could be: Turn On/Turn Off
  416. }
  417.  
  418. function CheckDefaultAction() {
  419. // you could want to change which extension activates which default action, or which button sprite
  420. // it changes. The extensions are characters, so remember to put them with single ', not ".
  421. int x=mouse.x;
  422. int y=mouse.y;
  423. location=Game.GetLocationName(x, y);
  424. if (Extension()==0) {
  425. // Setting default modes if the thing has no extension:
  426. if (GetLocationType(x, y)==eLocationCharacter) // if it is a character
  427. AddExtension('t'); // set default action "talk to"
  428. else if ((GetLocationType(x, y)!=eLocationNothing) || (InventoryItem.GetAtScreenXY(x, y)!=null))
  429. // if its an inv item, a hotspot or an object
  430. AddExtension('l'); // set default action "look at"
  431. else
  432. AddExtension('n'); // set default action "none"
  433. }
  434. else if (Extension()=='v') { // if the default action depends on some events
  435. RemoveExtension();
  436. VariableExtensions();
  437. }
  438. if (GlobalCondition(2) || GlobalCondition(3) || GlobalCondition(4) || GlobalCondition(5))
  439. //Dont send the name of the hotspt/obj/char/inv to the action bar and set default action "none"
  440. location=">n";
  441.  
  442. GSinvloc=location;
  443.  
  444. // Set "Look" as default action for Inv items
  445. if ((Extension()=='u') && (InventoryItem.GetAtScreenXY(x, y) != null)) {
  446. // it's an inv item
  447. RemoveExtension();
  448. AddExtension('l'); // set default action "look at"
  449. }
  450.  
  451. SetAlternativeAction('n', eMA_Default);
  452. SetAlternativeAction('g', eGA_GiveTo);
  453. SetAlternativeAction('p', eGA_PickUp);
  454. SetAlternativeAction('u', eGA_Use);
  455. SetAlternativeAction('o', eGA_Open);
  456. SetAlternativeAction('l', eGA_LookAt);
  457. SetAlternativeAction('s', eGA_Push);
  458. SetAlternativeAction('c', eGA_Close);
  459. SetAlternativeAction('t', eGA_TalkTo);
  460. SetAlternativeAction('y', eGA_Pull);
  461. RemoveExtension();
  462. SHOWNlocation=location;
  463. }
  464. // ============================= ActionBar ===========================================
  465.  
  466. function UpdateActionBar (){
  467. // set the text in the action bar
  468. int action = global_action;
  469.  
  470. act_object=SHOWNlocation;
  471. item="";
  472. if (Mouse.Mode==eModeUseinv) { // use or give inventory item
  473. item=player.ActiveInventory.Name;
  474. location=item;
  475. RemoveExtension();
  476. item=location;
  477. }
  478. else if (GlobalCondition (1)) { // if the mouse is in the inventory and modes Walk or pickup are selected
  479. if (oldschool_inv_clicks) action=eGA_LookAt;
  480. else action=eGA_Use;
  481. }
  482.  
  483. TranslateAction(action, lang);
  484. madetext=tresult;
  485. // show action text
  486. ActionLine.Text=madetext;
  487. ActionLine.TextColor=ActionLabelColorNormal;
  488. }
  489.  
  490.  
  491. // ============================= translation ===========================================
  492.  
  493. String clearToSpace(String text) {
  494. int p=0;
  495. // ignore white spaces at the beginning
  496. while (p<text.Length && text.Chars[p]==' ') {
  497. p++;
  498. }
  499. // write white spaces until next white space
  500. while (p<text.Length && text.Chars[p]!=' ') {
  501. text=text.ReplaceCharAt(p, ' ');
  502. p++;
  503. }
  504. return text;
  505. }
  506.  
  507. int getInteger() {
  508. int r=numbers.AsInt;
  509. numbers=clearToSpace(numbers);
  510. return r;
  511. }
  512.  
  513. function SetActionButtons(Action action, String button_definition) {
  514. // extract data from button_definition
  515. String bd;
  516.  
  517. if (IsTranslationAvailable ())
  518. bd=GetTranslation(button_definition);
  519. else {
  520. bd=button_definition;
  521. }
  522.  
  523. bd=clearToSpace(bd);
  524. numbers=bd;
  525. action_button[action]=getInteger();
  526. action_button_normal[action]=getInteger();
  527. action_button_highlight[action]=getInteger();
  528. bd=numbers;
  529. int p=bd.Length-1;
  530. while (p>0) {
  531. action_l_keycode[action]=bd.Chars[p];
  532. p--;
  533. action_u_keycode[action]=bd.Chars[p];
  534. if (action_l_keycode[action]!=' ') p=0;
  535. }
  536. button_action[action_button[action]]=action;
  537.  
  538. }
  539.  
  540. function AdjustLanguage() {
  541.  
  542. // English
  543. if (lang == eLangEN){
  544. // yes/no-keys
  545. key_u_yes= 'Y';
  546. key_l_yes= 'y';
  547. key_u_no= 'N';
  548. key_l_no= 'n';
  549.  
  550. // (eNum Name, Name, GUI Button ID, Sprite-Normal, Sprite-Highlight, Keyboard-Shortcut)
  551. SetActionButtons(eGA_GiveTo, "a_button_give 0 125 138 Qq");
  552. SetActionButtons(eGA_PickUp, "a_button_pick_up 1 126 139 Ww");
  553. SetActionButtons(eGA_Use, "a_button_use 2 127 140 Ee");
  554. SetActionButtons(eGA_Open, "a_button_open 3 129 142 Aa");
  555. SetActionButtons(eGA_LookAt, "a_button_look_at 4 134 147 Ss");
  556. SetActionButtons(eGA_Push, "a_button_push 5 131 144 Dd");
  557. SetActionButtons(eGA_Close, "a_button_close 6 133 146 Zz");
  558. SetActionButtons(eGA_TalkTo, "a_button_talk_to 7 130 143 Xx");
  559. SetActionButtons(eGA_Pull, "a_button_pull 8 135 148 Cc");
  560. }
  561. // German
  562. else if (lang == eLangDE) {
  563. // yes/no-keys
  564. key_u_yes= 'J';
  565. key_l_yes= 'j';
  566. key_u_no= 'N';
  567. key_l_no= 'n';
  568. // (eNum Name, Name, GUI Button ID, Sprite-Normal, Sprite-Highlight, Keyboard-Shortcut)
  569. SetActionButtons(eGA_GiveTo, "a_button_give 0 157 166 Qq");
  570. SetActionButtons(eGA_Use, "a_button_use 1 158 167 Ww");
  571. SetActionButtons(eGA_PickUp, "a_button_pick_up 2 159 168 Ee");
  572. SetActionButtons(eGA_Open, "a_button_open 3 160 169 Aa");
  573. SetActionButtons(eGA_Close, "a_button_close 4 161 170 Ss");
  574. SetActionButtons(eGA_TalkTo, "a_button_talk_to 5 162 171 Dd");
  575. SetActionButtons(eGA_LookAt, "a_button_look_at 6 163 172 Yy");
  576. SetActionButtons(eGA_Push, "a_button_push 7 164 173 Xx");
  577. SetActionButtons(eGA_Pull, "a_button_pull 8 165 174 Cc");
  578. }
  579. // Spanish
  580. else if (lang == eLangES) {
  581. // yes/no-keys
  582. key_u_yes= 'S';
  583. key_l_yes= 's';
  584. key_u_no= 'N';
  585. key_l_no= 'n';
  586. // (eNum Name, Name, GUI Button ID, Sprite-Normal, Sprite-Highlight, Keyboard-Shortcut)
  587. SetActionButtons(eGA_GiveTo, "a_button_give 0 6 11 Qq");
  588. SetActionButtons(eGA_TalkTo, "a_button_talk_to 1 18 17 Ww");
  589. SetActionButtons(eGA_Use, "a_button_use 2 4 145 Ee");
  590. SetActionButtons(eGA_Open, "a_button_open 3 5 2 Aa");
  591. SetActionButtons(eGA_Close, "a_button_close 4 8 7 Ss");
  592. SetActionButtons(eGA_PickUp, "a_button_pick_up 5 10 9 Dd");
  593. SetActionButtons(eGA_LookAt, "a_button_look_at 6 122 75 Zz");
  594. SetActionButtons(eGA_Push, "a_button_push 7 14 13 Xx");
  595. SetActionButtons(eGA_Pull, "a_button_pull 8 16 15 Cc");
  596. }
  597. // French
  598. else if (lang == eLangFR) {
  599. // yes/no-keys
  600. key_u_yes= 'O';
  601. key_l_yes= 'o';
  602. key_u_no= 'N';
  603. key_l_no= 'n';
  604. // (eNum Name, Name, GUI Button ID, Sprite-Normal, Sprite-Highlight, Keyboard-Shortcut)
  605. SetActionButtons(eGA_GiveTo, "a_button_give 0 149 184 Qq");
  606. SetActionButtons(eGA_PickUp, "a_button_pick_up 1 176 185 Ww");
  607. SetActionButtons(eGA_Use, "a_button_use 2 177 186 Ee");
  608. SetActionButtons(eGA_Open, "a_button_open 3 178 187 Aa");
  609. SetActionButtons(eGA_TalkTo, "a_button_talk_to 4 179 188 Xx");
  610. SetActionButtons(eGA_Push, "a_button_push 5 180 189 Dd");
  611. SetActionButtons(eGA_Close, "a_button_close 6 181 190 Zz");
  612. SetActionButtons(eGA_LookAt, "a_button_look_at 7 182 191 Ss");
  613. SetActionButtons(eGA_Pull, "a_button_pull 8 183 175 Cc");
  614. }
  615. // Italian
  616. else if (lang == eLangIT) {
  617. // yes/no-keys
  618. key_u_yes= 'S';
  619. key_l_yes= 's';
  620. key_u_no= 'N';
  621. key_l_no= 'n';
  622. // (eNum Name, Name, GUI Button ID, Sprite-Normal, Sprite-Highlight, Keyboard-Shortcut)
  623. SetActionButtons(eGA_GiveTo, "a_button_give 0 193 200 Qq");
  624. SetActionButtons(eGA_PickUp, "a_button_pick_up 1 195 203 Ww");
  625. SetActionButtons(eGA_Use, "a_button_use 2 196 204 Ee");
  626. SetActionButtons(eGA_Open, "a_button_open 3 197 205 Aa");
  627. SetActionButtons(eGA_TalkTo, "a_button_talk_to 4 198 206 Xx");
  628. SetActionButtons(eGA_Push, "a_button_push 5 199 207 Dd");
  629. SetActionButtons(eGA_Close, "a_button_close 6 201 213 Zz");
  630. SetActionButtons(eGA_LookAt, "a_button_look_at 7 202 214 Ss");
  631. SetActionButtons(eGA_Pull, "a_button_pull 8 194 215 Cc");
  632. }
  633.  
  634. // --- load font corresponding to language and screen width ---
  635. String font_info;
  636. if (System.ScreenWidth<640)
  637. font_info=GetTranslation("font_lowres: 1 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 3 3");
  638. else
  639. font_info=GetTranslation("font_hires: 1 0 0 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 3 3");
  640. //Game.NormalFont
  641. font_info=clearToSpace(font_info);
  642. numbers=font_info;
  643.  
  644. // Setting the fonts from the string: font_info
  645. Game.SpeechFont = getInteger(); // Speech
  646. ActionLine.Font = getInteger(); // Status-Line
  647. Game.NormalFont = getInteger(); // Dialog GUI
  648. OptionsTitle.Font = getInteger(); // Options-GUI Title
  649. OptionsSave.Font = getInteger(); // Options-GUI Save Button
  650. OptionsLoad.Font = getInteger(); // Options-GUI Load Button
  651. OptionsQuit.Font = getInteger(); // Options-GUI Quit Button
  652. OptionsPlay.Font = getInteger(); // Options-GUI Play Button
  653. gPausedText.Font = getInteger(); // Game Paused Message
  654. OptionsDefault.Font = getInteger(); // Options-GUI Default Button
  655. OptionsMusic.Font = getInteger(); // Options-GUI Music Label
  656. OptionsSpeed.Font = getInteger(); // Options-GUI Gamespeed Label
  657. OptionsRestart.Font = getInteger(); // Options-GUI Restart Button
  658. RestoreTitle.Font = getInteger(); // Restore-GUI Title
  659. RestoreCancel.Font = getInteger(); // Restore-GUI Cancel Button
  660. SaveTitle.Font = getInteger(); // Save-GUI Title
  661. SaveOK.Font = getInteger(); // Save-GUI Okay Button
  662. SaveCancel.Font = getInteger(); // Save-GUI Cancel Button
  663. gConfirmexitText.Font = getInteger(); // Confirm Exit Message
  664. gRestartText.Font = getInteger(); // Restart Game Message
  665. }
  666.  
  667. function AdjustGUIText() {
  668.  
  669. // English
  670. if (lang == eLangEN){
  671. // english is the default language, nothing to adjust
  672. return;
  673. }
  674. else if (lang == eLangDE) {
  675. // German
  676. OptionsTitle.Text = "Optionen";
  677. OptionsMusic.Text = "Musik Lautstärke";
  678. OptionsSound.Text = "Sound Effekte";
  679. OptionsSpeed.Text = "Geschwindigkeit";
  680. OptionsDefault.Text = "Standard";
  681. OptionsSave.Text = "Speichern";
  682. OptionsLoad.Text = "Laden";
  683. OptionsRestart.Text = "Neustart";
  684. OptionsQuit.Text = "Beenden";
  685. OptionsPlay.Text = "Weiter";
  686. gPausedText.Text = "Pause. Leertaste für weiter";
  687. RestoreTitle.Text = "Wählen Sie ein Spiel zum Laden";
  688. RestoreCancel.Text = "Abbruch";
  689. SaveTitle.Text = "Name für das Spiel";
  690. SaveOK.Text = "Speichern";
  691. SaveCancel.Text = "Abbruch";
  692. gConfirmexitText.Text = "Möchten Sie das Spiel beenden? (J/N)";
  693. gRestartText.Text = "Möchten Sie das Spiel neu starten? (J/N)";
  694. }
  695. else if (lang == eLangES) {
  696. // Spanish
  697. OptionsTitle.Text = "Opciones";
  698. OptionsMusic.Text = "Volumen de la música";
  699. OptionsSound.Text = "Efectos de sonido ";
  700. OptionsSpeed.Text = "Velocidad de juego";
  701. OptionsDefault.Text = "Restablecer";
  702. OptionsSave.Text = "Guardar";
  703. OptionsLoad.Text = "Cargar";
  704. OptionsRestart.Text = "Reiniciar";
  705. OptionsQuit.Text = "Salir";
  706. OptionsPlay.Text = "Volver";
  707. gPausedText.Text = "Juego en pausa. Pulsa Espacio para continuar";
  708. RestoreTitle.Text = "Por favor, elige el juego a cargar";
  709. RestoreCancel.Text = "Cancelar";
  710. SaveTitle.Text = "Por favor, introduce un nombre";
  711. SaveOK.Text = "Guardar";
  712. SaveCancel.Text = "Cancelar";
  713. gConfirmexitText.Text = "¿Seguro que quieres salir? (S/N)";
  714. gRestartText.Text = "¿Seguro que quieres reiniciar? (S/N)";
  715. }
  716. else if (lang == eLangFR) {
  717. // French
  718. OptionsTitle.Text = "Paramètres";
  719. OptionsMusic.Text = "Volume de la musique";
  720. OptionsSound.Text = "Volume des sons";
  721. OptionsSpeed.Text = "Vitesse du jeu";
  722. OptionsDefault.Text = "Réinitialiser";
  723. OptionsSave.Text = "Sauver";
  724. OptionsLoad.Text = "Charger";
  725. OptionsRestart.Text = "Redémarrer";
  726. OptionsQuit.Text = "Quitter";
  727. OptionsPlay.Text = "Reprendre";
  728. gPausedText.Text = "PAUSE. Appuyez sur la barre d'espacement pour reprendre";
  729. RestoreTitle.Text = "Choisissez une partie à charger";
  730. RestoreCancel.Text = "Annuler";
  731. SaveTitle.Text = "Saisissez un nom";
  732. SaveOK.Text = "Sauver";
  733. SaveCancel.Text = "Annuler";
  734. gConfirmexitText.Text = "Voulez-vous vraiment quitter? (O/N)";
  735. gRestartText.Text = "Voulez-vous vraiment redémarrer? (O/N)";
  736. }
  737. else if (lang == eLangIT) {
  738. // Italian
  739. OptionsTitle.Text = "Opzioni";
  740. OptionsMusic.Text = "Volume della Musica";
  741. OptionsSound.Text = "Effetti Sonori";
  742. OptionsSpeed.Text = "Velocita' del Gioco";
  743. OptionsDefault.Text = "Default";
  744. OptionsSave.Text = "Salva";
  745. OptionsLoad.Text = "Carica";
  746. OptionsRestart.Text = "Ricomincia";
  747. OptionsQuit.Text = "Esci";
  748. OptionsPlay.Text = "Continua";
  749. gPausedText.Text = "Partita in Pausa. Premi Spazio per Continuare";
  750. RestoreTitle.Text = "Scegli una partita da caricare";
  751. RestoreCancel.Text = "Cancella";
  752. SaveTitle.Text = "Inserisci un nome";
  753. SaveOK.Text = "Salva";
  754. SaveCancel.Text = "Cancella";
  755. gConfirmexitText.Text = "Sei sicuro/a che vuoi uscire? (S/N)";
  756. gRestartText.Text = "Sei sicuro/a che vuoi ricominciare? (S/N)";
  757. }
  758. }
  759. // ============================= Player function ===========================================
  760. function freeze_player(){player_frozen = true;}
  761.  
  762. function unfreeze_player(){player_frozen = false;}
  763.  
  764. function FaceDirection(this Character*, eDirection dir) {
  765. int dx;
  766. if (dir==eDir_Left) dx=-1;
  767. if (dir==eDir_Right) dx=1;
  768. int dy;
  769. if (dir==eDir_Up) dy=-1;
  770. else if (dir==eDir_Down) dy=1;
  771. this.FaceLocation(this.x+dx, this.y+dy);
  772. }
  773.  
  774.  
  775. function SetPlayer(Character*ch) {
  776. //use this instead of SetPlayerCharacter function.
  777. if (player.Room==ch.Room) { // if old and new player character are in the same room then scroll room
  778. int x=GetViewportX();
  779. int tx=ch.x-160;
  780. if (tx<0) tx = 0;
  781. else if (tx>Room.Width-320) tx=Room.Width-320;
  782. SetViewport(x, GetViewportY());
  783. while (x<tx) {
  784. x+=X_SPEED;
  785. if (x>tx) x=tx;
  786. SetViewport(x, GetViewportY());
  787. Wait(1);
  788. }
  789. while (x>tx) {
  790. x -= X_SPEED;
  791. if (x<tx) x=tx;
  792. SetViewport(x, GetViewportY());
  793. Wait (1);
  794. }
  795. }
  796. else // if they are in different rooms
  797. player.StopMoving();
  798. player.Clickable=true;
  799. ch.Clickable=false;
  800. ch.SetAsPlayer();
  801. ReleaseViewport();
  802. }
  803.  
  804. int MovePlayerEx(int x, int y, WalkWhere direct) {
  805. // Move the player character to x,y coords, waiting until he/she gets there,
  806. // but allowing to cancel the action by pressing a mouse button.
  807. if (player_frozen==false) {
  808. mouse.ChangeModeGraphic(eModeWait, cursorspritenumber);
  809. GScancelable = 0;
  810. player.Walk(x, y, eNoBlock, direct);
  811. // wait for release of mouse button
  812. while (player.Moving && (mouse.IsButtonDown(eMouseLeft) || mouse.IsButtonDown(eMouseRight))) {
  813. Wait(1);
  814. mouse.Update();
  815. CheckDefaultAction();
  816. }
  817. // abort moving on new mouse down
  818. while (player.Moving) {
  819. int xm=mouse.x;
  820. int ym=mouse.y;
  821. InventoryItem*ii=InventoryItem.GetAtScreenXY(xm, ym);
  822. if (mouse.IsButtonDown(eMouseLeft) && (GUI.GetAtScreenXY(xm, ym)==null || ii!=null)) {
  823. player.StopMoving();
  824. GScancelable = 1;
  825. }
  826. else if (mouse.IsButtonDown(eMouseRight) && (GUI.GetAtScreenXY(xm, ym)==null || ii!=null)) {
  827. player.StopMoving();
  828. GScancelable = 2;
  829. }
  830. else {
  831. Wait(1);
  832. mouse.Update();
  833. CheckDefaultAction ();
  834. }
  835. }
  836. mouse.ChangeModeGraphic(eModeWait, blankcursorspritenumber);
  837. //if (GScancelable==0) return 1;
  838. //BUG FIX: AdventureTreff:
  839. if (GScancelable==0 && player.x==x && player.y==y) return 2;
  840. else if (GScancelable == 0) return 1;
  841. else return 0;
  842. }
  843. else return 0;
  844. }
  845.  
  846. int MovePlayer(int x, int y) {
  847. //Move the player character to x,y coords, waiting until he/she gets there, but allowing to cancel the action
  848. //by pressing a mouse button.
  849. return MovePlayerEx (x, y, eWalkableAreas);
  850. }
  851.  
  852. // ============================= Go ===========================================
  853. int GoToCharacterEx(Character*chwhogoes, Character*ch, eDirection dir, int xoffset, int yoffset, bool NPCfacesplayer, int blocking) {
  854. //Goes to a character staying at the side defined by 'direction': 1 up, 2 right, 3 down, 4 left
  855. //and it stays at xoffset or yofsset from the character. NPCfacesplayer self-explained. ;)
  856. // blocking: 0=non-blocking; 1=blocking; 2=semi-blocking
  857. Character*pl=chwhogoes;
  858. int chx, chy;
  859. chx=ch.x;
  860. chy=ch.y;
  861. int arrived=1;
  862. if (Offset(pl.x, chx)>xoffset || Offset(pl.y, chy)>yoffset) {
  863. if (dir==eDir_None) {
  864. // get the nearest position
  865. if (Offset (chx, pl.x)>=Offset(chy, pl.y)) {
  866. // right or left
  867. if (pl.x>=chx) dir=eDir_Right; //right
  868. else dir=eDir_Left; //left
  869. }
  870. else {
  871. if (pl.y>=chy) dir=eDir_Down; //abajo
  872. else dir=eDir_Up;
  873. }
  874. }
  875. // calculate target position
  876. if (dir==eDir_Up) chy-=yoffset;
  877. else if (dir==eDir_Right) chx+=xoffset;
  878. else if (dir==eDir_Down) chy+=yoffset;
  879. else if (dir==eDir_Left) chx-=xoffset;
  880. // move character
  881. if (blocking==0) {
  882. pl.Walk(chx, chy);
  883. arrived=0;
  884. }
  885. else if (blocking==1) {
  886. pl.Walk(chx, chy, eBlock, eWalkableAreas);
  887. arrived=1;
  888. }
  889. else if (blocking==2) arrived=MovePlayer(chx, chy);
  890. }
  891. if (arrived>0) {
  892. // characters only face each other after the moving character arrived at the target point
  893. if (NPCfacesplayer) ch.FaceCharacter(pl, eBlock);
  894. pl.FaceCharacter(ch, eBlock);
  895. }
  896. return arrived;
  897. }
  898.  
  899. int NPCGoToCharacter(Character*chwhogoes, Character*chtogoto, eDirection dir, bool NPCfacesplayer, int blocking) {
  900. // same as above but with default x and y offset.
  901. int defaultxoffset=35;
  902. int defaultyoffset=20;
  903. return GoToCharacterEx (chwhogoes, chtogoto, dir, defaultxoffset, defaultyoffset, NPCfacesplayer, blocking);
  904. }
  905.  
  906. int GoToCharacter(Character*ch, eDirection dir, bool NPCfacesplayer, int blocking) {
  907. // same as above but with default x and y offset.
  908. int defaultxoffset=35;
  909. int defaultyoffset=20;
  910. return GoToCharacterEx (player, ch, dir, defaultxoffset, defaultyoffset, NPCfacesplayer, blocking);
  911. }
  912.  
  913. function GoTo(int blocking) {
  914. // Goes to whatever the player clicked on.
  915. // blocking: 0=non-blocking; 1=blocking; 2=semi-blocking
  916. int xtogo, ytogo;
  917. int locationtype=GetLocationType(mouse.x, mouse.y);
  918. Hotspot*hot_spot=Hotspot.GetAtScreenXY(mouse.x, mouse.y);
  919. int arrived=0;
  920. if (locationtype==eLocationCharacter)
  921. arrived=GoToCharacter(Character.GetAtScreenXY(mouse.x, mouse.y), eDir_None, false, blocking);
  922. else {
  923. if (locationtype==eLocationHotspot && hot_spot.ID>0) {
  924. xtogo=hot_spot.WalkToX;
  925. ytogo=hot_spot.WalkToY;
  926. }
  927. if (locationtype==eLocationObject) {
  928. Object*obj=Object.GetAtScreenXY(mouse.x, mouse.y);
  929. xtogo=obj.X;
  930. ytogo=obj.Y;
  931. }
  932. if (hot_spot==hotspot[0]) {
  933. xtogo=mouse.x;
  934. ytogo=mouse.y;
  935. }
  936. else {
  937. xtogo=mouse.x;
  938. ytogo=mouse.y;
  939. }
  940. xtogo+=GetViewportX ();
  941. ytogo+=GetViewportY ();
  942. if (blocking==0) player.Walk(xtogo, ytogo);
  943. else if (blocking==1) {
  944. player.Walk(xtogo, ytogo, eBlock);
  945. arrived=1;
  946. }
  947. else if (blocking==2) arrived=MovePlayer(xtogo, ytogo);
  948. }
  949. return arrived;
  950. }
  951.  
  952. function Go() {
  953. // Go to whatever the player clicked on. You can cancel the action, and returns 1 if the player has gone to it.
  954. return GoTo(2);
  955. }
  956.  
  957. function WalkOffScreen(){
  958. //handles the action of hotspots with exit extension ('>e').
  959. //double click in such hotspots/objects... will make the player skip
  960. //walking to it. Look the documentation for more information on exits.
  961.  
  962. // doubleclick
  963. if (UsedAction(eMA_WalkTo)) {
  964. if (timer_run == true)
  965. {
  966. timer_run=false;
  967. if (MovePlayerEx(player.x,player.y,eWalkableAreas)>0) hotspot[GSlocid].RunInteraction(eModeUsermode1);
  968. }
  969. else
  970. {
  971. //doubleclick = false;
  972. timer_run = true;
  973. if (Go()){
  974. int x=player.x,y=player.y;
  975. int offset=walkoffscreen_offset;
  976. int dir=ExtensionEx(2,GSlocname);
  977. if (dir=='u') y-=offset;
  978. else if (dir=='d') y+=offset;
  979. else if (dir=='l') x-=offset;
  980. else if (dir=='r') x+=offset;
  981. if (MovePlayerEx(x,y,eAnywhere)>0){
  982. hotspot[GSlocid].RunInteraction(eModeUsermode1);
  983. }
  984. }
  985. }
  986. }
  987. }
  988.  
  989. // ============================= Unhandled Events ===========================================
  990.  
  991. // Please check this section and replace the boring default values with your own.
  992. // If you courious, how it all works, keep on reading this comment ;-)
  993. //
  994. //Check modes with: if(UsedAction(A_???)), check types by if(type==#). types:
  995. // 1 a hotspot
  996. // 2 a character
  997. // 3 an object
  998. // 4 an inventory item.
  999. // 5 inv. item on hotspot
  1000. // 6 inv. item on character
  1001. // 7 inv. item on object
  1002. // 8 inv. item on inv. item
  1003. //
  1004. // You have the string "locationname" that is the name of
  1005. // what you clicked on, and the string "usedinvname" that is
  1006. // the name of the item that was used on where you clicked (only for types 5,6,7,8)
  1007.  
  1008. function Unhandled(int door_script) {
  1009. InventoryItem*ii=InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
  1010. int type=0;
  1011. if (GSloctype==eLocationHotspot) type=1;
  1012. if (GSloctype==eLocationCharacter) type=2;
  1013. if (GSloctype==eLocationObject) type=3;
  1014. String locationname=GSlocname;
  1015. String usedinvname;
  1016. String translation;
  1017. translation=Game.TranslationFilename;
  1018. location=locationname;
  1019. RemoveExtension();
  1020. locationname=location;
  1021. if (ii!=null) type = 4;
  1022. if (GSagsusedmode == eModeUseinv) {
  1023. if (ii!=null) {
  1024. usedinvname=ii.Name;
  1025. location=usedinvname;
  1026. RemoveExtension();
  1027. usedinvname=location;
  1028. if (type>0) type+=4;
  1029. }
  1030. }
  1031. if (GSagsusedmode!=eModeUsermode2 && type!=0) {
  1032. if (type==2 || type==6) player.FaceCharacter(character[GSlocid], eBlock);
  1033.  
  1034. // unhandled USE
  1035. if (UsedAction(eGA_Use)) {
  1036. // use inv on inv
  1037. if (type >= 5) player.Say("That won't do any good.");
  1038. // use
  1039. else player.Say("I can't use that.");
  1040. }
  1041.  
  1042. // unhandled LOOK AT
  1043. else if (UsedAction(eGA_LookAt)) {
  1044. // look at hotspots, objects etc.
  1045. if (type!=2) player.Say ("");
  1046. // look at characters
  1047. else player.Say("");
  1048. }
  1049.  
  1050. // unhandled PUSH
  1051. else if (UsedAction(eGA_Push)) {
  1052. // push everything except characters
  1053. if (type!=2) player.Say("I can't push that.");
  1054. // push characters
  1055. else player.Say("I can't push %s",locationname);
  1056. }
  1057.  
  1058. // unhandled PULL
  1059. else if (UsedAction(eGA_Pull)){
  1060. // pull everything except characters
  1061. if (type!=2) player.Say("I can't pull that.");
  1062. // pull characters
  1063. else player.Say("I can't pull %s",locationname);
  1064. }
  1065.  
  1066. // unhandled CLOSE
  1067. else if (UsedAction(eGA_Close)){
  1068. if (door_script == 1) player.Say("It has already been closed.");
  1069. else if (type == 2) player.Say("Doing that with %s is not a good idea.",locationname);
  1070. else player.Say("I can't close that.");
  1071. }
  1072.  
  1073. // unhandled OPEN
  1074. else if (UsedAction(eGA_Open)) {
  1075. if (door_script == 1) player.Say("It is already open.");
  1076. else if (type ==2) player.Say("%s would not like it.",locationname);
  1077. else player.Say("I can't open that.");
  1078. }
  1079.  
  1080. // unhandled PICKUP
  1081. else if (UsedAction(eGA_PickUp)) {
  1082. if (type!=2) player.Say("I don't need that.");
  1083. else player.Say("I don't want to pick %s up.",locationname);
  1084. }
  1085.  
  1086. // unhandled TALK TO
  1087. else if (UsedAction(eGA_TalkTo)) {
  1088. if (type==2) player.Say("I don't want to talk to %s", locationname);
  1089. else player.Say("I have nothing to say.");
  1090. }
  1091.  
  1092. // unhandled USE INV
  1093. else if (UsedAction(eGA_UseInv)) player.Say("That won't do any good.");
  1094.  
  1095. // unhandled GIVE
  1096. else if (ItemGiven != null) player.Say("I'd rather keep it.");
  1097.  
  1098. // unhandled DEFAULT
  1099. else if (type==4) player.Say("I can't do that.");
  1100.  
  1101. }
  1102. }
  1103.  
  1104. // ============================= interaction functions ===========================================
  1105. function EnterRoom(this Character*, int newRoom, int x, int y, eDirection dir, bool onWalkable) {
  1106. this.ChangeRoom(newRoom, x, y);
  1107. if (onWalkable) this.PlaceOnWalkableArea();
  1108. this.FaceDirection(dir);
  1109. }
  1110.  
  1111. function any_click_move (int x, int y, eDirection dir) {
  1112. int result=MovePlayer(x, y);
  1113. if (result) {
  1114. player.FaceDirection(dir);
  1115. Wait(5);
  1116. }
  1117. return result;
  1118. }
  1119.  
  1120. function any_click_walk(int x, int y, eDirection dir){
  1121. int result=1;
  1122. if (UsedAction(eMA_WalkTo)) any_click_move(x, y, dir);
  1123. else result=0;
  1124. return result;
  1125. // 0 = unhandled
  1126. // 1 = handled
  1127. }
  1128.  
  1129. function any_click_walk_look(int x, int y, eDirection dir, String lookat){
  1130. int result=any_click_walk(x, y, dir);
  1131. //if (result==0 && UsedAction(eGA_LookAt) && lookat.Length>0) {
  1132. if (result==0 && lookat.Length>0) {
  1133. result=1;
  1134. if (any_click_move(x, y, dir)) {
  1135. player.Say(lookat);
  1136. }
  1137. }
  1138. return result;
  1139. // 0 = unhandled
  1140. // 1 = handled
  1141. }
  1142.  
  1143. function any_click_use_inv(InventoryItem*iitem, int x, int y, eDirection dir) {
  1144. int result=0;
  1145. if (UsedAction(eGA_UseInv)) {
  1146. if (player.ActiveInventory==iitem) {
  1147. if (any_click_move (x, y, dir)) result = 2;
  1148. else result = 1;
  1149. }
  1150. }
  1151. return result;
  1152. // 0 = unhandled
  1153. // 1 = handled, but canceled
  1154. // 2 = use this item
  1155. }
  1156.  
  1157. // ============================= AGS internal functions ==========================================
  1158.  
  1159. function on_mouse_click(MouseButton button) {
  1160.  
  1161. if (!is_gui_disabled()) {
  1162. int mrx=mouse.x+GetViewportX();
  1163. int mry=mouse.y+GetViewportY();
  1164. int x=mouse.x;
  1165. int y=mouse.y;
  1166. // get location under mouse cursor
  1167. GSloctype=GetLocationType(x, y);
  1168. GSlocname=Game.GetLocationName(x, y);
  1169. GSagsusedmode=Mouse.Mode;
  1170. used_action=global_action;
  1171.  
  1172. InventoryItem*ii = InventoryItem.GetAtScreenXY(x, y);
  1173. if (GSloctype==eLocationHotspot) {
  1174. Hotspot*h=Hotspot.GetAtScreenXY(x, y);
  1175. GSlocid=h.ID;
  1176.  
  1177. }
  1178. else if (GSloctype==eLocationCharacter) {
  1179. Character*c=Character.GetAtScreenXY(x, y);
  1180. GSlocid=c.ID;
  1181. }
  1182. else if (GSloctype==eLocationObject) {
  1183. Object*o=Object.GetAtScreenXY(x, y);
  1184. GSlocid=o.ID;
  1185. }
  1186. else if (ii!=null) GSlocid=ii.ID;
  1187.  
  1188.  
  1189.  
  1190.  
  1191. if (IsGamePaused()) {
  1192. // Game is paused, so do nothing (ie. don't allow mouse click)
  1193. }
  1194. // Mousebutton Left
  1195. else if (button==eMouseLeft)
  1196. {
  1197.  
  1198. if (GlobalCondition(2) || GlobalCondition(3) || GlobalCondition(4)) {
  1199. // Do nothing, if:
  1200. // the mode is useinv and the mouse is over the active inv (like "use knife on knife")
  1201. // or the mode is talk, or "Give", and the mouse isnt over a character
  1202. // or its GIVE and the mouse isnt over a inv.item
  1203.  
  1204. }
  1205. else if (ExtensionEx(1, GSlocname)=='e') {
  1206. UpdateActionBar();
  1207. ActionLine.TextColor=ActionLabelColorHighlighted;
  1208. WalkOffScreen();
  1209. }
  1210. // walk to
  1211. else if (GSagsusedmode==eModeUsermode2) {
  1212. ActionLine.TextColor=ActionLabelColorHighlighted;
  1213. if (IsInteractionAvailable(x, y, GSagsusedmode)) ProcessClick (x, y, GSagsusedmode);
  1214. else ProcessClick(x, y, eModeWalkto);
  1215. }
  1216. // talkto
  1217. else if (GSagsusedmode==eModeTalkto && IsInteractionAvailable(x, y, GSagsusedmode) && GSloctype==eLocationCharacter) {
  1218. ActionLine.TextColor=ActionLabelColorHighlighted;
  1219. if (GoToCharacter(character[GSlocid], eDir_None, NPC_facing_player, 1)) character[GSlocid].RunInteraction(GSagsusedmode);
  1220. SetAction(eMA_Default);
  1221. }
  1222. // Giveto
  1223. else if ((GSagsusedmode == eModeUseinv) && GSloctype==eLocationCharacter && isAction(eGA_GiveTo)) {
  1224. ActionLine.TextColor=ActionLabelColorHighlighted;
  1225. ItemGiven=player.ActiveInventory;
  1226.  
  1227. if (GoToCharacter(character[GSlocid], eDir_None, NPC_facing_player, 2)) {
  1228. if (IsInteractionAvailable (mrx - GetViewportX (), mry - GetViewportY (), eModeUseinv) == 1) {
  1229. character[GSlocid].RunInteraction(eModeUseinv);
  1230. }
  1231. }
  1232. SetAction (eMA_Default);
  1233. }
  1234. else {
  1235. UpdateActionBar();
  1236. ActionLine.TextColor=ActionLabelColorHighlighted;
  1237. ProcessClick(x, y, GSagsusedmode);
  1238. SetAction(eMA_Default);
  1239. ItemGiven=null;
  1240. }
  1241. }
  1242. // Mousebutton Right
  1243. else if (button==eMouseRight) {
  1244. if (alternative_action==eMA_Default) {
  1245. SetAction(eMA_Default);
  1246. ActionLine.TextColor=ActionLabelColorHighlighted;
  1247. if (Mouse.Mode==eModeUsermode2) {
  1248. if (ExtensionEx(1, GSlocname)=='e') {
  1249. UpdateActionBar();
  1250. ActionLine.TextColor=ActionLabelColorHighlighted;
  1251. WalkOffScreen();
  1252. }
  1253. else ProcessClick(x, y, eModeWalkto);
  1254. }
  1255. else ProcessClick(x, y, Mouse.Mode);
  1256. }
  1257. else
  1258. {
  1259. SetAction(alternative_action);
  1260. used_action=global_action;
  1261. UpdateActionBar();
  1262. ActionLine.TextColor=ActionLabelColorHighlighted;
  1263. GSagsusedmode=Mouse.Mode;
  1264. if (GSagsusedmode==eModeTalkto && IsInteractionAvailable(x, y, GSagsusedmode) && GSloctype==eLocationCharacter) { //(GetCharacterAt (mouse.x, mouse.y) < 7))
  1265. if (GoToCharacter(character[GSlocid], eDir_None, NPC_facing_player,2 )) character[GSlocid].RunInteraction(GSagsusedmode);
  1266. }
  1267. else ProcessClick(x, y, GSagsusedmode);
  1268. SetAction(eMA_Default);
  1269. }
  1270. }
  1271. //left click in inventory
  1272. else if (button==eMouseLeftInv) {
  1273. if (!isAction(eGA_GiveTo))ItemGiven= null;
  1274.  
  1275. if (GlobalCondition (1)) {
  1276. // if the mouse is in the inventory and modes Walk or pickup are selected
  1277. SetAction (eGA_Use);
  1278. location=GSinvloc;
  1279. if (Extension()=='u' && ii.IsInteractionAvailable(eModeInteract)) {
  1280. // use it immediately (not with anything else)
  1281. used_action=global_action;
  1282. ii.RunInteraction(eModeInteract);
  1283. SetAction(eMA_Default);
  1284. }
  1285. else {
  1286. if (oldschool_inv_clicks) {
  1287. SetAction (eGA_LookAt);
  1288. used_action=global_action;
  1289. ii.RunInteraction(eModeLookat);
  1290. SetAction(eMA_Default);
  1291. }
  1292. else player.ActiveInventory=ii;
  1293. }
  1294. }
  1295. else if (GlobalCondition (2) == 1) {
  1296. // if the mode is useinv and the mouse is over the active inv (like "use knife on knife")
  1297. // so do nothing again
  1298. }
  1299. else {
  1300. used_action=global_action;
  1301. if (Mouse.Mode==eModeInteract) {
  1302. if (isAction(eGA_Use) && ii.IsInteractionAvailable(eModeInteract)) {
  1303. ActionLine.TextColor=ActionLabelColorHighlighted;
  1304. ii.RunInteraction(eModeInteract);
  1305. SetAction(eMA_Default);
  1306. }
  1307. else player.ActiveInventory=ii;
  1308. }
  1309. else {
  1310. if ( (Mouse.Mode >0 && Mouse.Mode <10 )&& ii != null) {
  1311. GSagsusedmode=Mouse.Mode;
  1312. ActionLine.TextColor=ActionLabelColorHighlighted;
  1313. ii.RunInteraction(Mouse.Mode);
  1314. SetAction(eMA_Default);
  1315. }
  1316. }
  1317. }
  1318. }
  1319. //right click in inventory
  1320. else if (button==eMouseRightInv) {
  1321. if (alternative_action==eMA_Default) {
  1322. SetAction(eMA_Default);
  1323. }
  1324. else {
  1325. SetAction(alternative_action);
  1326. used_action=global_action;
  1327. GSagsusedmode=Mouse.Mode;
  1328. if (Mouse.Mode==eModeInteract) {
  1329. if (isAction(eGA_Use) && ii.IsInteractionAvailable(eModeInteract)) {
  1330. UpdateActionBar();
  1331. ActionLine.TextColor=ActionLabelColorHighlighted;
  1332. ii.RunInteraction(eModeInteract);
  1333. SetAction(eMA_Default);
  1334. }
  1335. else player.ActiveInventory=ii;
  1336. }
  1337. else {
  1338. UpdateActionBar();
  1339. ActionLine.TextColor=ActionLabelColorHighlighted;
  1340. inventory[game.inv_activated].RunInteraction(Mouse.Mode);
  1341. SetAction(eMA_Default);
  1342. }
  1343. }
  1344. }
  1345. }
  1346. }
  1347.  
  1348. function repeatedly_execute_always() {
  1349. // Doubleclick Timer
  1350. if (!IsGamePaused() && !is_gui_disabled()) {
  1351. if (timer_run == true)
  1352. {
  1353. timer_click++;
  1354. if (timer_click >= dc_speed){
  1355. timer_click = 0;
  1356. timer_run = false;
  1357. }
  1358. }
  1359. }
  1360. }
  1361.  
  1362. function repeatedly_execute() {
  1363. if (!IsGamePaused() && !is_gui_disabled())
  1364. {
  1365.  
  1366. // --- for the MovePlayer function ---
  1367. if (GScancelable==1) {
  1368. GScancelable=0;
  1369. if (InventoryItem.GetAtScreenXY(mouse.x, mouse.y)==null) on_mouse_click(eMouseLeft);
  1370. else on_mouse_click(eMouseLeftInv);
  1371. }
  1372. else if (GScancelable==2) {
  1373. GScancelable=0;
  1374. CheckDefaultAction();
  1375. if (InventoryItem.GetAtScreenXY(mouse.x, mouse.y)==null) on_mouse_click(eMouseRight);
  1376. else on_mouse_click(eMouseRightInv);
  1377. }
  1378. CheckDefaultAction();
  1379. UpdateActionBar();
  1380. }
  1381. // change the arrows in the inventory to show if you
  1382. // can scroll the inventory:
  1383. if (MainInv.TopItem>0) {
  1384. // if inventory can scroll up
  1385. InvUp.NormalGraphic=invUparrowONsprite;
  1386. InvUp.MouseOverGraphic=invUparrowHIsprite;
  1387.  
  1388. if (InventoryItem.GetAtScreenXY(gMaingui.X+MainInv.X+1, gMaingui.Y+MainInv.Y+1)==null) MainInv.TopItem-=MainInv.ItemsPerRow;
  1389. }
  1390. else {
  1391. InvUp.NormalGraphic=invUparrowOFFsprite;
  1392. InvUp.MouseOverGraphic=invUparrowOFFsprite;
  1393. }
  1394. //if inv can scroll down
  1395. if (MainInv.TopItem<MainInv.ItemCount-(MainInv.ItemsPerRow * MainInv.RowCount)) {
  1396. InvDown.NormalGraphic=invDownarrowONsprite;
  1397. InvDown.MouseOverGraphic=invDownarrowHIsprite;
  1398. }
  1399. else{
  1400. InvDown.NormalGraphic=invDownarrowOFFsprite;
  1401. InvDown.MouseOverGraphic=invDownarrowOFFsprite;
  1402. }
  1403.  
  1404. }
  1405.  
  1406. // ============================= Exports GUI Things===========================================
  1407. export ActionLabelColorHighlighted;
  1408. export key_l_yes, key_u_yes, key_l_no, key_u_no;
  1409. export action_l_keycode;
  1410. export action_u_keycode;
  1411. export GStopsaveitem;
  1412. export listBoxGap;
  1413. export ItemGiven;
  1414. export lang;
Advertisement
Add Comment
Please, Sign In to add comment