Skip to content
This repository has been archived by the owner on Apr 17, 2022. It is now read-only.

Fix player properties "name" and "ai" #4628

Closed
wzdev-ci opened this issue Aug 29, 2017 · 14 comments
Closed

Fix player properties "name" and "ai" #4628

wzdev-ci opened this issue Aug 29, 2017 · 14 comments

Comments

@wzdev-ci
Copy link
Contributor

resolution_fixed type_patch (an actual patch, not a request for one) | by Forgon


The player properties "name" and "ai" are broken.

In One-Player Skirmish games (excluding challenges) and Multi Player games, AI players get "name" and "ai" properties assigned only if selected interactively through the widget system (see function 'displayPlayer()' in './src/multiint.cpp'), where the position of the chosen AI in a vector of known
skirmish AIs (set up by function 'readAIs()' in './src/multiint.cpp') determines the "ai" property. The displayed AI name is copied to the player's "name". Because "Nexus" is the first entry in that vector, it is the default AI with "ai" equal to '0' (see '/.src/multiint.cpp:732').

Otherwise, all AI players

  • lack a "name" value (including Nexus)
  • have an "ai" value equal to '0' (wrong unless Nexus)

Challenge games get all "name" values from their configuration files printed in the setup screen before the game starts, except for player 0 (the human player). All "ai" values given are set to 'AI_CUSTOM', i.e. '127'. Once the game starts, all "name" values are discarded through the variable 'nameOverrides' (see './src/multiint.cpp').

Ingame, a player without name usually still has a name displayed. AI players without "name" value
are addressed by their colour. If a "name" value exists, their colour and a dash are prepended to their string. In chat messages, all players without names are adressed as "Commander" (since
#4612). This is useful for tutorials and campaigns.

This patch fixes all those problems by guaranteeing that

  • every AI player has a "name" value. If no "name" value is given and no AI name can be found, this will be "Commander".
  • every AI player has a correct "ai" value. It is determined through the index of the AI in 'aidata', the vector of known skirmish AIs, or set to 'CUSTOM_AI' (i.e. 127) for custom AIs of challenges.
  • no "name" values from challenge files are overwritten

The variable 'nameOverrides' is now removed, as is other bizarre code. To correctly display "name" and "ai" values before the setup screen appears, there are now ugly hacks into the function 'hostCampaign()' in './src/multiopt.cpp':

  • for challenges, split up function 'loadMultiScripts()' from './src/multiint.cpp' which assigns
    "ai" values from challenge JSON files to AI players but is only called after the game starts. A new
    function 'setupChallengeAIs()' now performs that task early.
  • for all skirmish games, afterwards assign "name" values to "ai" values.

The attached files 'test.json' and 'custom.json' provide a test challenge where all effects of this patch can be observed. I could not correctly test custom AIs, i.e. AIs exclusively available for challenges, possibly because they are not implemented. There are 8 combinations of "ai" and "name", corresponding to player numbers in the challenge file:

    1. "ai" not given, "name" given and player is 0: copy "name", "ai" equals '0'
    1. "ai" is known skirmish ai, "name" not given: copy "name" from the AI's JSON file, assign "ai" by 'aidata' index
    1. "ai" is custom, "name" not given: copy "name" from the AI's JSON file, "ai" equals '127' ('AI_CUSTOM')
    1. "ai" is custom but broken, "name" not given: "name" equals "Commander", "ai" equals '127' ('AI_CUSTOM')
    1. "ai" not given, "name" not given: copy "name" from default skirmish AI's JSON file, "ai" equals '0'
    1. "ai" is known skirmish ai, "name" given: copy "name", assign "ai" by 'aidata' index
    1. "ai" is custom, "name" given: copy "name", "ai" equals '127' ('AI_CUSTOM')
    1. "ai" not given, "name" given: copy "name", "ai" equals '0'

Issue migrated from trac:4628 at 2022-04-16 12:46:18 -0700

@wzdev-ci
Copy link
Contributor Author

Forgon uploaded file remove_useless_netName_property.patch (0.9 KiB)

patch file created with git format-patch (part 2/4)

@wzdev-ci
Copy link
Contributor Author

Forgon uploaded file refactoring_function.patch (1.9 KiB)

patch file created with git format-patch (part 3/4)

@wzdev-ci
Copy link
Contributor Author

Forgon uploaded file remove_unused_routine.patch (0.9 KiB)

patch file created with git format-patch (part 4/4)

@wzdev-ci
Copy link
Contributor Author

Forgon uploaded file test.json (1.2 KiB)

test challenge

@wzdev-ci
Copy link
Contributor Author

Forgon uploaded file custom.json (0.1 KiB)

test ai

@wzdev-ci
Copy link
Contributor Author

Forgon uploaded file setup_screen_names_old.png (82.8 KiB)

view of setup screen names before this patch for test challenge
setup_screen_names_old.png

@wzdev-ci
Copy link
Contributor Author

Forgon uploaded file setup_screen_names_new.png (84.1 KiB)

view of setup screen names after this patch for test challenge
setup_screen_names_new.png

@wzdev-ci
Copy link
Contributor Author

Forgon uploaded file ingame_names_old.png (372.5 KiB)

view of ingame names before this patch for test challenge
ingame_names_old.png

@wzdev-ci
Copy link
Contributor Author

Forgon uploaded file ingame_names_new.png (337.4 KiB)

view of ingame names after this patch for test challenge
ingame_names_new.png

@wzdev-ci
Copy link
Contributor Author

Forgon uploaded file fix_player_name_and_ai.patch (7.5 KiB)

patch file created with git format-patch (part 1/4)

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Sep 6, 2017

Berserk Cyborg changed status from new to closed

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Sep 6, 2017

Berserk Cyborg changed owner from `` to Berserk Cyborg

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Sep 6, 2017

Berserk Cyborg changed resolution from `` to fixed

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Sep 6, 2017

Berserk Cyborg committed [18]


In Warzone2100/warzone2100@18ec97b:

#CommitTicketReference repository="" revision="18ec97beb53fb5c0677e2ccaaec4686edca25fd1"
Fix player properties name and ai.

Patch by forum member Forgon.
Fixes #4628.

@wzdev-ci wzdev-ci closed this as completed Sep 6, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant